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

Powercli parallel commands

$
0
0

Hi guys,

 

i'am not quit sure how to manage it.   i try to connect to esxi hosts to sync away vm's in a suspended mode.  That works fine.

But it's just doing it 1 by a time and not parallel.

 

i'am not sure how i need to change the code that the sync is processing for each vm at the same time. i found    a info about "Foreach -Parallel"  but that gives me an error that the workflow is missing.

 

any ideas?

 

$content = get-content C:\Users\xxx\Documents\rsync-repl\servers.txt

$vms = get-vm $content |get-view

 

 

$suspend = get-vm $vms.name |suspend-vm -confirm:$False

 

 

$myColVM = @()

foreach ($vm in $vms){

$MyObjVM = "" | Select-Object Name,VolumePath,FolderName,Path

$MyObjVM.Name = $vm.name

$MyObjVM.VolumePath = $vm.config.datastoreurl.url

$MyObjVM.FolderName = ((($vm.Summary.Config.VmPathName).Split(']')[1]).Split('/'))[0].TrimStart(' ')

$MyObjVM.path = $MyObjVM.VolumePath+"/"+$MyObjVM.FolderName

$myColVM += $MyObjVM

}

 

 

$Plink = "C:\Users\xxx\Documents\rsync-repl\plink.exe"

$pass = Read-Host "Enter Pass" -AsSecureString

$SSTU = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($pass)

$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($SSTU)

$vmhost = "xxxx"

 

 

 

foreach ($path in $myColVM.path){

$plinkC = '-ssh $vmhost -l root -pw $password -P 22'

$Command1 = "rsync --delete -arvh --progress --exclude '*.*log' --exclude '*.vmem' --exclude '*.vmss'  --exclude '*.vmsd'  --no-whole-file --sparse $path rsync://xxxxxxx/$vmhost"

$plinkconnect = "$plinkC"

$plinkoptions = "$plinkC $Command1"

$PlinkCache   = [string]::Format('echo y | & "{0}" {1} exit', $plink, $plinkconnect)

$PlinkCommand  = [string]::Format(' & "{0}" {1} ', $plink, $plinkoptions)

$invokePlinkCache = Invoke-Expression $PlinkCache

$InvokePlinkCommand = Invoke-Expression $PlinkCommand |out-file "C:\Users\xxx\Documents\rsync-repl\clients\$vmhost"

$Resume = get-vm $vms.name |start-vm -confirm:$False

}

 

thx

 

Max


Viewing all articles
Browse latest Browse all 219257

Trending Articles



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