Optimizing WMI queries using forward only enumerators

I was writing a script that runs queries to about 2000 servers to check the patch compliance of each server, using WMI to query the SCCM agent on each machine. The servers are located all around the world, with varying degree of latency. Even though I utilize runspaces to speed things up, I still noticed that some of the threads timed out on me. Investigating I found out that it was the WMI query itself that took a long time executing, particularly on high-latency sites.
(more…)

Extending Test-Connection

Using the Test-Connection in an enterprise environment, I often miss the -a parameter of the old ping command, that tells ping to try to resolve IP address to HostName.

So I sat down and created a proxy function for Test-Connection, adding a Resolve parameter. It’s quite simple actually, it’s checks the ComputerName parameter, and if the data is a valid IP address tries to resolve using the Net.Dns class. It then takes the resolved name and injects it back into the ComputerName parameter before calling the original Test-Connection command.
(more…)

New-DataTableFromSqlTable

Working with SqlBulkCopy can sometimes be a struggle. Sure, if you happen to get the data from a table that is identical to the one you want to push to, you are in luck. If not, you need to be sure that the DataTable object is exactly like the target table in the SQL database you want to import data to. One type wrong, or one column in the wrong place, and you are out of luck… it won’t work.
(more…)