You mean like this?
`$Today = (Get-Date)
`$StartDate = `$Today.Date.AddDays(-22)
`$EndDate = `$Today.Date.AddDays(1)
"### Output ###"
(New-Object System.Net.Sockets.TCPClient -ArgumentList $($row.Name),3389).Connected
"### Output ###"
(Get-HotFix | Where {`$_.InstalledOn -gt `$StartDate -AND `$_.InstalledOn -lt `$EndDate }| Measure-Object).Count
"### Output ###"
Get-HotFix | Where {`$_.InstalledOn -gt `$StartDate -AND `$_.InstalledOn -lt `$EndDate } |
Select CSName,Description,HotFixID,InstalledBy,InstalledOn |
ConvertTo-Csv -UseCulture -NoTypeInformation
'@
$report1=@()
$report2=@()
Import-Csv-Path $reportlocation2-UseCulture -PipelineVariable row |
ForEach-Object-Process {
$sInvoke=@{
VM =$_.Name
GuestCredential=$creds
ScriptTYpe ='powershell'
ScriptText =$ExecutionContext.InvokeCommand.ExpandString($code)
}
$result=Invoke-VMScript@sInvoke
$dummy,$out1,$out2,$out3=$result.ScriptOutput-split'### Output ###'
$out1=$out1.TrimStart("`n`r")-split"`n`r"
$out2=$out2.TrimStart("`n`r")
$out3=$out3.TrimStart("`n`r")
$report1+=$row|Add-Member-MemberType NoteProperty -Name 'RDP Status'-Value ([Boolean]$out1)-PassThru |
Add-Member-MemberType NoteProperty -Name Count -Value ([int]$out2)-PassThru
$report2+=$out3|ConvertFrom-Csv-UseCulture |Select-Object-Property CSName, HotFixID, Description, Caption, InstalledOn, InstalledBy
}
$report1|Export-Csv-Path $reportlocation2-UseCulture -NoTypeInformation
$report2|Export-Csv-Path .\fixes.csv -UseCulture -NoTypeInformation