我有一个运行良好的脚本,在本地服务器上没有问题,但是当我在(Update2017)中执行一个任务并从那里运行它时,它会抛出一个错误,错误将在脚本之后进行引用。
param(
[string]$ServiceNames
)
if([string]::IsNullOrWhiteSpace($ServiceNames))
{
throw "Missing argument [-ServiceNames $ServiceNames]"
}
$Services=$ServiceNames.Split(",")
foreach($Service in $Services)
{
if(Get-Service $Service | Where {$_.status –eq 'Stopped'})
{
Get-Service $Service | Where {$_.status –eq 'Stopped'} | Start-Service
Write-Host "$Service has been started."
}
else
{
Write-Host "$Service is already running."
}
}这个错误出现了。
if(Get-Service $Service | Where {$_.status â?"eq 'Stopped'})意料之外的令牌‘?“eq’停止‘})
提前谢谢。
发布于 2018-07-11 18:12:33
是的,“从Word或Outlook复制/粘贴”总是插入编辑器中不需要的字符。为此,我将下面的函数放在我的Powershell配置文件中。
这并不意味着直接回答这个问题,因为TheIncorrigible1已经给出了这个答案。然而,它可能会对其他人有所帮助。
function Editor-ReplaceSmartQuotes {
## this function replaces "smart-qoutes" and long dashes you get
## when pasting from Word into normal straight characters (" ' -)
$text = Editor-GetSelectedText
$psISE.CurrentFile.Editor.InsertText(($text -creplace '[\u201C\u201D\u201E\u201F\u2033\u2036]', '"' `
-creplace "[\u2018\u2019\u201A\u201B\u2032\u2035]", "'" `
-creplace "[\u2013\u2014\u2015]", "-"))
}并将其添加到我的ISE菜单中:
Editor-AddMenu "Replace Smart_Quotes in Selection" {Editor-ReplaceSmartQuotes} "Alt+Q"https://stackoverflow.com/questions/51288442
复制相似问题