问题描述
我正在使用 PowerShell Core 来执行此操作。 命令:
pwsh -NoLogo -NonInteractive -InputFormat text -OutputFormat text -Command “& { $Password = ConvertTo-SecureString 'pswd' -AsPlainText -Force;$skipCN = New-PSSessionOption -SkipCNCheck -SkipCACheck;$Credential = New-Object System.Management.Automation.PsCredential 'Administrator’,$Password;Invoke-Command -ComputerName hostname -Authentication Basic -Credential $remote_credential -ScriptBlock {{ Get-WmiObject -Class Win32_PerfRawData_PerfOS_Memory | Format-List * }} -useSSL -SessionOption $skipCN }”
输出为:
但是,如果我使用命令运行脚本
pwsh -NoLogo -NonInteractive -InputFormat text -OutputFormat text -Command absolute_file_path
它按预期工作。
我应该进行哪些更改以使用 -Command 选项使其作为字符串运行?
编辑:删除 {{
之后的双 -scriptblock
并将其替换为单个 {
没有帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)