Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 219257

Power CLI Code to seperate VM's

$
0
0

Hi Guys,

           I am trying to write a power CLI 6.0 script that will look at hosts in a cluster Host A and Host B then check to see if a particular VM is running on it in conjuction with its buddy. Lest say VMA and VMB. VMA needs to be on a seprate Host then VMB. If they are both running on the same host VMA on Host A and VMB on Host B it needs to promped the user if the script should migrate one VM to a different host. If one of the VM's are powerd off it needs to eithre option one tell the user the VM is powered off and migrate / power on on the other host or Tell the user the other host is still down and ask them if they still want to power it on the same blade. I am writting a script for users that are not VMware trained and we do not have the licensing for DRS so its like a manual check script to ensure our VM's are running on seprate servers for redundacy purposes. As we have High Avalability on we could get in a senario where one VM gets migrated to another blade but need the ability to move it back VIA power CLI. I am very new to Powershell / PowerCLI. I currently have a script that will alow me to initalize Power CLI in a native Power Shell enviroment as shown below. Just looking to build the If statement cases.

#Loading VMware PowerCLI PSSnapins and Modules for custom scripts

Add-PSSnapinVMware.VimAutomation.Core

Add-PSSnapinVMware.DeployAutomation

Add-PSSnapinVMware.ImageBuilder

if(get-itemHKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\VMware.VimAutomation.Core){

. ((get-itemHKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\VMware.VimAutomation.Core).GetValue("ApplicationBase")+"\Scripts\Initialize-PowerCLIEnvironment.ps1")

}

else

{

write-warning"PowerCLI Path not found in registry, please set path to Initialize-PowerCLIEnvironment.ps1 manually. Is PowerCli aleady installed?"

."D:\Programs (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"

}

#Connect to vCenter

$sVCenterHost="142.37.126.237"

Write-Host-NoNewline" Connecting to vCenter..."

Connect-VIServer$sVCenterHost-ErrorActionSilentlyContinue-WarningActionSilentlyContinue|out-null

if(!$?){

Write-Host-ForegroundColorRed" Could not connect to $sVCenterHost"

exit2

}

else{

Write-Host"ok"

}


Viewing all articles
Browse latest Browse all 219257

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>