More Powershell

Here are a few quick Powershell scripts I created to take care of some daily tasks that came up.

Output list of installed software into a text files, one text file per IP and one master file with all hosts:

$ip = get-content C:\

foreach ($i in $ip)
wmic  /node: $i computersystem get name >> C:\installList.txt
wmic  /node: $i os get name`,version >> C:\installList.txt
wmic  /node: $i product get name`,version >> C:\installList.txt
wmic  /node: $i computersystem get name >> C:\$i.txt
wmic  /node: $i os get name`,version >> C:\$i.txt
wmic  /node: $i product get name`,version >> C:\$i.txt


Convert a dynamic distribution group to a regular distribution group in Exchange 2010:

$employees = Get-DynamicDistributionGroup “(dynamic group)” #This is the dynamic group to be read from
$groupName = Get-distributiongroup “(regular group name)” -erroraction ‘silentlycontinue’ #This is the group to be modified. Continues if there are any errors encountered.

#if the group exists, remove it and re-create it.  If it doesn’t exist, create it.
if ( $groupname )
remove-distributiongroup “(regular group)” -Confirm:$false #disables confirmation of group removal.
new-distributiongroup “(regular group)”
set-distributiongroup “Employees” -customattribute11 “(whatever attribute you use to populate the group)”
new-distributiongroup “(regular group)”
set-distributiongroup “(regular group)” -customattribute11 “(whatever attribute you use to populate the group)”
Get-Recipient -RecipientPreviewFilter $employees.RecipientFilter | export-csv C:\filename.csv #prints pertinent information about members of the group and exports it to csv

import-csv C:\filename.csv | foreach { Add-DistributionGroupMember “(regular group)” -member $ }
Remove-item C:\filename.csv -Confirm:$false #remove csv file if necessary


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s