[英]How To Execute PowerShell via WinRM
Env: ENV:
Windows Server 2016 Standard Evaluation
version 1607(OSbuild 14393.2248)
my_powershell.ps1 is below. my_powershell.ps1在下面。
echo $args
In local I can execute above script. 在本地我可以执行上面的脚本。
PS C:\Users\Administrator> .\echo_args.ps1 "aaaa"
aaaa
And I can execute command or exe files via winrm. 而且我可以通过winrm执行命令或exe文件。 eg)
例如)
PS C:\Users\Administrator> winrs -r:localhost -u:Administrator -p:MyPassword .\my.exe
But when I execute my_powershell.ps1 via WinRM(below), my_powershell.ps1 has been waiting, without doing something. 但是,当我通过WinRM(下面)执行my_powershell.ps1时,my_powershell.ps1一直在等待,但未执行任何操作。
PS C:\Users\Administrator> winrs -r:localhost -u:Administrator -p:MyPassword .\echo_args.ps1
My WinRM config is below. 我的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
Where should I chanage? 我应该在哪里改变?
My command of winrm was wrong. 我对winrm的命令是错误的。 When executing PowerShell via WinRm, I should specify to use PowerShell.exe.
通过WinRm执行PowerShell时,我应指定使用PowerShell.exe。
So right command is below. 所以下面是正确的命令。
PS C:\Users\Administrator> winrs -r:localhost -u:Administrator -p:MyPassword powershell .\echo_args.ps1 "aaaa"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.