PowerCLI – vulnerability report script

Shares

powerCLI iconI had to create a script to automate vulnerability reporting. Thanks to my colleague Grzegorz from http://psvmware.wordpress.com who helped me a lot with a script. Script generates report in CSV format and send email out with attachment.

Requirements:

  1. Base PowerCLI installed
  2. VUM PowerCLI snap-in installed

[button color=”red”] NOTEVUM PowerCLI snap-in has to have the same build version as vCenter server.[/button]

Add-PSSnapin VMware.VimAutomation.Core
Add-PSSnapin VMware.VumAutomation
#variables
$VC='vcenter-server-IP-or-FQDN'
$expfile='D:\tools\scripts\VPM-report.csv'
$date=get-date -Format dd/MM/yyyy
#import credentials
$pwd = Get-Content D:\tools\scripts\ap-vcs-credentials | ConvertTo-SecureString
$credentials = New-Object System.Management.Automation.PsCredential โ€œusernameโ€œ, $pwd
#connect to vCS server
Connect-VIServer -Server $VC
$baseline=Get-PatchBaseline -Name 'ESX-*'
#remove last report from tmp location
Remove-Item $expfile
$hosts=get-vmhost
#scanning
$hosts | Scan-Inventory
$ComplianceResult=$hosts |Get-Compliance -Baseline $baseline -Detailed
$ComplianceResult | select  @{n='Esx Host';e={$_.entity.name}},
@{n='esx Version';e={$_.entity.version}},
Status, @{n='CompliantPatches';e={$_.CompliantPatches.count}},
@{n='NotCompliantPatches';e={$_.NotCompliantPatches.count}},
@{n='UnknownPaches';e={$_.UnknownPaches.count}},
@{n='NotApplicablePatches';e={$_.NotApplicablePatches.count}},
@{n='Baseline name';e={$_.Baseline.Name}},
@{n='generated on';e={get-date -Format dd/MM/yyyy}} |export-csv $expfile -NoTypeInfor

Send email with attached CSV report.

#email variables
$smtpserver='FQDN-for-SMTP-server'
$emailfrom="sender email"
$emailto="recipient email "
$emailcc="who's in CC"
$emaildate=get-date -Format MMMM/yyyy
#send email with attachment
Send-mailmessage -to $emailto -cc $emailcc -from $emailfrom -subject "Report Virtual infrastructure $emaildate" -Attachments $expfile -SmtpServer $smtpserver
Disconnect-VIServer -Confirm:$false

[button link=”http://www.vmwaremine.com/2013/04/19/schedule-task-with-powercli-script/”] Learn how to store credentials in a file and how to schedule a task with PowerCLI script in Windows 2008 R2[/button]

0 0 votes
Article Rating

Artur Krzywdzinski

Artur is Consulting Architect at Nutanix. He has been using, designing and deploying VMware based solutions since 2005 and Microsoft since 2012. He specialize in designing and implementing private and hybrid cloud solution based on VMware and Microsoft software stacks, datacenter migrations and transformation, disaster avoidance. Artur holds VMware Certified Design Expert certification (VCDX #077).

You may also like...

Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Grzegorz Kulikowski

Not bad ๐Ÿ˜‰

3
0
Would love your thoughts, please comment.x
()
x

FOR FREE. Download Nutanix port diagrams

Join our mailing list to receive an email with instructions on how to download 19 port diagrams in MS Visio format.

NOTE: if you do not get an email within 1h, check your SPAM filters

You have Successfully Subscribed!

Pin It on Pinterest