#Set-ExecutionPolicy RemoteSigned
# VMware vSphere PowerCLI
if (((Get-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null ) -and ((Get-PSSnapin–registered -Name "VMware.VimAutomation.Core") -ne $null))
{
Write-Host "Adding VMware vSphere PowerCLI" -ForegroundColor Green
Add-PSSnapin -name VMware.VimAutomation.Core
."C:\Program Files (x86)\VMware\Infrastructure\ vSphere PowerCLI\Scripts\Initialize- PowerCLIEnvironment.ps1"
}
$vmmodule = Get-PSSnapin -Name "VMware.VimAutomation.Core"
if (!$vmmodule) {
[System.Reflection.Assembly]:: LoadwithPartialName("System. windows.Forms")
[System.windows.Forms. MessageBox]::Show("We dont got the VM powerCLI module.")
exit
} else {
echo "Module $vmmodule loaded successfully"
}
# SSH-Sessions Module load
$sshmodule = Get-Module -List 'SSH-Sessions'
if (!$sshmodule) {
[System.Reflection.Assembly]:: LoadwithPartialName("System. windows.Forms")
[System.windows.Forms. MessageBox]::Show("We dont got the SSh-Sessions module.")
exit
} else {
Import-Module SSH-Sessions
echo "Module $sshmodule loaded successfully"
}
#Connect to Vcenter
$Viserver = Connect-VIServer -Server 'IP' -User 'username' -Password 'password'
If (!$viserver) {
[System.Reflection.Assembly]:: LoadwithPartialName("System. windows.Forms")
[System.windows.Forms. MessageBox]::Show("We dont connect to FTvcenter01.")
exit
} else {
echo "Connect to vcenter success"
}
Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Where-Object {$_.Name -ne "vcenter"} | Shutdown-VMGuest -Confirm:$false
Start-
#Get-VM
#Start-Sleep -s 600
#Get-VMHost | Stop-VMHost -Confirm:$false
#Get-VMHost
#Start-Sleep -s 300
#SSH to NetApp
$naserver = New-SshSession -ComputerName 'IP for 1st','IP for 2nd' -Username 'username' -Password 'password'
If (!$naserver) {
[System.Reflection.Assembly]:: LoadwithPartialName("System. windows.Forms")
[System.windows.Forms. MessageBox]::Show("We dont connect to NetApp Controller.")
exit
} else {
echo "Connect to NetApp Controller success"
}
exit
#Invoke-Sshcommand -InvokeOnAll -Command 'halt -t 0 -f'
#Invoke-Sshcommand -InvokeOnAll -Command 'ifconfig -a'
#Remove-SshSession -RemoveAll
沒有留言:
張貼留言