Powershell script not run

Welcome Forums General PowerShell Q&A Powershell script not run

Viewing 2 reply threads
  • Author
    Posts
    • #50093
      Participant
      Topics: 1
      Replies: 1
      Points: 0
      Rank: Member

      Set-ExecutionPolicy RemoteSigned

      Hello I have this script "GetInvalidImagePathsV2.ps1" from:

      https://blogs.technet.microsoft.com/askcore/2010/06/18/ps-script-for-blog-enumeration-of-the-files-failed/

        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?

      Thank you

    • #50110
      Participant
      Topics: 4
      Replies: 104
      Points: 82
      Rank: 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.

    • #50116
      Participant
      Topics: 15
      Replies: 22
      Points: 1
      Rank: Member

      Hey Alejandro,

      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).

      set-executionpolicy -RemoteSigned.

      After that,

      replace:

      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” `
      “`n” `
      -ForeGroundColor “$Color”

      with:

      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”
      “`n”

      It is working for me.

      • #50125
        Participant
        Topics: 1
        Replies: 1
        Points: 0
        Rank: Member

        "amit aman" worked perfectly your change.

        Thank you so much.

Viewing 2 reply threads
  • The topic ‘Powershell script not run’ is closed to new replies.