I'm connecting a PSDrive from a machine running SCCM and trying to do a test-path to work out whether or not to create a given directory.
However test-path is returning $false
for directories that do indeed exist (as a matter of fact I can even tab-complete the paths in the PoSh window)
My PSDrive connection code is as follows:
New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName -Scope global
This returns a PSDrive as "RED" which returns a $true
result:
PS C:\> test-path RED:\
True
However when I try and test anything below that it returns $false
and if I try and create the new-item it fails
PS C:\> test-path RED:\Driver\Dell\WinPE\
False
PS C:\> new-item RED:\Driver\Dell\WinPE\
new-item : Path already exists.
At line:1 char:1
+ new-item RED:\Driver\Dell\WinPE\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (OBFUSCATED\Driver\Dell\WinPE\:String) [New-Item], InvalidOperationException
+ FullyQualifiedErrorId : Path,Microsoft.PowerShell.Commands.NewItemCommand
(I've obfuscated the FQDN of the machine)
This is what I get if I run a get-item
on the path:
PSPath : AdminUI.PS.Provider\CMSite::OBFUSCATED\Driver\Dell
PSParentPath : AdminUI.PS.Provider\CMSite::OBFUSCATED\Driver
PSChildName : Dell
PSDrive : RED
PSProvider : AdminUI.PS.Provider\CMSite
PSIsContainer : True
SmsProviderObjectPath : SMS_ObjectContainerNode.ContainerNodeID=16777240
ContainerNodeID : 16777240
FolderFlags : 0
FolderGuid : 1DAF9853-75BE-4629-97EF-0689D9E02961
IsEmpty : False
Name : Dell
ObjectType : 25
ObjectTypeName : SMS_Driver
ParentContainerNodeID : 0
SearchFolder : False
SearchString :
SourceSite : RED
I tried specifying CMSite::
while running test-path
and that didn't help either.
Any ideas on what I'm doing wrong to trip this up?