So I'm trying to run a script that looks for servers that do not have a certain key listed, instead of the opposite. So currently, I can run:
Get-VM | Get-VMAdvancedConfiguration -key log.keepOld and it will give me all the servers in the vCenter I'm connected to that do have the log.keepOld setting. Anyone know how I would do the opposite though, and return the servers that do not have that advanced setting?
Actually- added an If statement and it's working now. In case anyone's interested:
foreach ($vm in Get-VM)
{
$keepOld = Get-VMAdvancedConfiguration -vm $vm -key log.keepOld
if (-not $keepOld)
{ Write-Output ($vm.Name)
You could do
Get-VM | where{!(Get-VMAdvancedConfiguration -key log.keepOld)}
The Where-clause will only let VMs pass that return nothing on the Get-AdvancedConfiguration call.
And the negation :smileyalert: of $null is considered true
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks- that doesn't seem to work though. It doesn't pass the variable, so it asks for the VM variable. When I put that in, it doesn't give the correct info:
Get-VM $vm | where{!(Get-VMAdvancedConfiguration -vm $vm -key log.keepOld)}
where $vm equaled a VM with the log.keepold key set, the command I ran showed the server anyway.
And like this ?
Get-VM | where{!(Get-AdvancedSetting -Entity $_ -Name log.keepOld)}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That brings back both VMs that do and do not have the log.keepOld setting in place.
Sorry, not sure I get what you mean there.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So I run the following command:
Get-VM | where{!(Get-AdvancedSetting -Entity $_ -Name log.keepOld)}
And it shows me all servers. This includes servers that have the log.keepOld setting in place and servers which do not have that setting in place.
Actually- added an If statement and it's working now. In case anyone's interested:
foreach ($vm in Get-VM)
{
$keepOld = Get-VMAdvancedConfiguration -vm $vm -key log.keepOld
if (-not $keepOld)
{ Write-Output ($vm.Name)
