VMware Cloud Community
prd
Enthusiast
Enthusiast
Jump to solution

Rename Datastores

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

}

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
prd
Enthusiast
Enthusiast
Jump to solution


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!!!!!

Reply
0 Kudos