Are you asking us to teach you how to use Powershell? Well this forum is not really about writing scripts for you. It’s more about answering specific questions about Powershell scripting. Do you have a specific question about a particular issue you have with a Powershell script you wrote?
If you already have some code to show you can post it here and we’ll be pleased to try to help you out.
based on your statement “Usually I make scripts with an array containing server names”, it sounds like you already have the answer to number 2 and 3 on your list. How you go about number 1 depends on your environment. Think about how you create your static list of server names now. Do you just know them off the top of your head? Do you pull them from a master list somewhere? That question is really about how you organize data in your environment, and less about how to do that with powershell. Really the powershell is the easy part once you figure out how to organize your server list in your environment.
I don’t want to update all the scripts all the time to accommodate servers that come and go.
Also, for at least one script I use, if the server is not running, an error is thrown…but that server could be re-activated later…continually updating scripts is not optimal.
I want to dynamically obtain and work with the running servers.
That is all. Doing so should not be dependent on anything but:
is this server running?? if yes, add it to the array. when done looking at servers, process the array.
$Servers = (Get-ADComputer -Filter {OperatingSystem -like "*Server*"}).Name
foreach($Comp in $Servers){
#If the server replies Ping request
If(Test-Connection -ComputerName $Comp -Count 1 -Quiet){
#Do-Something or create another servers list
}
}
Thank you, that helps a lot, gets me started.
I had trouble figuring out a good search term to get good/usable results.
Do you think it’s better or faster to test for RPC response rather than pinging??
This is a completely internal script, perhaps RPC response testing would be quicker.
You could also have them in a CSV file and just edit the file whenever one of these servers come and go rather than modifying the script itself. Have you tried that?
I don’t want to have to remember to edit files.
I’ve already found all I need to gather all the servers, test them, next is to learn how to build an array containing the desired servers, which should be reasonably easy.
Thank you, Tom