I am trying to write a simple script which reads all AD server objects using get-adcomputer and then using the retreived ipv4address property, ping each of these in turn after, using if/else to seperate the results into resolvable or not .csv files.
The main issue I am experiencing is that the line of code to ping the hostname below will work from the command line:
[pre]
if (test-Connection-ComputerName$Server.ipv4address -Count1-Quiet ) {
[/pre]
However when run within the script I receive the error:
Test-Connection : Cannot validate argument on parameter ‘ComputerName’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Why don’t you “ping” the names? The property IPv4Address is actually not an AD attribute it will be populated by the cmdlet under the hood. But if the computer/IPv4Address is not resolveable it will fail - therefore your query fails as well … try to output the list of computers from Get-ADComputer and show only the name and the IPv4Address … then you might see what I mean
Also you are not filtering on server operating systems and do you really need all of the properties back -Properties * as on a large domain this can put unnecessary strain on your DC’s
You have the talent to confuse me. … fqdn = Full Qualified Domain Name … not Full Qualified Domain IPv4Address.
If you need to ping the ip address you can do this. But to get the ip address from the AD with the cmdlet Get-ADUser is not a reliable way - that’s what you should have in mind.
I think it will be more obvious what I mean when you run this code snippet: