SHARE
TWEET

XE-Recreate-ISO-Store

alcaron Nov 27th, 2012 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-PSSnapin XenServerPSSnapin
  2. $strSrv = Read-Host "XenServer"
  3.  
  4. Get-Credential | Connect-XenServer -Server $strSrv
  5.  
  6. [psobject]$sr = Get-XenServer:SR | Where-Object{$_.content_type -eq "iso" -and $_.type -ne "udev" -and $_.name_label -ne "XenServer Tools"}
  7. "There are currently {0} ISO repositories." -f $sr.Count
  8.  
  9. foreach($tsr in $sr)
  10. {
  11.         $csr = $tsr.name_label
  12.         $destroy = Read-Host "Destroy the $csr SR? [y|n]"
  13.         if($destroy -eq "y")
  14.         {
  15.                 foreach($i in $tsr.PBDs){Invoke-XenServer:PBD.Unplug $i}
  16.                 Invoke-XenServer:SR.Forget -SR $tsr.name_label
  17.         }
  18. }
  19.  
  20. $destroy = $null
  21. $destroy = Read-Host "Create New ISO SR? [y|n]"
  22. if($destroy -eq "y")
  23. {
  24.         $srname = Read-Host "SR Name"
  25.         $srdesc = Read-Host "SR Description"
  26.         $srpath = Read-Host "SR Path (//host/path/dst)"
  27.         $creds = Read-Host "Specify credentials? [y|n]"
  28.         $uuid = (Get-XenServer:Host).uuid
  29.         if($creds -eq "n" -or $creds -eq $null){
  30.                 $config = @{"location" = "$srpath"}
  31.                 Create-XenServer:SR -Host $uuid -NameLabel $srname -NameDescription $srdesc -Type iso -ContentType iso -DeviceConfig $config
  32.         }elseif($creds -eq "y"){
  33.                 $creds = Get-Credential
  34.                 $config = @{"location" = "$srpath"; "username" = $creds.UserName; "cifspassword" = $creds.GetNetworkCredential().Password}
  35.                 Create-XenServer:SR -Host $uuid -NameLabel $srname -NameDescription $srdesc -Type "iso" -ContentType "iso" -DeviceConfig $config
  36.         }
  37. }
  38.  
  39. "Press any key to exit..."
  40. $exit = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top