简体   繁体   English

来自SCCM的本地用户的Powershell VSCode invoke-command

[英]Powershell VSCode invoke-command from localhost different user for SCCM

Because VSCode is not able to run a powershell console and debug it as a different user i am trying to get arround it with invoked credentials like this: 由于VSCode无法运行Powershell控制台并以其他用户身份对其进行调试,因此我尝试使用调用的凭证将其环绕,例如:

Start-Service -Name "WinRM"
$cred = Get-Credential -Credential domain\myuser
Invoke-command -Credential $cred -Computer "localhost" -scriptblock {

    Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1"
    Set-Location 'XXX:' # my sccm site code
    Import-CMComputerInformation -CollectionName "All Systems" -ComputerName "TestComputer" -MacAddress "00:00:00:00:00:69"

}

If i start it in the debugger of VSCode (F5) it starts but cant connect then to the SCCM Server infrastructure. 如果我在VSCode(F5)的调试器中启动它,它将启动但无法连接到SCCM Server基础结构。 Could someone help me to solve this issue? 有人可以帮我解决这个问题吗?

Error: 错误:

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

This command cannot be run from the current drive. To run this command you must first connect to a Configuration Manager drive.
    + CategoryInfo          : DeviceError: (Microsoft.Confi...ormationCommand:ImportComputerInformationCommand) [Import-CMComputerInformation], InvalidOperationException
    + FullyQualifiedErrorId : CommandCannotExecuteFromCurrentDrive,Microsoft.ConfigurationManagement.Cmdlets.Oob.Commands.ImportComputerInformationCommand
    + PSComputerName        : localhost

If i logoff from my machine and login with my admin credentials and execute everything in the invoke-command scriptblock it works. 如果我从计算机注销并使用我的管理员凭据登录,并在invoke-command脚本块中执行所有操作,则它会起作用。 As i am not allowed to work like this by our company policy's is there maybe a alternative way or something i can do to use the visual studio code debugger? 由于我们公司的政策不允许我这样工作,是否可以使用Visual Studio代码调试器替代方法或采取其他措施?

Have you logged onto the SCCM site server interactively with the credentials you are using and opened the console at least once? 您是否已使用所使用的凭据交互式登录到SCCM站点服务器并至少一次打开了控制台? I believe this initial first opening is required before the drive is accessible remotely... 我认为必须首先进行首次打开,然后才能远程访问驱动器。

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

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