Hi,
I am unable to get the Date information from VM from the below script as I am getting the below error.
Please help
Script
$incsv = Import-Csv .\$($folder)_OS_Info_$date.csv
$report = @()
$reportNotFound = @()
Foreach($vm in $incsv.Name)
{
$getvm = Get-VM -Name $vm -ErrorAction SilentlyContinue
if($getvm){
$report += Invoke-Command -ComputerName $vm -Credential $Creds -ScriptBlock {$DT = Get-WmiObject -Class Win32_LocalTime
$Times = New-Object PSObject -Property @{
ServerName = $DT.__Server
$DateTime = (Get-Date -Day $DT.Day -Month $DT.Month -Year $DT.Year -Minute $DT.Minute -Hour $DT.Hour -Second $DT.Second)
}
}
"$($vm) information has been fetched"
}
else{
$reportNotFound += $vm
"$($vm) not found"
}
}
$row | Add-Member -MemberType NoteProperty -Name 'DateTime' -Value $DateTime -PassThru
$report | Export-Csv -Path .\$($folder)_Date_Info_$date.csv -NoTypeInformation -UseCulture
$reportNotFound | Export-Csv -Path .\$($folder)_No_VMs_Date_Info_$date.csv -NoTypeInformation -UseCulture
Output
Add-Member : Cannot bind argument to parameter 'InputObject' because it is null.
At D:\myreports\Get_Date\get_date1.ps1:41 char:8
+ $row | Add-Member -MemberType NoteProperty -Name 'DateTime' -Value $D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Member], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand
A null key is not allowed in a hash literal.
+ CategoryInfo : InvalidOperation: (System.Collections.Hashtable:Hashtable) [], RuntimeException
+ FullyQualifiedErrorId : InvalidNullKey
+ PSComputerName : app01