Inconsistent output from PS script
-
@gjacobse Try removing the space between
,
andpc2
. -
@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).
-
@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
-
@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.
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.
-
@EddieJennings said in Inconsistent output from PS script:
@gjacobse Try removing the space between
,
andpc2
.No - changed and on initial run returned nothing.
-
@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.
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
-
@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.
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.
-
@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.
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....
-
@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.
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?
-
@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.
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.