2

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?

Steve Brown
  • 77
  • 1
  • 9

1 Answers1

0

The fix to this turned out to be super simple in the end.

Deleting the trailing slash appears to have fixed it:

PS C:\> test-path RED:\Driver\Dell\WinPE\
False
PS C:\> test-path RED:\Driver\Dell\WinPE
True

I'm not sure exactly why this is however.

Steve Brown
  • 77
  • 1
  • 9
  • 1
    For anybody curious on why the trailing slash is an issue, I'm fairly certain it's because "folders" in SCCM aren't exactly the same thing as we see in something like Windows Explorer. Folders in SCCM were an added functionality due to user demand, so it was jammed in and made to look and act like folders, almost... For example, the recurse option isn't available. Folders in SCCM are actually just Database notations, and work off NodeID's and container Nodes. The CMSITE PS-Drive provider adds a lot of options we're familiar with, but it's a fancy coating over chicken-wire and duct-tape. – Cthanatos Mar 30 '23 at 16:02