A recent question of the PowerShell forum asked how the output of two scripts could be combined. The scripts in question were using Get-ChildItem and Get-Acl to pull back two sets of information related to the file.
PowerShell produces objects. .NET objects with a PowerShell wrapper. The questioner was looking for something like the UNION operator in TSQL. Unfortunately, you can’t combine objects like that. Trying to match up the properties and methods would be a nightmare.
So we need to combine the way we produce the information to create a single object with all of the data we require
Start by using Get-ChildItem to read the directory lists. Then foreach object we create a new object and use Add-Member to create some properties on it. In this case we pick off the full name of the object and the last times it was accessed & written to.
We also need to get some ACL information. We can use Get-Acl within our loop – we only read the file directories once this way. And then we add a few more properties. Add the object to our array and loop back for the next file.
At the end we can dump the information to a csv file for future use.