Psdrive is similar to, but not the same, as subst. The behavior you experience is exactly what should be happening.
What are you trying to do? -----Original Message----- From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Michael Leone Sent: Wednesday, August 7, 2013 1:12 PM To: powershell@lists.myitforum.com Subject: [powershell] Confused about PSDrive So I am writing a script, where I want to read in files from 2 directories. And I want to access them as if they were 2 separate drive letters (to emulate the configuration on another machine, where I will eventually run this script). So, if I use a SUBST command, all works correctly: Z:\>subst I: D:\Testing\SyncCheckDirs\Web01 Script: --------------- $Web01_Dir = "I:\PHAWebsiteR2\media" $Web01_Drv_Letter = "I" $Web01_Files = Get-ChildItem -Path $Web01_Dir -recurse | Sort ForEach ($LeftFile in $Web01_Files) { $ThisFile = $LeftFile.FullName Write-Host "FullName = " $LeftFile.FullName } --------------- And I get this: PS Z:\PHA Scripts> .\Test-PSDrive.PS1 FullName = I:\WebsiteR2\media\10022 FullName = I:\WebsiteR2\media\10037 IOW , I see the SUBST drive letter, and not the actual path of "D:\Testing\SyncCheckDirs\Web01". Great! Exactly as I expect, and want. BUT: If I don't do a SUBST at the command line first, and instead include a line to use New-PSDrive: --------------- $Web01_Dir = "I:\PHAWebsiteR2\media" $Web01_Drv_Letter = "I" New-PSDrive -name $Web01_Drv_Letter -PSProvider FileSystem -root D:\Testing\SyncCheckDirs\Web01 $Web01_Files = Get-ChildItem -Path $Web01_Dir -recurse | Sort ForEach ($LeftFile in $Web01_Files) { $ThisFile = $LeftFile.FullName Write-Host "FullName = " $LeftFile.FullName } --------------- I get this: FullName = D:\Testing\SyncCheckDirs\Web01\WebsiteR2\media\10022 FullName = D:\Testing\SyncCheckDirs\Web01\WebsiteR2\media\10037 IOW,the result isn't using the "mapped" drive letter of I:, as it does if I do a SUBST from the command line. And I don't know why. Shouldn't the result of using the New-PSDrive command cause a Get-ChildItem to return results using the PSDrive letter? It seems to be ignoring that, and giving me the actual, i.e., non-aliased, path. I want the result to include the PSDrive letter; how can I do that? (this will influence the rest of the script, as I process the file) I've read that New-PSDrive gives similar results to the SUBST command, but this seems not to be the case for me. What concept am I missing, or doing wrong here? Thanks ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1