Difference between revisions of "Script Extracts and Examples (PowerCLI)"

Jump to navigation Jump to search
m
→‎Daily ESX Up/Down Check: Added link to Store_Password_Securely
m (→‎Daily ESX Up/Down Check: Added link to Store_Password_Securely)
Line 827: Line 827:
=== Daily ESX Up/Down Check ===
=== Daily ESX Up/Down Check ===
Simple script that runs every morning just before I start work to provide a basic sanity check email to glance through over the first tea of the day.
Simple script that runs every morning just before I start work to provide a basic sanity check email to glance through over the first tea of the day.
See the following page for details on how to [[Power_Shell#Store_Password_Securely Store Password Securely]] (as I have done, loaded though the files specified by <code>$UserFile</code> and <code>$PassFile</code> in the script below).


<source lang="Powershell" enclose="div">
<source lang="Powershell" enclose="div">
Line 868: Line 870:
$EmailRecipients = "person1@domain.com,person2@domain.com"
$EmailRecipients = "person1@domain.com,person2@domain.com"
$EmailSender = "VI-Mgmt@domain.com"
$EmailSender = "VI-Mgmt@domain.com"
$UserFile = "User.fil"
$PassFile = "Pass.fil"


$smtp = New-Object Net.Mail.SmtpClient -arg "smtp-server.domain.com"
$smtp = New-Object Net.Mail.SmtpClient -arg "smtp-server.domain.com"
Line 883: Line 888:
}
}


$pass = Get-Content "Cred.fil" | ConvertTo-SecureString  
$pass = Get-Content $PassFile -errorAction Stop | ConvertTo-SecureString  
$cred = New-Object System.Management.Automation.PsCredential("MPADGLOBAL\simonstrutt",$pass)
$user = Get-Content $UserFile -errorAction Stop
$cred = New-Object System.Management.Automation.PsCredential($user, $pass)


foreach ($vc in $ToCheck) {
foreach ($vc in $ToCheck) {

Navigation menu