簡體   English   中英

從批處理或.cmd 文件中運行 PowerShell 命令的問題

[英]Issue running PowerShell Commands from batch or .cmd file

I am trying to update the DNS IP on all DR Servers and I tried changing the DNS IP using the below script and it is not working through batch file or.cmd file

請幫忙

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.

嘗試這個:

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}"

您遇到標點錯誤,例如未將腳本括在引號中。 我還刪除了不必要的啟動過程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM