• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Powershell Help

VeeDubbs

Limp Gawd
Joined
Dec 9, 2005
Messages
398
Hi all -

I'm using this Powershell script to send me an e-mail every Monday morning about snapshots in my VM environment -- very handy! However, we use Veeam for backup and replication, and all of my VMs are replicated to an off-site ESXi host with _replica after their name. All of the VMs with _replica have snapshots that I do not care about. How can I modify this script to ignore the snaps from VMs that have _replica in their name?

Thanks!


Code:
Add-PSSnapin VMware.VimAutomation.Core
connect-viserver -server $viserver -protocol https -user $viuser -password $vipass

$found_error=0
$error_count=0
$body="The following Virtual Machine(s) contain a Snapshot:`n"
$body2="Entire Log:`n"

$virtual_machines=Get-VM
foreach ($virtual_machine in $virtual_machines) {
	$snapshot=Get-Snapshot -VM $virtual_machine
	
	if ($snapshot) {
		$found_error=1
	        $error_count++

		Write-Host $virtual_machine.Name ": Snapshot found!"
		$body+="`t"+ $virtual_machine.Name +": Snapshot found! Snapshot name: "+ $snapshot.Name +"`n"
		$body2+="`t"+ $virtual_machine.Name +": Snapshot found! Snapshot name: "+ $snapshot.Name +"`n"
	} else {
		Write-Host $virtual_machine.Name ": Snapshot not found."
	        $body2+="`t"+ $virtual_machine.Name +": Snapshot not found.`n"
	}
}

if ($found_error) {
    $subject=$client +": "+ $error_count +" Snapshot(s) found!"
    $smtp = new-object System.Net.Mail.SmtpClient($smtp_host)
    $message = New-Object System.Net.Mail.MailMessage "${from}", "${to}", "${subject}", "${body}`n${body2}"
    $smtp.Send($message)
}
 
I'm not familiar with the VMware object model, but .... Wherever the VM's name (as a string) resides, you can do a ".Contains()" operation on it to let you know whether the name has a particular substring located in it:
Code:
$d = $a.Contains("ript")

The resulting boolean can be evaluated, which (given your requirements) would tell you whether to ignore that name or proceed with the work in the foreach loop.

http://technet.microsoft.com/en-us/library/ee692804.aspx
 
Back
Top