Newbie here to powershell! I have a script which looks through servers and services listed in an array and stops and starts depending on input parameter’s. What i’d like to do is list out the service name, status and servername (variable $Servername) into an output folder. Below is the work line I have so far which lists the service name, status and startup type…now how do I add the server name? I’m guessing it real simple but my skills are not up to scratch yet nore can I find anything on the net.
I would suggest using Invoke-Command for running commands against multiple computers. You could then throw the Computernames in a text file and make the process smoother as well. You will need to make sure PSRemoting is enabled in your environment. Invoke-Command by default will provide you with the PSComputername Property providing the server name you would like to see.
Your first stop if you have some questions should always be the help for the cmdlets you’re about to use. You should always read the help completely including the examples - even if you don’t understand everything yet.
All the examples you’ve got here from the answers do export the results to a TXT or CSV file. Did you try the code snippets?
yes it work but it enters every service into a text file - I am only interested in returning one service titled “MSSQLSERVER”. From what I read online I need to pass the service parameter into Invoke-Command using -ArgumentList but Im struggling to get this to work at the moment
Don’t you think a CSV file would be better? You can even easily read it again with PowerShell and use the informations contained within.
AAnd BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.