Env:
Windows Server 2016 Standard Evaluation
version 1607(OSbuild 14393.2248)
my_powershell.ps1在下面。
echo $args
在本地我可以执行以上脚本。
PS C:\Users\Administrator> .\echo_args.ps1 "aaaa"
aaaa
我可以通过winrm执行命令或exe文件。 例如)
PS C:\Users\Administrator> winrs -r:localhost -u:Administrator -p:MyPassword .\my.exe
但是,当我通过WinRM(如下)执行my_powershell.ps1时,my_powershell.ps1一直在等待,而未做任何事情。
PS C:\Users\Administrator> winrs -r:localhost -u:Administrator -p:MyPassword .\echo_args.ps1
我的WinRM配置在下面。
PS C:\Users\Administrator> winrm get winrm/config
Config
MaxEnvelopeSizekb = 500
MaxTimeoutms = 60000
MaxBatchItems = 32000
MaxProviderRequests = 4294967295
Client
NetworkDelayms = 5000
URLPrefix = wsman
AllowUnencrypted = false
Auth
Basic = true
Digest = true
Kerberos = true
Negotiate = true
Certificate = true
CredSSP = false
DefaultPorts
HTTP = 5985
HTTPS = 5986
TrustedHosts = *
Service
RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
MaxConcurrentOperations = 4294967295
MaxConcurrentOperationsPerUser = 1500
EnumerationTimeoutms = 240000
MaxConnections = 300
MaxPacketRetrievalTimeSeconds = 120
AllowUnencrypted = true
Auth
Basic = true
Kerberos = true
Negotiate = true
Certificate = false
CredSSP = false
CbtHardeningLevel = Relaxed
DefaultPorts
HTTP = 5985
HTTPS = 5986
IPv4Filter = *
IPv6Filter = *
EnableCompatibilityHttpListener = false
EnableCompatibilityHttpsListener = false
CertificateThumbprint
AllowRemoteAccess = true
Winrs
AllowRemoteShellAccess = true
IdleTimeout = 7200000
MaxConcurrentUsers = 2147483647
MaxShellRunTime = 2147483647
MaxProcessesPerShell = 2147483647
MaxMemoryPerShellMB = 2048
MaxShellsPerUser = 2147483647
我应该在哪里改变?
答案 0 :(得分:1)
我对winrm的命令是错误的。通过WinRm执行PowerShell时,我应指定使用PowerShell.exe。
下面是正确的命令。
PS C:\Users\Administrator> winrs -r:localhost -u:Administrator -p:MyPassword powershell .\echo_args.ps1 "aaaa"