powershell - TFS-Powershell 脚本
问题描述
我有这个脚本,它在本地服务器上运行良好,没有问题,但是当我在 Team Foundation Server(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 'Stopped'})
提前致谢。
解决方案
是的,从 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"
推荐阅读
- julia - Julia automatic differentiation - is it completely busted?
- r - 无法调用 input$"OptionType1"
- python - 使用 Gaussian Process scikit 达到的最大内存使用量
- winapi - 我想枚举窗口类名称
- neo4j - 密码外壳没有响应
- php - 带return语句的php函数
- php - 重定向 .htaccess 中的 url 添加延迟和消息
- javascript - 迷路了,我有一个丢失的捕获?// Discord.JS
- github - 同步远程和本地故障
- python - 如何提高数据框中的搜索索引