使用不同的凭据运行powershell脚本
我正在尝试运行powershell脚本以搜索特定文件的网络驱动器。在我的测试中,我发现我的脚本工作得非常好,但是我需要搜索的网络驱动器需要我的域管理员登录 我有使用不同的凭据运行powershell脚本,powershell,Powershell,我正在尝试运行powershell脚本以搜索特定文件的网络驱动器。在我的测试中,我发现我的脚本工作得非常好,但是我需要搜索的网络驱动器需要我的域管理员登录 我有 启动进程powershell.exe-凭据“域\管理员用户名”-非Windows-参数列表“启动进程powershell.exe-动词runAs” 作为脚本的第一行,但每当运行脚本时,都会出现以下错误: Start-Process : This command cannot be run due to the error: The di
启动进程powershell.exe-凭据“域\管理员用户名”-非Windows-参数列表“启动进程powershell.exe-动词runAs”
作为脚本的第一行,但每当运行脚本时,都会出现以下错误:
Start-Process : This command cannot be run due to the error: The directory
name is invalid.
At Path\to\script.ps1:1 char:1
+ Start-Process powershell.exe -Credential "domain\adminusername" -NoN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process],
InvalidOperationException
+ FullyQualifiedErrorId :
InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
它说的是什么目录名?如果我将脚本移动到实际的网络驱动器,仍然会出现相同的错误。如何以不同的用户身份运行脚本?您可以使用
net use
命令获得访问权限,或者使用new psdrive
命令。另一个选项是启动进程
cmd提示符,并在其中使用runas
。此外,您可能需要包含powershell.exe的完整路径或将其添加到path变量中<代码>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe我多次使用新PSDrive
映射具有管理员凭据的网络驱动器。或者,您也可以在首次启动PowerShell时,以不同用户的身份在PowerShell上运行。