Hey all,
I am currently trying to make a script to report any VMs that do not have tools installed, but it is kicking back all my veeam replicas and that is just not needed. Here is my script, what am I doing wrong to eliminate any VMs with the suffix _replica. Here is my script:
Get-VM | Get-View | Select-Object @{N=”VM Name”;E={$_.Name}},@{Name=”VMware Tools”;E={$_.Guest.ToolsStatus}}
Get-View -ViewType VirtualMachine -Property Name,Guest.ToolsStatus -Filter @{
"Config.Template"="False";"Guest.ToolsStatus"="^(?!toolsOk$).*$" } | `Select-Object Name,@{Name="ToolsStatus";E={$_.Guest.ToolsStatus}} |
I have excluded some information before this for the vcenter connection and after because I FTP this to a web server.
Any help would be great, thank you!
Andy
That works to exclude the _replica VMs, but there seems to be an error with the way your filtered for ToolsOk. The output error only showed VMs with ToolsOK. So I edited it a little to this:
Get-View -ViewType VirtualMachine -Property Config.Template,Name,Guest.ToolsStatus -Filter @{
"Config.Template"="False";"Guest.ToolsStatus"="^(?!toolsOk$).*$" ;"Name"="^((?!_replica).)*$"} |
Select-Object Name,@{Name="ToolsStatus";E={$_.Guest.ToolsStatus}}
This worked, thank you so much!
Does this work for you ?
Get-View -ViewType VirtualMachine -Property Config.Template,Name,Guest.ToolsStatus -Filter @{
"Config.Template"="False";"Guest.ToolsStatus"="^toolsOk";"Name"="^((?!_replica).)*$"} |
Select-Object Name,@{Name="ToolsStatus";E={$_.Guest.ToolsStatus}}
Since negative matching and RegEx is not too straightforward, in the end you might pick the more simple solution
Get-View -ViewType VirtualMachine -Property Config.Template,Name,Guest.ToolsStatus -Filter @{
"Config.Template"="False";"Guest.ToolsStatus"="^toolsOk"} |
where{$_.Name -notmatch "_replica$"} |
Select-Object Name,@{Name="ToolsStatus";E={$_.Guest.ToolsStatus}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That works to exclude the _replica VMs, but there seems to be an error with the way your filtered for ToolsOk. The output error only showed VMs with ToolsOK. So I edited it a little to this:
Get-View -ViewType VirtualMachine -Property Config.Template,Name,Guest.ToolsStatus -Filter @{
"Config.Template"="False";"Guest.ToolsStatus"="^(?!toolsOk$).*$" ;"Name"="^((?!_replica).)*$"} |
Select-Object Name,@{Name="ToolsStatus";E={$_.Guest.ToolsStatus}}
This worked, thank you so much!
Oops, misread that, thought you wanted the VMs with ToolsOk.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference