如何创建当前用户的凭据?

时间:2017-11-30 10:42:36

标签: powershell credentials invoke remote-server sccm

如何在PowerShell中创建当前用户的凭据(没有提示)?

我使用服务帐户凭据调用远程脚本(在SCCM服务器上), 我想将它发送给我当前的凭证,因为这个远程脚本需要我的本地凭证才能在我的本地硬盘上写入(在母带制作期间)。 两台计算机都在同一个域中,但我的服务帐户不允许在我的本地硬盘上写入。

编辑:

1)我无法使用$ Password方式,因为我不知道谁被记录(和密码)

2)我已经有了PSSession。我的PSSession是一个服务帐户但我的远程脚本需要我的本地凭证我需要2个凭据

Invoke-Command -Session $RemoteServerSession -ScriptBlock $ScriptBlock -ArgumentList $LocalWorkstationSession

因为在我的远程脚本中我确实想要

$DriveOnWorkstation = New-PSDrive -Credential $LocalWorkstationSession -Name MyDrive -Root $UNCWorkstationFolderPath -PSProvider FileSystem

1 个答案:

答案 0 :(得分:0)

显示当前脚本。

另外,你可以使用

PS> $s = New-PSSession -ComputerName localhost
PS> Invoke-Command -Session $s -Script { param($processId) Get-Process -Id $processId } -Args $pid

$Password = ConvertTo-SecureString "password" -AsPlainText -Force

$Credential = New-Object System.Management.Automation.PSCredential (“Login”, $Password)