VMware Cloud Community
digitaldybbuk
Contributor
Contributor
Jump to solution

Mounted drive is suddenly non-existent after Get-ChildItem is used with a wildcard

I use this function to mount the drive

Function MountDrive() {

     $name = "Functional_Storage"

     $datastore = Get-Datastore $name

     New-PSDrive -Location $datastore -Name fs -PSProvider VimDatastore -Root "\"

     cd fs:

}

I now try to do a directory listing using a wildcard

PS fs:\> Get-ChildItem "Somthing*"

Get-ChildItem : Cannot find drive. A drive with the name 'fs' does not exist.

At line:1 char:14

+ Get-ChildItem <<<<  "Somthing*"

    + CategoryInfo          : ObjectNotFound: (fs:String) [Get-ChildItem], DriveNotFoundException

    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

However, if I had just issued a Get-Childitem, no error occurs... how is it that fs becomes non-existent only if I use a wildcard?

-MC
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect that this might be a scope issue.

You set up the psdrive inside a function, but you seem to perform the Get-ChildItem outside the function.

I think the psdrive is only available inside the function.


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect that this might be a scope issue.

You set up the psdrive inside a function, but you seem to perform the Get-ChildItem outside the function.

I think the psdrive is only available inside the function.


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

0 Kudos
digitaldybbuk
Contributor
Contributor
Jump to solution

***UPDATE*** : Yep. You are right.

I think you're right. I have been having some trouble about scope and this happens when I am using the function with "interactive mode," thanks for clearing this up

-MC
0 Kudos