VMware Cloud Community
shaffan331987
Enthusiast
Enthusiast
Jump to solution

Get-VMAdvancedConfiguration Help

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?

1 Solution

Accepted Solutions
shaffan331987
Enthusiast
Enthusiast
Jump to solution

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)

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

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

shaffan331987
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And like this ?

Get-VM | where{!(Get-AdvancedSetting -Entity $_ -Name log.keepOld)}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
shaffan331987
Enthusiast
Enthusiast
Jump to solution

That brings back both VMs that do and do not have the log.keepOld setting in place. 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, not sure I get what you mean there.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
shaffan331987
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
shaffan331987
Enthusiast
Enthusiast
Jump to solution

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)

Reply
0 Kudos