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."
}
}
and this error came.
if(Get-Service $Service | Where {$_.status â?"eq 'Stopped'})
Unexpected token 'â?"eq 'Stopped'})
Thanks in advance.
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.
This is not meant as a direct answer to this question because TheIncorrigible1 already gave that. It may however help others.
and added it to my ISE menu with: