首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TFS-Powershell脚本

TFS-Powershell脚本
EN

Stack Overflow用户
提问于 2018-07-11 14:44:40
回答 1查看 108关注 0票数 0

我有一个运行良好的脚本,在本地服务器上没有问题,但是当我在(Update2017)中执行一个任务并从那里运行它时,它会抛出一个错误,错误将在脚本之后进行引用。

代码语言:javascript
运行
复制
 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."
}
}

这个错误出现了。

代码语言:javascript
运行
复制
if(Get-Service $Service | Where {$_.status â?"eq 'Stopped'})

意料之外的令牌‘?“eq’停止‘})

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-07-11 18:12:33

是的,“从Word或Outlook复制/粘贴”总是插入编辑器中不需要的字符。为此,我将下面的函数放在我的Powershell配置文件中。

这并不意味着直接回答这个问题,因为TheIncorrigible1已经给出了这个答案。然而,它可能会对其他人有所帮助。

代码语言:javascript
运行
复制
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菜单中:

代码语言:javascript
运行
复制
Editor-AddMenu "Replace Smart_Quotes in Selection" {Editor-ReplaceSmartQuotes} "Alt+Q"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51288442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档