Get-FolderSize

This is a little function I wrote one day when I needed to get the total size of a set of folders (including sub folders). It performs a recursive search and computes the total count and also shows the size in a more human-readable format. It also have a “hidden” property called SizeInBytes that can be helpful if you want to do size calculations and need the size in a common format.
(more…)

New-DataTable

I have written previously about how to convert an object to a DataTable and how to create one based on an existing MSSQL table, but now I will share a function to create a new empty DataTable. Sure, this isn’t very complicated to do manually, but using this function you can define the table structure using an ordered dictionary, which makes it much easier to update later if needed.
(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…)