gpt4 book ai didi

powershell - powershell-Invoke-Command:FilePath参数的值必须是Windows PowerShell脚本文件

转载 作者:行者123 更新时间:2023-12-03 01:15:48 25 4
gpt4 key购买 nike

我有一个成功使用过的可重复使用的脚本,成功地调用了远程ps1文件,但是现在我正尝试调用远程批处理文件,并且收到以下错误消息-

Invoke-Command : The value of the FilePath parameter must be a Windows
PowerShell script file. Enter the path to a file with a .ps1 file name
extension and try the command again.

这是脚本-
#Admin Account 
$AdminUser = "domain\svc_account"
$Password = Get-Content D:\scripts\pass\crd-appacct.txt | convertto-securestring
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminUser, $Password
$FileName = "runme.bat"
$ItemLocation = "D:\path\to\bat\"

#Invoke Script Remotely
Invoke-Command -ComputerName Servername -filepath "$ItemLocation$FileName" -Authentication CredSSP -Credential $Credential

最佳答案

您应该使用-ScriptBlock参数而不是-FilePath:

Invoke-Command -ComputerName Servername -ScriptBlock {& "$using:ItemLocation$using:FileName"} -Authentication CredSSP -Credential $Credential

或者,如果您使用的是不带 $using:VariableName语法的PowerShell v2:

Invoke-Command -ComputerName Servername -ScriptBlock {param($ItemLocation,$FileName) & "$ItemLocation$FileName"} -ArgumentList $ItemLocation,$FileName -Authentication CredSSP -Credential $Credential

关于powershell - powershell-Invoke-Command:FilePath参数的值必须是Windows PowerShell脚本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30338301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com