PSDrive Question

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Charles Downing Charles Downing 3 years, 8 months ago.

  • Author
    Posts
  • #9679
    Profile photo of baja63dhb
    baja63dhb
    Participant

    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!

  • #9682
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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.

  • #9686
    Profile photo of Charles Downing
    Charles Downing
    Participant

    It's a feature? 😉

You must be logged in to reply to this topic.