简体   繁体   English

System Center Configuration Manager - PowerShell 远程处理

[英]System Center Configuration Manager - PowerShell Remoting

I have a primary SCCM server - "ABC"我有一个主 SCCM 服务器 - “ABC”

Later I installed SCCM console and PowerShell Module on one more machine - "XYZ"后来我在另一台机器上安装了 SCCM 控制台和 PowerShell 模块 - “XYZ”

I am running below script from server - "OPQ" and trying to remote "XYZ" (on which i installed SCCM Console Recently)我正在从服务器运行脚本-“OPQ”并尝试远程“XYZ”(我最近在其上安装了 SCCM 控制台)

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:\
}

ERROR ::错误 ::

Access is denied.访问被拒绝。 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) + CategoryInfo : OpenError: (PS1:PSDriveInfo) [Import-Module], UnauthorizedAccessException + FullyQualifiedErrorId : Drive,Microsoft.PowerShell.Commands.ImportModuleCommand + PSComputerName : XYZ (来自 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 + CategoryInfo : ObjectNotFound: (PS1:String) [Set-Location], DriveNotFoundException + FullQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand + PSComputerName : XYZ

Well it appears you have a permissions issue.好吧,看来您有权限问题。 Here is how I executed a remote command in my SCCM environment, via my PSS:以下是我通过 PSS 在 SCCM 环境中执行远程命令的方法:

 $device = Invoke-Command -Session $sess -ScriptBlock {
 Import-Module (Join-Path (Split-Path $env:SMS_ADMIN_UI_PATH) 
 ConfigurationManager.psd1)
 Push-Location -Path ((Get-WmiObject -Namespace "root\SMS" -Class 
 "SMS_ProviderLocation" | Select-Object -ExpandProperty SiteCode) + ":")
 Get-CMDevice -Name $env:COMPUTERNAME
 Pop-Location
 }
 $device
 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, eg:请注意,如果您不远程连接到 PSS,则需要在 Get-WmiObject 命令中指定您的 PSS,例如:

 (Get-WmiObject -ComputerName [YOUR PSS] -Namespace "root\SMS" -Class "SMS_ProviderLocation" | Select-Object -ExpandProperty SiteCode) + ":"

通过将凭据保存在 XYZ 服务器上,然后在我的 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. ... .. . . . }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM