Skip to main content

Posts

Showing posts with the label Hash Tables

Export Hash Tables to CSV - Powershell V2

I wrote about hash tables a while back in regards to counting OS types. The one thing I didn't lookinto back then was how to export the information to CSV. Easy, I hear you cry - just use export-csv!  Not quite as easy as you would imagine. The main thing to tackle is the fact that Hash Tables are not objects as we would usually consider them.  If you run get-member on a hash table you get the following properties : Count IsFixedSize IsReadOnly IsSynchronized Keys SyncRoot Values What is required is to create an object based on the hash table prior to exporting. Lets create a similar hash table to the one found in my previous post : $complist = get-ADcomputer -filter {enabled -eq $true} -properties operatingsystem $OSlist = @{} $complist | % {try {$OSlist.$($_.operatingsystem) ++}catch{$OSlist.None ++}} Export this to CSV and you get : PS U:\> $OSlist | Export-Csv "OScount1.csv" -NoTypeInformation PS U:\> type .\OScount1.csv "IsReadOnly",...

Hash Tables - DC operating systems

I have been meaning to get my head around a lot of different aspects of powershell, one of which is hash tables.  As we are currently going through a DC upgrade, I wanted to know how many DC's we had of each different operating system.  I wondered if hash tables would help me. First, I got all DC's in my domain :  $DClist = get-ADDomainController -server domain.com -filter {enabled -eq $true} You may notice the get-ad portion of the command....this means that this command runs only on powershell 2 when connected to an Windows 2008 R2 DC or a 2003 / 2008 DC with ADMGS installed.  So, $DCList is now all the DC's from domain.com (-server domain.com) that are set to enabled (-filter {enabled -eq $true}).  NOTE: The only DC's that are not enabled are pre-staged RODC accounts ... by that i mean accounts that have been created but the server has not come online yet.  These servers do not have any OS information in them anyway. It is more helpful...