Hello.
I'd like to get a list which of the VMs in $VM is powered based on a listed of VMs with a particular attached security tag:
$VM = Get-NsxSecurityTag | where-object { $_.name -like "MCAFEE.MOVE.unprotected=yes" } | Get-NsxSecurityTagAssignment | Select-Object VirtualMachine | ft -hidetableheaders.
Each line in $VM is just the VMs name
but GET-VM $VM seems to expect more.
/Peter
Get-VM expectes one VM as argument.
I think you have multiple VMs in $VM.
Just try a foreach loop over $VM:
foreach ($singlevm in $VM){
Get-VM -Name $singlevm
}
Get-VM expectes one VM as argument.
I think you have multiple VMs in $VM.
Just try a foreach loop over $VM:
foreach ($singlevm in $VM){
Get-VM -Name $singlevm
}
Hello aleex42
Thank you for your input.
1)
*****
If I set
$VM = Get-NsxSecurityTag | where-object { $_.name -like "MCAFEE.MOVE.unprotected=yes" } | Get-NsxSecurityTagAssignment | Select-Object VirtualMachine | ft -hidetableheaders
I get this error for each line in $VM:
"
Get-VM : 09-07-2018 15:39:03 Get-VM VM with name 'Microsoft.PowerShell.Commands.Internal.Format.FormatEndData' was not found using the specified filter(s).
At line:3 char:6
+ Get-VM -Name $singlevm
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
"
2
*****
If I set
$VM = Get-NsxSecurityTag | where-object { $_.name -like "MCAFEE.MOVE.unprotected=yes" } | Get-NsxSecurityTagAssignment | Select-Object VirtualMachine
I get:
"
Get-VM : 09-07-2018 15:41:01 Get-VM VM with name '@{VirtualMachine=V00606}' was not found using the specified filter(s).
At line:3 char:6
+ Get-VM -Name $singlevm
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
"
3
*****
If I set
$VM = Get-NsxSecurityTag | where-object { $_.name -like "MCAFEE.MOVE.unprotected=yes" } | Get-NsxSecurityTagAssignment
I get:
"
Get-VM : 09-07-2018 15:42:08 Get-VM VM with name '@{SecurityTag=System.Xml.XmlElement; VirtualMachine=V00606}' was not found using the specified filter(s).
At line:3 char:6
+ Get-VM -Name $singlevm
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
"
/Peter
Ahhh!
Got it! Each VM in the list has trailing spaces galore.
I trimmed the text file and this works:
$VMFile = "C:\Users\blahblahblah\Documents\VM.txt"
$VM = Get-Content $VMFile
foreach ($singlevm in $VM){Get-VM -Name $singlevm | where-object {$_.PowerState -eq "poweredON" }}
/Peter