VMware Cloud Community
clarky_ba
Contributor
Contributor
Jump to solution

Is there a quicker way to Remove-Folder

Doing up some automation scripts to mass create folders with associated cleanup scripts and wondering if anybody has come up with a quicker way to execute... Similar to LucD's get-vm vs get-view?

PowerCLI C:\temp> Measure-Command {Get-Folder -Name "Solutions Design 7" | Remove-Folder -Confirm:$false}
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 7
Milliseconds      : 414
Ticks             : 74143023
TotalDays         : 8.58136840277778E-05
TotalHours        : 0.00205952841666667
TotalMinutes      : 0.123571705
TotalSeconds      : 7.4143023
TotalMilliseconds : 7414.3023

PowerCLI C:\temp> measure-command {Remove-Folder "Solutions Design 6" -Confirm:$false}

Days              : 0

Hours             : 0

Minutes           : 0

Seconds           : 7

Milliseconds      : 228

Ticks             : 72287489

TotalDays         : 8.36660752314815E-05

TotalHours        : 0.00200798580555556

TotalMinutes      : 0.120479148333333

TotalSeconds      : 7.2287489

TotalMilliseconds : 7228.7489

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try this variation

Get-View -ViewType Folder -Filter @{"Name"="^Solutions Design 7$"} | %{
  $_.Destroy_Task()
}

The filter uses RegEx expression on the rightside operand, hence the ^ and $ meta-characters.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try this variation

Get-View -ViewType Folder -Filter @{"Name"="^Solutions Design 7$"} | %{
  $_.Destroy_Task()
}

The filter uses RegEx expression on the rightside operand, hence the ^ and $ meta-characters.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
clarky_ba
Contributor
Contributor
Jump to solution

Ever so slightly quicker...

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Measure-Command {Get-View -ViewType Fo
lder -Filter @{"Name" = "^Prod$"} | %{ $_.Destroy_Task() }}
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 482
Ticks             : 4820769
TotalDays         : 5.57959375E-06
TotalHours        : 0.00013391025
TotalMinutes      : 0.008034615
TotalSeconds      : 0.4820769
TotalMilliseconds : 482.0769

Like Wow...

thansk LucD

0 Kudos