To start off, I have very minimal coding/scripting skills. However, I am tasked with finding this solution:
I need a script that will go through the VMS in a VCenter, Identify them by the host OS, and then moving them into a specified folder such as "Linux" or " Windows"
thoughts?
$VMs = Get-VM
Foreach ($VM in $VMs)
{
If ($VM.Extensiondata.guest.guestfamily -match "linux") {Move-VM -VM $VM -Destination (Get-Folder Linux)}
Else {Move-VM -VM $VM -Destination (Get-Folder Windows)}
}
Or something along these lines.
somewhat helpful, but just moves everything not linux into the Windows Folder, when it just needs to move the windows machines into the windows folder
Then just do this:
$VMs = Get-VM
Foreach ($VM in $VMs)
{
If ($VM.Extensiondata.guest.guestfamily -match "windows") {Move-VM -VM $VM -Destination (Get-Folder Windows)}
}
You can add more if statements if you want to move different OS's into different folders too.
Can we make it so in only looks in the "Discovered Virtual Machine folder" and not the whole inventory?
Try something like this
$VMs = Get-Folder -Name "Discovered Virtual Machine folder" | Get-VM
Foreach ($VM in $VMs){
If ($VM.Extensiondata.guest.guestfamily -match "windows") {
Move-VM -VM $VM -Destination (Get-Folder Windows)
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference