Hello guys,
I'm new to powershell and I want to try and create a script that is taking snapshot of several VMs. The trick is I need to somehow filter the output. These are the vm names: srv1, srv2, srv1-temp, srv2-temp, srv3, srv1test, srv2test.
Example:
New-Snapshot -VM(Get-VM -Name "srv*") -Name pre-upgrade
We need to create a snapshot of all but the first two. Using "Get-VM -name srv*" is returning all of them.
Is there a way to filter them out?
One more question:
Can we use the credentials of currently logged on user instead of providing user name and password in "Connect-VIServer"?
If this is your full list:
srv1, srv2, srv1-temp, srv2-temp, srv3, srv1test, srv2test.
Then just do something like:
$vms = ("srv1-temp"," srv2-temp","srv3","srv1test","srv2test")
foreach ($vm in $vms){New-Snapshot -VM (Get-VM -Name $vm) -Name pre-upgrade}
If this is your full list:
srv1, srv2, srv1-temp, srv2-temp, srv3, srv1test, srv2test.
Then just do something like:
$vms = ("srv1-temp"," srv2-temp","srv3","srv1test","srv2test")
foreach ($vm in $vms){New-Snapshot -VM (Get-VM -Name $vm) -Name pre-upgrade}
for a tutorial on credentials,see
http://www.brangle.com/wordpress/2009/08/pass-credentials-via-powershell/
you can save the creds and re-use them (so you can schedule your script and have no clear text passwords anywhere)
Thanks, looks like this is it. I'll try it tomorrow.
Anyway, if I do need to use some kine of exclusion, is it possible?
Lets say use the "where-object" with "-ne" parameter, but combine two of those, with an AND statement or something like that...
?