Hello all. I have a simple script to rename datastores. Input is a list of Datastore names. New name is current datastore name prepended by "DoNotUse." However it is very slow.
Any suggestions on speeding it up? Thank you very much
$DSList = Get-Content -Path c:\temp\DSlist.txt
Foreach ($DS in $DSList){
$NewDS = "DoNotUse_$DS"
Get-Datastore -Name $DS | Set-Datastore -Name $NewDS
}
See if the following is faster
$dsList = Get-Content -Path c:\temp\DSlist.txt
$filter = $dsList -join '|'
Get-View -ViewType Datastore -Property Name -Filter @{'Name'=$filter} | %{
$_.Rename("DoNotUse_$($_.Name)")
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
See if the following is faster
$dsList = Get-Content -Path c:\temp\DSlist.txt
$filter = $dsList -join '|'
Get-View -ViewType Datastore -Property Name -Filter @{'Name'=$filter} | %{
$_.Rename("DoNotUse_$($_.Name)")
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you Luc! That did it. See difference:
My script:
PowerCLI C:\temp> measure-command {.\Test.ps1}
TotalSeconds : 57.1541357
Your script:
PowerCLI C:\temp> measure-command {.\Test1.ps1}
TotalSeconds : 24.5906194
I had tried Get-View but failed miserably. Your example was very helpful!!!!!