TFS-Powershell脚本 [英] TFS-Powershell Scripting
问题描述
我有此脚本,该脚本可以在本地服务器上正常运行,并且没有问题,但是当我在Team Foundation Server(update2017)中执行任务并从那里运行它时会引发错误,该错误在脚本后面供参考。 / p>
I have this script which runs fine with no issue on the server locally but when I made a task in Team Foundation Server(update2017) and run it from there it throws an error, the error is after the script for reference.
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'})
Unexpected token 'â?"eq 'Stopped'})
预先感谢。
推荐答案
是的,从Word或Outlook复制/粘贴总是在编辑器中插入不需要的字符。为此,我在Powershell配置文件中放置了以下功能。
Yes, copy/Paste from Word or Outlook always inserts characters you don't want in the editor. For that i have put below function in my Powershell profile file.
这并不意味着直接回答此问题,因为 TheIncorrigible1 已经给出了。
它可能会帮助其他人。
This is not meant as a direct answer to this question because TheIncorrigible1 already gave that. It may however help others.
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菜单中:
and added it to my ISE menu with:
Editor-AddMenu "Replace Smart_Quotes in Selection" {Editor-ReplaceSmartQuotes} "Alt+Q"
这篇关于TFS-Powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!