I'm getting the following error:
The term 'writedata' is not recognized as the name of a cmdlet, function, sc
t file, or operable program. Check the spelling of the name, or if a path wa
ncluded, verify that the path is correct and try again.
At D:\VPO\VM\LastPoweredOn\test.ps1:211 char:18
+ writedata <<<< $obj.VM $obj.LastPoweredOn $obj.User $obj.Owner
+ CategoryInfo : ObjectNotFound: (writedata:String) [], Command
tFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Code:
---------
$oneMonth = (Get-Date).AddDays(-31)
$entity = Get-Folder -Name datacenters
$events = Get-VIEventPlus -Entity $entity -EventType
VmPoweredOnEvent -Recurse -FullMessage
$events | Group-Object -Property {$_.Vm.Name} | %{
$_.Group | Sort-Object -Property CreatedTime -Descending |
Select -First 1 |
where {$_.CreatedTime -lt $oneMonth -and (Get-VM -Name
$_.Vm.Name -ErrorAction SilentlyContinue).PowerState -eq
"PoweredOff"} | %{
$obj = New-Object -TypeName PSObject -Property @{
VM = $_.VM.Name
LastPoweredOn = $_.CreatedTime
User = $_.VM.Name | Select UserName
Owner = (Get-VM
$_.Vm.Name).CustomFields.Item("OwnerDL")
}
writedata $obj.VM $obj.LastPoweredOn $obj.User $obj.Owner
}
}
#Function will compile the data passed from the GetCluster
Function into HTML table format
##################################################################
########################
Function writedata {
param ($Obj)
#Write output to html table
###########################
$tableEntry = "<td><font face='Tahoma'>$($Obj.VM)</font></td>"
+
"<td><font
face='Tahoma'>$($Obj.LastPoweredOn)</font></td>" +
"<td><font face='Tahoma'>$($Obj.User)</font></td>" +
"<td><font face='Tahoma'>$($Obj.Owner)</font></td></tr>"
Add-Content $fileName $tableEntry
Write-Host $tableEntry}
#Combine functions into orderly format for the output
#####################################################
writehtmlheader $fileName
writetableheader $fileName
Get-VIEventPlus
writehtmlfooter $fileName