Change root password XenServer pool

I have just finished creating a PowerShell script that changes the local root password for a Citrix XenServer pool.

You will find a ZIP file containing the script here: http://muya.no-ip.info/wordpress/wp-content/uploads/2011/09/Change-root-Password-XenServer.zip

 

Script:

function Get-EncryptedText($text) {

$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($text)

$result = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)

[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)

$result

}

Try {

Get-PSSnapin XenServerPSSnapin -ErrorAction Stop

}

Catch [Exception] {

If ($env:PROCESSOR_ARCHITECTURE -eq “AMD64”) {Invoke-Expression “$env:systemroot\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe ‘c:\Program Files (x86)\Citrix\XenServerPSSnapIn\XenServerPSSnapIn.dll'”; Add-PSSnapin XenServerPSSnapin}

If ($env:PROCESSOR_ARCHITECUTRE -eq “x86”){Invoke-Expression “$env:systemroot\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe ‘c:\Program Files\Citrix\XenServerPSSnapIn\XenServerPSSnapIn.dll'”; Add-PSSnapin XenServerPSSnapin}

}

 

$PoolMaster = Read-Host ‘Enter Poolmaster’

$Username = Read-Host ‘Enter Username’

$Password = Read-Host -AsSecureString ‘Enter Old Password’

$NewPassword = Read-Host -AsSecureString ‘Enter New Password’

$NewPasswordPlain = Get-EncryptedText $NewPassword$

PasswordPlain = Get-EncryptedText $Password

 

# // Build connection to xenserver

 

Try {

$Connect = [XenAPI.Session] ($(“https://” + $PoolMaster))

$Connect = Connect-XenServer -Server $PoolMaster -UserName $Username -Password $PasswordPlain -NoWarnCertificates

}

 

Catch [XenAPI.Failure] {

$Connect = Connect-XenServer -Server ($($_.exception.ErrorDescription[1])) -UserName $Username -Password $Password -NoWarnCertificates

}

 

# // Change Password

$Connect.change_password($PasswordPlain, $NewPasswordPlain)