This topic contains 3 replies, has 3 voices, and was last updated by
August 12, 2016 at 5:12 am #50093ParticipantTopics: 1Replies: 1Points: 0Rank: Member
Hello I have this script "GetInvalidImagePathsV2.ps1" from:
PS C:\powershell> .\GetInvalidImagePathsV2.ps1
Unexpected token '` ' in expression or statement.
At C:\powershell\GetInvalidImagePathsV2.ps1:99 char:50
+ " Service Name : $Name`n" ` < <<< + CategoryInfo : ParserError: (` :String) , ParseException + FullyQualifiedErrorId : UnexpectedToken
And I added the command "Set-ExecutionPolicy restricted" and confirmed "Y"
If I enter this command:"Get-Host | Select-Object Version" it returnd me V2.0
But not run why can't run the script?
August 12, 2016 at 9:53 am #50110ParticipantTopics: 4Replies: 104Points: 82Rank: Member
Looking at the error message thrown, it complains about a problem with a backtick ( ` ) at line 99, character 50.
If the backtick is used to break a statement into several lines, it must be emediately follows by a line break. It is important that it is not followed by whitespace if any kind.
When you copy from a web page like that, you will often find extra whitespace, invalid line breaks etc. So you will have to go through the script, and check the formatting.
August 12, 2016 at 10:12 am #50116ParticipantTopics: 15Replies: 22Points: 1Rank: Member
By default running script is disabled on your machine if you are running any machine lower than Windows Server 2012 R2.
So, to run the script on your machine, you need to set the execution policy to RemoteSigned(recommended).
Write-Host “$Header`n” `
” Service Name : $Name`n” `
” Service Caption : $Caption`n” `
” Registry key : HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservices$NameImagePath`n” `
” Value : $Path`n” `
” Reason : $Info`n” `
Write-Host -ForeGroundColor “$Color” “$Header`n”
” Service Name : $Name`n”
” Service Caption : $Caption`n”
” Registry key : HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservices$NameImagePath`n”
” Value : $Path`n”
” Reason : $Info`n”
It is working for me.
August 12, 2016 at 11:38 am #50125ParticipantTopics: 1Replies: 1Points: 0Rank: Member
"amit aman" worked perfectly your change.
Thank you so much.
The topic ‘Powershell script not run’ is closed to new replies.