ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Inconsistent output from PS script

    Scheduled Pinned Locked Moved IT Discussion
    13 Posts 5 Posters 506 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dafyreD
      dafyre @gjacobse
      last edited by

      @gjacobse said in Inconsistent output from PS script:

      I mentioned that I was building another convenience script, It needs to only look at a servie running on four remote computers. This service runs to accept CC/Debit cards on a POS station. But sometimes the service borks and has to be restarted.

      I have a simple batch file that does it now, but figured at some point I would move it to PS using a menu type system... and thus I have started doing so.

      Oddly, I am seeing inconsistent output when it's ran. The syntax of the line didn't / doesn't change - so not sure why this happens.

      Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
      

      Run it once and I get nothing back, run it again and I get listed twice, run it a third time and I get what I want to see the first time.

      Additionally, I have a 'title line' that I ass the -Foreground color and it skips the first one or two letters before applying the color. seems odd, and comparing my formatting - it's no different then others I have seen...

      Can you try it with Invoke-Script or Start-Job ?

      gjacobseG 1 Reply Last reply Reply Quote 0
      • gjacobseG
        gjacobse @dafyre
        last edited by

        @dafyre

        Not sure on using those - I will look though.

        EddieJenningsE 1 Reply Last reply Reply Quote 0
        • EddieJenningsE
          EddieJennings @gjacobse
          last edited by

          @gjacobse Try removing the space between , and pc2.

          gjacobseG 1 Reply Last reply Reply Quote 0
          • ObsolesceO
            Obsolesce @gjacobse
            last edited by

            @gjacobse said in Inconsistent output from PS script:

            I mentioned that I was building another convenience script, It needs to only look at a servie running on four remote computers. This service runs to accept CC/Debit cards on a POS station. But sometimes the service borks and has to be restarted.

            I have a simple batch file that does it now, but figured at some point I would move it to PS using a menu type system... and thus I have started doing so.

            Oddly, I am seeing inconsistent output when it's ran. The syntax of the line didn't / doesn't change - so not sure why this happens.

            Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
            

            Run it once and I get nothing back, run it again and I get listed twice, run it a third time and I get what I want to see the first time.

            Additionally, I have a 'title line' that I ass the -Foreground color and it skips the first one or two letters before applying the color. seems odd, and comparing my formatting - it's no different then others I have seen...

            Does that above command work properly by itself in the script, without anything else in the script? Can you share the output of just that part by itself (you can blur any sensitive info).

            1 Reply Last reply Reply Quote 0
            • 1
              1337 @gjacobse
              last edited by 1337

              @gjacobse said in Inconsistent output from PS script:

              Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
              

              Where did you get the -ComputerName syntax from?

              I can't find anything like that from the manual: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.2

              If it actually works like you said, I would assume you need to write it like this (with no spaces):

              Get-Service -ComputerName pc1,pc2 SERVICE | Select name, MachineName, Status
              

              Or encapsulate the list of computers inside double quotes:

              Get-Service -ComputerName "pc1, pc2" SERVICE | Select name, MachineName, Status
              
              1 1 Reply Last reply Reply Quote 0
              • 1
                1337 @1337
                last edited by 1337

                @Pete-S said in Inconsistent output from PS script:

                @gjacobse said in Inconsistent output from PS script:

                Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
                

                Where did you get the -ComputerName syntax from?

                I can't find anything like that from the manual: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.2

                OK, it's been deprecated. It's available in older versions of powershell, up to 5.1.

                https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-5.1

                I read somewhere it doesn't use powershell remoting but dcom instead. And that's why it became obsolete.

                Maybe you haven't got the right dcom privileges to run it remotely.

                gjacobseG 1 Reply Last reply Reply Quote 0
                • gjacobseG
                  gjacobse @EddieJennings
                  last edited by

                  @EddieJennings said in Inconsistent output from PS script:

                  @gjacobse Try removing the space between , and pc2.

                  No - changed and on initial run returned nothing.

                  1 Reply Last reply Reply Quote 0
                  • gjacobseG
                    gjacobse @1337
                    last edited by

                    @Pete-S said in Inconsistent output from PS script:

                    @Pete-S said in Inconsistent output from PS script:

                    @gjacobse said in Inconsistent output from PS script:

                    Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
                    

                    Where did you get the -ComputerName syntax from?

                    I can't find anything like that from the manual: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.2

                    OK, it's been deprecated. It's available in older versions of powershell, up to 5.1.

                    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-5.1

                    I read somewhere it doesn't use powershell remoting but dcom instead. And that's why it became obsolete.

                    Maybe you haven't got the right dcom privileges to run it remotely.

                    Say what now? I'm reading this:

                    https://learn.microsoft.com/en-us/powershell/scripting/samples/managing-services?view=powershell-7.2

                    1 1 Reply Last reply Reply Quote 0
                    • 1
                      1337 @gjacobse
                      last edited by 1337

                      @gjacobse said in Inconsistent output from PS script:

                      @Pete-S said in Inconsistent output from PS script:

                      @Pete-S said in Inconsistent output from PS script:

                      @gjacobse said in Inconsistent output from PS script:

                      Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
                      

                      Where did you get the -ComputerName syntax from?

                      I can't find anything like that from the manual: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.2

                      OK, it's been deprecated. It's available in older versions of powershell, up to 5.1.

                      https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-5.1

                      I read somewhere it doesn't use powershell remoting but dcom instead. And that's why it became obsolete.

                      Maybe you haven't got the right dcom privileges to run it remotely.

                      Say what now? I'm reading this:

                      https://learn.microsoft.com/en-us/powershell/scripting/samples/managing-services?view=powershell-7.2

                      I'd put one script on each remote computer and have it send an email whenever the service stops. Or check whatever it is you really want to know with the service.

                      gjacobseG 1 Reply Last reply Reply Quote 0
                      • gjacobseG
                        gjacobse @1337
                        last edited by

                        @Pete-S said in Inconsistent output from PS script:

                        @gjacobse said in Inconsistent output from PS script:

                        @Pete-S said in Inconsistent output from PS script:

                        @Pete-S said in Inconsistent output from PS script:

                        @gjacobse said in Inconsistent output from PS script:

                        Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
                        

                        Where did you get the -ComputerName syntax from?

                        I can't find anything like that from the manual: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.2

                        OK, it's been deprecated. It's available in older versions of powershell, up to 5.1.

                        https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-5.1

                        I read somewhere it doesn't use powershell remoting but dcom instead. And that's why it became obsolete.

                        Maybe you haven't got the right dcom privileges to run it remotely.

                        Say what now? I'm reading this:

                        https://learn.microsoft.com/en-us/powershell/scripting/samples/managing-services?view=powershell-7.2

                        I'd put one script on each remote computer and have it send an email whenever the service stops. Or check whatever it is you really want to know with the service.

                        Sadly, we already monitor the service. I can be 'running' but fail and need to be stop/started. We've also already done the scheduled task route where it checked it ever 15 min and stop/started it. But there are still times it needs to be manually stop/started. And this is 10x better then what they were doing when I started last year....

                        1 1 Reply Last reply Reply Quote 0
                        • 1
                          1337 @gjacobse
                          last edited by 1337

                          @gjacobse said in Inconsistent output from PS script:

                          @Pete-S said in Inconsistent output from PS script:

                          @gjacobse said in Inconsistent output from PS script:

                          @Pete-S said in Inconsistent output from PS script:

                          @Pete-S said in Inconsistent output from PS script:

                          @gjacobse said in Inconsistent output from PS script:

                          Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
                          

                          Where did you get the -ComputerName syntax from?

                          I can't find anything like that from the manual: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.2

                          OK, it's been deprecated. It's available in older versions of powershell, up to 5.1.

                          https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-5.1

                          I read somewhere it doesn't use powershell remoting but dcom instead. And that's why it became obsolete.

                          Maybe you haven't got the right dcom privileges to run it remotely.

                          Say what now? I'm reading this:

                          https://learn.microsoft.com/en-us/powershell/scripting/samples/managing-services?view=powershell-7.2

                          I'd put one script on each remote computer and have it send an email whenever the service stops. Or check whatever it is you really want to know with the service.

                          Sadly, we already monitor the service. I can be 'running' but fail and need to be stop/started. We've also already done the scheduled task route where it checked it ever 15 min and stop/started it. But there are still times it needs to be manually stop/started. And this is 10x better then what they were doing when I started last year....

                          OK, so the script is part of something you actually use to restart it when you decide to?

                          gjacobseG 1 Reply Last reply Reply Quote 0
                          • gjacobseG
                            gjacobse @1337
                            last edited by

                            @Pete-S said in Inconsistent output from PS script:

                            @gjacobse said in Inconsistent output from PS script:

                            @Pete-S said in Inconsistent output from PS script:

                            @gjacobse said in Inconsistent output from PS script:

                            @Pete-S said in Inconsistent output from PS script:

                            @Pete-S said in Inconsistent output from PS script:

                            @gjacobse said in Inconsistent output from PS script:

                            Get-Service -ComputerName pc1, pc2 SERVICE | Select name, MachineName, Status
                            

                            Where did you get the -ComputerName syntax from?

                            I can't find anything like that from the manual: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-7.2

                            OK, it's been deprecated. It's available in older versions of powershell, up to 5.1.

                            https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-5.1

                            I read somewhere it doesn't use powershell remoting but dcom instead. And that's why it became obsolete.

                            Maybe you haven't got the right dcom privileges to run it remotely.

                            Say what now? I'm reading this:

                            https://learn.microsoft.com/en-us/powershell/scripting/samples/managing-services?view=powershell-7.2

                            I'd put one script on each remote computer and have it send an email whenever the service stops. Or check whatever it is you really want to know with the service.

                            Sadly, we already monitor the service. I can be 'running' but fail and need to be stop/started. We've also already done the scheduled task route where it checked it ever 15 min and stop/started it. But there are still times it needs to be manually stop/started. And this is 10x better then what they were doing when I started last year....

                            OK, so the script is part of something you actually use to restart it when you decide to?

                            Yes - while I would like to solve it with PS,.. my batch script works fine. I just figured with all that I am / have been doing with PS,.. why not convert it to PS and go one.

                            Now - if there is another way to accomplish this - I'm open to learning. It's what I'm applying with PS - learning.

                            1 Reply Last reply Reply Quote 1
                            • 1 / 1
                            • First post
                              Last post