VMware Cloud Community
MHEUser
Contributor
Contributor
Jump to solution

Snapshot automation

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"?

0 Kudos
1 Solution

Accepted Solutions
bulletprooffool
Champion
Champion
Jump to solution

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}

One day I will virtualise myself . . .

View solution in original post

0 Kudos
3 Replies
bulletprooffool
Champion
Champion
Jump to solution

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}

One day I will virtualise myself . . .
0 Kudos
bulletprooffool
Champion
Champion
Jump to solution

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)

One day I will virtualise myself . . .
MHEUser
Contributor
Contributor
Jump to solution

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...

?

0 Kudos