假设我有一个脚本: Install.ps1
作为管理员,我希望能够为指定的用户运行此脚本: joe.smith
Joe.smith不是管理员。所有这些都应该在本地主机上完成,不需要远程到不同的计算机上。
我尝试过的东西:
new-pssession localhost -credential SSN314\joe.smith错误: new-pssession : localhost连接到远程服务器localhost失败,并显示以下错误消息:访问被拒绝。有关详细信息,请参见about_Remote_Troubleshooting帮助主题。
我也试过了:
$username = "joe.smith"
$password = "pass"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secstr
Invoke-Command -FilePath "C:\dir\Install.ps1" -Credential $cred -ComputerName "."Joe.smith不是管理员,这就是为什么我会收到拒绝访问的错误。
joe.smith是一个域帐户。
当我运行: Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.Powershell命令时,PSSessionConfiguration具有完全控制权
任何帮助都是非常感谢的。
发布于 2021-01-20 02:24:11
在我看来,问题是您正在尝试远程连接到本地PC。您应该能够改用Start-Process。
Start-Process powershell.exe -ArgumentList "-file","C:\dir\Install.ps1" -Credential $credhttps://stackoverflow.com/questions/65796749
复制相似问题