从批处理或.cmd文件发出运行PowerShell命令的问题

时间:2020-07-08 08:25:45

标签: powershell

我正在尝试更新所有灾难恢复服务器上的DNS IP,并且尝试使用以下脚本更改DNS IP,但它无法通过批处理文件或.cmd文件工作

请帮助

PowerShell -noprofile -executionpolicy bypass -command Start-Process -FilePath powershell.exe -ArgumentList '-noprofile', '-command', &{(Get-DnsClientServerAddress | where {$_.ServerAddresses -contains 192.168.5.15} | Set-DnsClientServerAddress -ServerAddresses 192.168.15.100,192.168.15.101) -Verbose -Confirm:$false; ipconfig /flushdns; ipconfig /flushdns; Clear-DnsClientCache; Register-DnsClient -verb RunAs}

我收到如下错误消息


Missing expression after ',' in pipeline element.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpression

'{' is not recognized as an internal or external command,
operable program or batch file.

1 个答案:

答案 0 :(得分:0)

尝试一下:

PowerShell -noprofile -executionpolicy bypass -command "& {(Get-DnsClientServerAddress | where {$_.ServerAddresses -contains "192.168.5.15"} | Set-DnsClientServerAddress -ServerAddresses "192.168.15.100","192.168.15.101") ; ipconfig /flushdns; ipconfig /flushdns; Clear-DnsClientCache; Register-DnsClient -verb RunAs}"

您遇到标点错误,例如未将脚本括在引号中。我也删除了不必要的启动过程。