What is correct way to call this cscript??

Welcome Forums General PowerShell Q&A What is correct way to call this cscript??

Viewing 2 reply threads
  • Author
    Posts
    • #184757
      Participant
      Topics: 25
      Replies: 70
      Points: 45
      Rank: Member

      I need to do this for five (5) XenApp servers, for now only one for testing.
      PowerShell won't let me run the below line in bold with the cscript in it.

      I get this error:
      Microsoft (R) Windows Script Host Version 5.812
      Copyright (C) Microsoft Corporation. All rights reserved.
      Input Error: There is no file extension in "\\x1\C$\Program Files\Microsoft Office\Office16\ospp.vbs \dstatus".
      Press Enter to continue...:

      There IS a file extension and it's changing the forward slash to a back slash.
      What's the right way to call this cscript line in PowerShell??

      Code below:

      cls
      #$servers = @('x1,'x2','x3','x4','x5')
      $servers = @('x1')
      foreach ($server in $servers) {
      cscript "\\$server\C`$\Program Files\Microsoft Office\Office16\ospp.vbs /dstatus"
      pause
      # cscript ospp.vbs /inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
      # pause
      # cscript ospp.vbs /act
      # pause
      }

    • #184760
      Participant
      Topics: 10
      Replies: 117
      Points: 456
      Helping Hand
      Rank: Contributor

      Use the call operator & like so:

      & cscript "\\$server\C$\Program Files\Microsoft Office\Office16\ospp.vbs" "/dstatus"

      The call operator does not parse strings so you need to manually 'tokenize' the command into pieces with spaces between (no commas). Otherwise the entire line is considered one command rather than a command with additional options/arguments. That's why you get the file extension error because "... /dstatus" is not an extension.

    • #184766
      Participant
      Topics: 25
      Replies: 70
      Points: 45
      Rank: Member

      Thank you 2,348,532 tons!! 🙂 🙂

      I did not know of the & call operator nor its requirements.

      The script now works properly, plus I added $server at the end to make it work on the remote server.

      Now I have:

      foreach ($server in $servers) {
      & cscript "\\$server\C`$\Program Files\Microsoft Office\Office16\ospp.vbs" "/dstatus" $server
      pause
      # cscript ospp.vbs /inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
      # pause
      # cscript ospp.vbs /act
      # pause
      }

Viewing 2 reply threads
  • You must be logged in to reply to this topic.