Search code examples
powershellpowershell-remotingsccm

Powershell cd sitecode not working


I am trying to run CD to SCCM site folder after Import-Module ConfigurationManager.psd1 on a remote computer as a Non-Admin user. However I am gettting the following error:

PS C:\windows\system32> Enter-PSSession -ComputerName somecomputer -Credential Sccm\u6
[somecomputer]: PS C:\Users\u6\Documents> Import-Module ConfigurationManager.psd1
[somecomputer]: PS C:\Users\u6\Documents> cd 1SA:
cd : Cannot find drive. A drive with the name '1SA' does not exist.
    + CategoryInfo          : ObjectNotFound: (1SA:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

I can get around this issue by following the documentation given on this link: http://benef-it.blogspot.in/2013/04/solve-ps-drive-problem-with-sccm2012.html

But how can I do this programmatically from within powershell?


Solution

  • Ok found the solution to this

    New-PSDrive -Name $sitecode -PSProvider "AdminUI.PS.Provider\CMSite" -Root "$ENV:ComputerName" -Description "SCCM Site"
    

    Running the above command creates the drive which you can subsequently use.

    Refer: https://social.technet.microsoft.com/Forums/en-US/3c5aee8b-a7ea-4b74-8b13-a2569b88bd5f/newpsdrive-returns-error-object-reference-not-set-to-an-instance-of-an-object?forum=configmanagersdk