Greetings,
I am currently using a script to check the status of a list of host names from a txt file.
However not all devices have the same domain name
“Server.Prod.foo.com” or “Server.Prod.foobar.com”
is there a way i can append the script i currently have to include different DNS suffixes?
Below is my current script which works fine but looking to add the above.
If I understand this correctly, your list of servers only contains the NETBIOS name as in “server”, not “server.domain.com”. One thing you can do is add the additional DNS suffixes to the network adapter configuration. Adapter/TCPIP-4 Properties/Advanced/DNS/Append these DNS Suffixes.
You would need admin. Hit the WindowKey+R (run) and enter “ncpa.cpl”. Right mouse on your active network adapter, select Properties. Double Click on "Internet Protocol Version 4 (TCP/IP). Select Advanced. Select the DNS tab. Select the Radio Button for “Append these DNS suffixes…” then Select add and add your suffixes.
I realized this is technically not PowerShell related, no flames please
Again let me try to clarify, The script it to be run against hundreds of serves to obtain the status. Some of them not always ending with the same domain so i would like to run the list of server names thought the script with out adding the suffix to each and everyone in the list. Since the list changes frequently. The names would be looped thought with one domain name if non existed then use the next dns suffix. I’m no looking to changes the network adapter or any of the configurations on my end. Just need help with the syntax of powershell.
Thanks in advance!
etc…
K2Hunter, first let me advise you not to use $_ as a named variable. If you want to reference the automatic variable $_, use a ForEach-Object loop instead. Next, your plan to ping every possible domain with every host sounds like a bad approach. Especially when running sequentially, this could take forever. Can you not query for the actual hosts FQDN? If you insist one continuing down this path you should probably look into jobs, runspaces, or ForEach-Object -Parallel (powershell core only).
Here is a simple way you could test each host with each domain. However the way the logic is currently written each host will be output to the log once per domain.
I see the logic you have here it seems to me sufficient to do what i was planning.
However I’d like to learn more as to what you mean with this?
Blockquote
first let me advise you not to use $_ as a named variable. If you want to reference the automatic variable $_, use a ForEach-Object loop instead.
Blockquote
Secondly I only have 3 domains to search on with old servers being phased out and new ones being added I can’t keep up with what domain they will be on when created.
I’m jsut starting to begin scripting with powershell so I appreciate your help!
So, the solution I proposed is a configuration on the network adapter for the SYSTEM running the script. Make the change there once and you are done, you don’t need to add any logic/code to the script. Doug is a PowerShell black belt (I am far from that) and he has proposed a script based solution. I would use what he has proposed as long as performance does not become an issue.
Or if you want to test a whole network segment for connectivity you can use use the Test-Network command. It will return only those addresses that have a reverse DNS lookup, or have a successful ping. Any ip address that doesn’t have a reverse DNS lookup and doesn’t respond to ping will NOT show up in the output.
@riedyw … is Test-Network version dependent or require a module to install? It is not found on my PS 5.1 or PS 7.1.2. Can you elaborate please? Thanks.
I appreciate the info, I am not aware what poshfunctions are. I do apologize.
Also do you have a link to the gallery? As i stated before, I’m very noob to powershell. as in like last week.
The PowerShell Gallery is a software repository of modules and scripts that acts as a place for publishing those scripts and modules. These items can be installed through a PowerShell command.
Install-Module -Name PoshFunctions
You most likely will be prompted the PowerShell Gallery is an untrusted repository. If you run the command Get-PSRepository you will see the repositories that are registered on your machine.
To use the commands in the module run the command Import-Module -Name PoshFunctions which will load the module and all its functions into your current PowerShell session. You can see a listing of all the commands in the module by running Get-Command -Module Poshfunctions and there are over 180 different functions in that module.
May I ask if you Googled for “Powershell Gallery”? Or Googling “installing module from Powershell Gallery”? Learning things in the computer field is a journey of discovery. I gave you enough keywords so that you could have searched yourself.