- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do you call the script ExportComplianceToCSV.ps1 with this new setup ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Definitely digging your shortcut! I pretty much abandoned the original script. Here's is how I have been running my query:
$vmesxi = (Get-VMHost -Name (Get-Content "C:\esxihosts.txt"))
# Get today's date
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hhmmss')
# Set Output Path
$path = "C:\Reports\"
foreach ($i in $vmesxi) {
Get-Compliance -Entity $i -Detailed |
Select @{N="Host Name";E={$_.Entity.Name}},
@{N="Baseline";E={$_.Baseline.Name}},
@{N="Compliant Patches";E={$_.CompliantPatches | Measure-Object | Select -ExpandProperty Count}},
@{N="Not Compliant Patches";E={$_.NotCompliantPatches | Measure-Object | Select -ExpandProperty Count}},
@{N="Unknown Patches";E={$_.UnknownPatches | Measure-Object | Select -ExpandProperty Count}},
@{N="Not Applicable Patches";E={$_.NotApplicablePatches | Measure-Object | Select -ExpandProperty Count}},
Status |
Export-Csv "$path\PatchComplianceReport_$CurrentDate.csv" -UseCulture -NoTypeInformation
}
And there are two hostnames in the text file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To make sure the reading of the hostnames works correctly, can you check if the following actually produces 2 objects ?
Get-VMHost -Name (Get-Content "C:\esxihosts.txt")
Since the Get-Compliance cmdlet accepts multiple objects on the Entity parameter, and since the values can come from the pipeline, you could drop the ForEach altogether.
Something like this
# Get today's date
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hhmmss')
# Set Output Path
$path = "C:\Reports\"
Get-VMHost -Name (Get-Content "C:\esxihosts.txt") |
Get-Compliance -Detailed |
Select @{N="Host Name";E={$_.Entity.Name}},
@{N="Baseline";E={$_.Baseline.Name}},
@{N="Compliant Patches";E={$_.CompliantPatches | Measure-Object | Select -ExpandProperty Count}},
@{N="Not Compliant Patches";E={$_.NotCompliantPatches | Measure-Object | Select -ExpandProperty Count}},
@{N="Unknown Patches";E={$_.UnknownPatches | Measure-Object | Select -ExpandProperty Count}},
@{N="Not Applicable Patches";E={$_.NotApplicablePatches | Measure-Object | Select -ExpandProperty Count}},
Status |
Export-Csv "$path\PatchComplianceReport_$CurrentDate.csv" -UseCulture -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Very cool! I initially had a problem with it until I noticed the "|" after the text file. Once I added that in, everything ran perfectly. Output successful for both servers.
And is there any downside to running this code like it is versus the original ExportCompliance script? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The script provides more details about patches and upgrades, but if the info the last script produces is sufficient for your needs, use that one.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And the only prerequisite to running the script is to have an existing scan correct? It pulls against the compliance report right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can always run a Scan-Inventory from the script.
That way it will always produce a result, even if there was no scan done before your script runs.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What would be the best way to put that in? Just input before the "Get-Compliance" line?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, I wouldn't do that in the same pipeline construct, it would break it since it doesn't do a Passthru of the HostSystem objects.
Make a separate one before the one with Get-Compliance.
...
$esx = Get-VMHost -Name (Get-Content "C:\esxihosts.txt")
$esx |
Scan-Inventory
$esx |
Get-Compliance -Detailed |
...
To avoid doing a Get-Content and the Get-VMHost twice, I placed that on a separate line, and store the results in a variable
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Awesome! Thank you again LucD!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dropping in by to this old thread.
How do we use this script? I don't see any clear instructions. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What instructions do you mean?
How to run a PowerShell/PowerCLI script?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply mate.
If I execute .\ExportComplianceToCSV.ps1 (Get-VMHost -Name $vmHosts) "C:\MyReports\", I get ONLY the first compliance report, which is PatchComplianceReport.CSV
I expected it will provide me with HostUpgradeComplianceReport.csv, VMHWUpgradeComplianceReport.csv, GetVMToolsUpgradeBaselineComplianceReport.csv and GetVAUpgradeBaselineComplianceReport.csv as well.
Am I missing something?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When there are no entries for a specific report, the file is not created.
Could that be the case?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
LucD,
I tried to execute the script/command , but it throws an error. Need your help.
ExportCompliance.ps1 (Get-VMHost -Name $vmHosts) "C:\ABC\complinace-Reports\"
Thanks
V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks your $vmHosts variable is empty.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried the script and it worked great. Is there a way to get the install date for the patches?