System Center Configuration Manager - PowerShell Remoting


I have a primary SCCM server - "ABC"

Later I installed SCCM console and PowerShell Module on one more machine - "XYZ"

I am running below script from server - "OPQ" and trying to remote "XYZ" (on which i installed SCCM Console Recently)

Script ::

$Session = New-PSSession -ComputerName "XYZ" -Authentication Kerberos -Credential $Cred -ConfigurationName Microsoft.PowerShell32

Invoke-Command -Session $Session -ScriptBlock {
Import-module "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"

    Set-Location PS1:\


Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) + CategoryInfo : OpenError: (PS1:PSDriveInfo) [Import-Module], UnauthorizedAccessException + FullyQualifiedErrorId : Drive,Microsoft.PowerShell.Commands.ImportModuleCommand + PSComputerName : XYZ

Cannot find drive. A drive with the name '' does not exist. + CategoryInfo : ObjectNotFound: (PS1:String) [Set-Location], DriveNotFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand + PSComputerName : XYZ

asked on Stack Overflow Mar 31, 2020 by DBA Admin • edited Mar 31, 2020 by Theo

2 Answers


Well it appears you have a permissions issue. Here is how I executed a remote command in my SCCM environment, via my PSS:

 $device = Invoke-Command -Session $sess -ScriptBlock {
 Import-Module (Join-Path (Split-Path $env:SMS_ADMIN_UI_PATH) 
 Push-Location -Path ((Get-WmiObject -Namespace "root\SMS" -Class 
 "SMS_ProviderLocation" | Select-Object -ExpandProperty SiteCode) + ":")
 Get-CMDevice -Name $env:COMPUTERNAME
 RunspaceId                        : cbc7e008-d92c-4ba3-94a3-b75f8005be98
 SmsProviderObjectPath             : SMS_CM_RES_COLL_SMS00001.ResourceID=16777221
 AADDeviceID                       : 00000000-0000-0000-0000-000000000000
 AADTenantID                       : 00000000-0000-0000-0000-000000000000
 ActivationLockBypassState         :
 ActivationLockState               :
 ADLastLogonTime                   : 3/31/2020 11:23:38 PM
 ADSiteName                        : XXXX-XX

Note that if you're not remoting to your PSS, you will need to specify your PSS in the Get-WmiObject command, e.g.:

 (Get-WmiObject -ComputerName [YOUR PSS] -Namespace "root\SMS" -Class "SMS_ProviderLocation" | Select-Object -ExpandProperty SiteCode) + ":"
answered on Stack Overflow Apr 1, 2020 by RobotScience

I was able to resolve this issue by saving the credentials on the XYZ server and then calling them under my INvoke-Command.

Like This  : 

$Session = New-PSSession -ComputerName "XYZ" Invoke-Command -Session $Session -ScriptBlock { $password = Get-Content -Path D:\Creds\creds.txt | ConvertTo-SecureString $Cred = New-Object System.Management.Automation.PSCredential ("domain\UserId", $password) Then the rest of the code. ... .. . . . }

answered on Stack Overflow Apr 1, 2020 by DBA Admin

User contributions licensed under CC BY-SA 3.0