VMware Cloud Community
halr9000
Commander
Commander

change parameter order for new-folder?

case#1 doesn't work:

85# Get-Folder vm | New-Folder bat
New-Folder : Cannot bind parameter 'Location'. Cannot convert value "bat" to
type "VMware.VimAutomation.Types.VIContainer". Error: "Invalid cast from 'Sys
tem.String' to 'VMware.VimAutomation.Types.VIContainer'."
At line:1 char:27
+ Get-Folder vm | New-Folder <<<<  bat

case#2 works:

86# Get-Folder vm | New-Folder -Name bat

Name                           Id
----                           --
bat                            Folder-group-v478

From help (snipped):

-Location <VIContainer>
Position? 1
-Name <String>
Position? 2

If the position of these two params were reversed, then case #1 and case #2 would both work.

Since "name" is not accepted on the pipeline, you cannot do the reverse (e.g. "folder name" | new-folder -location "vm"), so there's really no reason to have Location be param #1 from what I can tell.

Agree? Disagree?

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Tags (2)
0 Kudos
1 Reply
LucD
Leadership
Leadership

Are you sure that "name" is not accepted on the pipe?

I could do

"bat" | New-Folder -Location (Get-Folder vm)

without a problem.

On the other hand I have to agree that "name" is probably what will be used most in a call to New-Folder.

So I agree that the "name" parameter should have position 1.


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

0 Kudos