Hi guys,
I would like to upload a few VMDK files to a datastore using PowerCLI and I have been using the below script from LucD, however it does one file at a time, is there a way to have the command run asynchronously, and be able to have it output the progress of each transfer? I thought about putting it inside a job, but I don't see how I can retrieve the progress.
$fileName = 'F:\VM1_disk1.vmdk'
$tgtFolder = 'VM1'
$ds = Get-VMHost -Name "host1.com" | Get-Datastore "DS-LUN01"
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" > $null
if(!(Test-Path -Path "DS:/$($tgtFolder)")){
New-Item -ItemType Directory -Path "DS:/$($tgtFolder)" > $null
}
Copy-DatastoreItem -Item $fileName -Destination "DS:/$($tgtFolder)"
$fileName = 'F:\VM2_disk1.vmdk'
$tgtFolder = 'VM2'
$ds = Get-VMHost -Name "host1.com" | Get-Datastore "DS-LUN01"
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" > $null
if(!(Test-Path -Path "DS:/$($tgtFolder)")){
New-Item -ItemType Directory -Path "DS:/$($tgtFolder)" > $null
}
Copy-DatastoreItem -Item $fileName -Destination "DS:/$($tgtFolder)"
Remove-PSDrive -Name DS -Confirm:$false
The problem might be that you can't really find out how long such a copy job might take.
So even inside one such job, how could you determine a 'percent complete'?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey LucD,
The Copy-DatastoreItem command does display a percentage when it's running, so was thinking of putting it within a hashtable and calling the key to get the state.
Or even within the job itself having it output to a file I could then read.
But, not sure if it's possible as the command doesn't seem to allow it to be run as async
Afaik, the Progress Bar the cmdlet shows is internal to the cmdlet.
I don't think you can read out that value easily from a PS script and store it somewhere.
There seems to be a possibility via an event handler, but I haven't played with that.See Reading PowerShell Progress Bar output in C#
https://stackoverflow.com/questions/34814719/reading-powershell-progress-bar-output-in-c-sharp
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, will take a look.