Author Posts

August 21, 2013 at 10:43 pm

I am working to get a better understanding how, and why the PSDrive functions work. On a side note I am very new to powershell.

I created the following:

$id = Get-Content Env:\USERNAME
$member = Get-ADPrincipalGroupMembership -Identity $id | Select-Object -Property name | Where-Object name -eq SomeADGroup
$BT = "SomeADGroup"
if ($member -match $bt)
{
New-PSDrive -Name r -PSProvider filesystem -Root \\some\nas\location -Persist
}

And this works with one hang up get-psdrive reports the following:

Name Used (GB) Free (GB) Provider Root
—- ——— ——— ——– —-
C 64.61 44.87 FileSystem C:\
D FileSystem D:\
r 160.24 539.76 FileSystem \\some\nas\location
R 160.24 539.76 FileSystem R:\

Why did my new-psdrive create 2 R drives, both case sensitive?

The Second issue is now when I use remove-psdrive The drive will be removed by PS will give me the following error:

Remove-PSDrive : Cannot find drive. A drive with the name 'r' does not exist.
At line:1 char:1
+ Remove-PSDrive r
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (r:String) [Remove-PSDrive], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemovePSDriveCommand

I am guessing it removes the first r: drive it finds and if one is removed they both are removed, and thats when Powershell error's out

Update:
I think I figured it out, when I was running this in the ISE it would create a Persist drive, and a non-Persist drive. if I closed and reopend the ISE and ran a get-psdrive I only showed the one R drive and the remove-PSdrive worked with no issue. Feel to offer up any pointers on what I have created thus far!

August 22, 2013 at 3:47 am

The ISE sometimes displays some screwy behavior if you have it running for a while (and, usually, have executed a lot of script code). I don't know why it happens, but restarting the ISE is always a good idea if you can't explain something.

August 22, 2013 at 5:32 am

It's a feature? 😉