Script not reading input on Powershell 7.0 Ubuntu

Welcome Forums General PowerShell Q&A Script not reading input on Powershell 7.0 Ubuntu

Viewing 3 reply threads
  • Author
    Posts
    • #225222
      Participant
      Topics: 37
      Replies: 114
      Points: 604
      Rank: Major Contributor

      PowerShell 7.0
      Ubuntu 18.04
      Windows 2019
      OpenSSh

      writing a simple script on Ubuntu to get service info on a windows server

      [/crayon]

      when I run the script

      [email protected]:/opt/microsoft/powershell/7-lts/Modules$ ./test.psm1 serv027-n1 nscp
      Get-Service: Cannot validate argument on parameter ‘Name’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

      Any ideas?

      Thank you

      Tom

    • #225225
      Participant
      Topics: 8
      Replies: 562
      Points: 2,149
      Helping Hand
      Rank: Community Hero
    • #225369
      Participant
      Topics: 37
      Replies: 114
      Points: 604
      Rank: Major Contributor

      Doug,

      Yes I was searching on the web first I found -ArgumentList but could not get that to work

      You one link had something I did not find before and that worked.

      $server = $args[0]
      $service = $args[1]

      write-host $server
      write-host $service

      invoke-command -computername $server -ScriptBlock { Get-Service $Using:service }

      This works now $Using:

      Thanks now off to the Ubuntu server to test this.

    • #225411
      Participant
      Topics: 8
      Replies: 562
      Points: 2,149
      Helping Hand
      Rank: Community Hero

      Yes using is one way. The point of the exercise is to understand your local variables will not be present in the remote session unless you provide it in one way or another. Of course, you got using working. Just understand with it, any local variable just turns into $using:variable in the remote session.

      For the args to work, you would need to pass them in with the arguments parameter and reference them with the index.

      You can also handle the parameter naming yourself and again pass it through with argumentlist

Viewing 3 reply threads
  • The topic ‘Script not reading input on Powershell 7.0 Ubuntu’ is closed to new replies.