<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4308036351571310943</id><updated>2011-04-21T21:29:04.235-05:00</updated><category term='Administrators Group'/><category term='Local Groups'/><title type='text'>Scripting Journal</title><subtitle type='html'>Powershell Scripting Utilities and Snippets that can be used for Windows Server Systems Administration.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://scriptingjournal.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://scriptingjournal.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Patrick</name><uri>http://www.blogger.com/profile/00138059907679045968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_4l4BAxpJHoY/SK3UIG65rGI/AAAAAAAAABs/iShSDdBcBOk/S220/DSC01338.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4308036351571310943.post-186430879587713895</id><published>2008-08-12T22:16:00.030-05:00</published><updated>2008-08-21T15:56:38.505-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Local Groups'/><category scheme='http://www.blogger.com/atom/ns#' term='Administrators Group'/><title type='text'>Get or Add Local Group Members to a Remote Computer</title><content type='html'>Here are a couple of interesting Powershell scripts that can be used to automate the addition of network accounts from one or more AD domains into the local Administrators group on a networked server or computer. Script 1 will be used to add members of any trusted domain to the local Administrators group on a list of computers. In this example, I am going to add domain groups to the local Administrators group. Script 2 will be used to check group membership of the local Administrators group. The output of this script is exported to a spreadsheet to make review of the results easier.&lt;br /&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;Here is the scenario. Your manager emails you and says, 'Hey Patrick old chum, please add these domain accounts from these domains to the local administrative groups on these servers. To make sure that I keep my job I am going to use ficticious names of domains and server.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;Step 1: &lt;/strong&gt;Create a text file called "computers.txt" in the same folder as the scripts. Each line of the text file will have the name or IP address of a networked computer or server on which we want to modify the local Administrators group. Now keep in mind, this process can be set to modify any local group on the list of computers, but I've chose the Administrators group for the sake of this discussion.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_4l4BAxpJHoY/SKc6J6nS9cI/AAAAAAAAABc/gaS2IPWM7T8/s1600-h/dir.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5235217033868801474" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_4l4BAxpJHoY/SKc6J6nS9cI/AAAAAAAAABc/gaS2IPWM7T8/s400/dir.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;&lt;strong&gt;Step 2: Adding the desired accounts to the Administrators groups on remote computers.&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is the script that will be used to add the members to the local groups.&lt;br /&gt;&lt;em&gt;&lt;span style="color:#000066;"&gt;add_to_admingroups.ps1 to add&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;****************************************************************&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;#add_to_admingroup.ps1&lt;br /&gt;#patrick parkison&lt;br /&gt;#email: patrickparkison@bellsouth.net&lt;br /&gt;#This script uses powershell to add domain accounts (user or groups) to the local administrators&lt;br /&gt;#group on remote computers.&lt;br /&gt;#&lt;br /&gt;#Reference for working with local groups on remote servers.&lt;br /&gt;#http://powershellcommunity.org/Forums/tabid/54/view/topic/postid/1528/Default.aspx&lt;br /&gt;&lt;br /&gt;#Get the list of computers to manange.&lt;br /&gt;#Iterate through the list of computers.&lt;br /&gt;foreach($i in (gc .\computers.txt)){&lt;br /&gt;&lt;br /&gt;#Write to screen for feedback.&lt;br /&gt;Write-Host "Processing "$i&lt;br /&gt;&lt;br /&gt;#Add first user/group to remote Administrators group.&lt;br /&gt;$objUser = [ADSI](“WinNT://DomainA/GroupA")&lt;br /&gt;$objGroup = [ADSI]("WinNT://$i/Administrators")&lt;br /&gt;$objGroup.PSBase.Invoke("Add",$objUser.PSBase.Path)&lt;br /&gt;&lt;br /&gt;#Add second user/group to remote Administrators group.&lt;br /&gt;$objUser = [ADSI](“WinNT://DomainB/GroupB")&lt;br /&gt;$objGroup = [ADSI]("WinNT://$i/Administrators")&lt;br /&gt;$objGroup.PSBase.Invoke("Add",$objUser.PSBase.Path)&lt;br /&gt;&lt;br /&gt;#Add third user/group to remote Administrators group.&lt;br /&gt;$objUser = [ADSI](“WinNT://DomainC/GroupC")&lt;br /&gt;$objGroup = [ADSI]("WinNT://$i/Administrators")&lt;br /&gt;$objGroup.PSBase.Invoke("Add",$objUser.PSBase.Path)&lt;br /&gt;&lt;br /&gt;#Add fourth user/group to remote Administrators group.&lt;br /&gt;$objUser = [ADSI](“WinNT://DomainD/GroupC")&lt;br /&gt;$objGroup = [ADSI]("WinNT://$i/Administrators")&lt;br /&gt;$objGroup.PSBase.Invoke("Add",$objUser.PSBase.Path)&lt;br /&gt;&lt;br /&gt;#Add more accounts as required.&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is pretty is a pretty simple script. There are only two key points to look at.&lt;br /&gt;The iteration of the remote computers from the computers.txt file occurs here:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000066;"&gt;foreach($i in (gc .\computers.txt)){&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000066;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;$i becomes that value of each computer name in the text file.&lt;br /&gt;The second key point is actuall connection and manipulation of the local groups. That is done here:&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000066;"&gt;#Add first user/group to remote Administrators group. $objUser = [ADSI](“WinNT://DomainA/GroupA") $objGroup = [ADSI]("WinNT://$i/Administrators") $objGroup.PSBase.Invoke("Add",$objUser.PSBase.Path)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Notice that $i will contain the name of each remote computer. Also, Administrators could be replaced by any valid group name.&lt;br /&gt;&lt;br /&gt;Here is how the output of the script looks when it runs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;$ Add_to_admingroup.ps1&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;Processing s30004w014011&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;Processing 10.87.52.198&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;$&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You would get two possible errors with this script.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first would be if the group or user account was already a member of the local group that you are updating. That error looks like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Exception calling "Invoke" with "2" argument(s): "Exception has been thrown by the target of an invocation."At I:\Utilities\PowerShellScripts\Local-Groups\add_to_admingroup.ps1:53 char:25+ $objGroup.PSBase.Invoke( &lt;&lt;&lt;&lt; "Add",$objUser.PSBase.Path)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The second error would be if the remote computer were not found on the network.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That takes care of the first script. Now here is a good method to check the membership of a specific group on a list of remote computers. As indicated above, the output is displayed in a spreadsheet.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The second script is called list_admin_group_members.ps1. Here is the text of the script.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;list_admin_group_members.ps1&lt;br /&gt;****************************************************************&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;#Assign account names to variables.&lt;br /&gt;$group1 = "GroupName1"&lt;br /&gt;$group2 = "GroupName2"&lt;br /&gt;$group3 = "GroupName3"&lt;br /&gt;$group4 = "GroupName4"&lt;br /&gt;&lt;br /&gt;#Open a spreadsheet&lt;br /&gt;#Region&lt;br /&gt;$RowCount = 1&lt;br /&gt;#http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept06/hey0908.mspx&lt;br /&gt;$a = New-Object -comobject Excel.Application&lt;br /&gt;$b = $a.Workbooks.Add()&lt;br /&gt;$c = $b.Worksheets.Item(1)&lt;br /&gt;$c.Cells.Item($RowCount,1) = "Server"&lt;br /&gt;$c.Cells.Item($RowCount,2) = $group1&lt;br /&gt;$c.Cells.Item($RowCount,3) = $group2&lt;br /&gt;$c.Cells.Item($RowCount,4) = $group3&lt;br /&gt;$c.Cells.Item($RowCount,5) = $group4&lt;br /&gt;$a.Range("A1:E1").Select()&lt;br /&gt;$a.Selection.Font.Bold = $True&lt;br /&gt;$a.Columns.AutoFit()&lt;br /&gt;$a.Visible = $True&lt;br /&gt;&lt;br /&gt;#EndRegion&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;foreach($i in (gc .\computers.txt)){&lt;br /&gt;Write-Host "Processing server $i."&lt;br /&gt;$script:RowCount += 1 #Increment row count.&lt;br /&gt;$group =[ADSI]"WinNT://$i/Administrators"&lt;br /&gt;$members = @($group.psbase.Invoke("Members"))&lt;br /&gt;$adminGrp = $members foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}&lt;br /&gt;$c.Cells.Item($RowCount,1) = $i&lt;br /&gt;$c.Cells.Item($RowCount,2) = ($adminGrp -contains $group1)&lt;br /&gt;$c.Cells.Item($RowCount,3) = ($adminGrp -contains $group2)&lt;br /&gt;$c.Cells.Item($RowCount,4) = ($adminGrp -contains $group3)&lt;br /&gt;$c.Cells.Item($RowCount,5) = ($adminGrp -contains $group4)&lt;br /&gt;}&lt;br /&gt;$a.Range("B2").Select()&lt;br /&gt;$a.ActiveWindow.FreezePanes = $True&lt;br /&gt;$a.Columns.AutoFit()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is the part of that section that you'll want to modify:&lt;br /&gt;&lt;span style="color:#000066;"&gt;$group1 = "GroupName1"&lt;br /&gt;$group2 = "GroupName2"&lt;br /&gt;$group3 = "GroupName3"&lt;br /&gt;$group4 = "GroupName4"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;This assigns that the actual text that you are looking for. You would change this to a real group name that exist in the domain(s) that you are searching.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are two main sections to this script. The first section is used to setup the spreadsheet. This is pretty useful by itself. I've included the reference where I learned how to configure the spreadsheet. If you do much reporting you'll find that to be a pretty useful link.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$c.Cells.Item($RowCount,1) = "Server"&lt;br /&gt;$c.Cells.Item($RowCount,2) = $group1&lt;br /&gt;$c.Cells.Item($RowCount,3) = $group2&lt;br /&gt;$c.Cells.Item($RowCount,4) = $group3&lt;br /&gt;$c.Cells.Item($RowCount,5) = $group4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This sets up the first row of the spreadsheet, or the column header. You could added or remove the group names as required. Just add any addition groups in subsequent columns, i.e. &lt;strong&gt;$RowCount,X&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The next three lines are used to manipulate the bold and width features of the spreadsheet. They simply make the spreadsheet more readable.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$a.Range("A1:E1").Select()&lt;br /&gt;$a.Selection.Font.Bold = $True&lt;br /&gt;$a.Columns.AutoFit()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The next section will iterate iterate through the text file computers.txt, and search the Administrators group on each computer.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;&lt;strong&gt;foreach($i in (gc .\computers.txt)){&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you wanted to check the membership on a different group you would change that here.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000066;"&gt;$group =[ADSI]"WinNT://$i/Administrators"&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This piece of code does the actual work of searching the remote computer for the group membership.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$group =[ADSI]"WinNT://$i/Administrators"&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$members = @($group.psbase.Invoke("Members"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$adminGrp = $members foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And for the output to the spreadsheet, for each cell the name of each domain account is checked against the value of $adminGrp.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If the value of $groupX is found in the contents of $adminGrp, then a True is placed into the current cell, other wise a False is placed into the current cell.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#000066;"&gt;$c.Cells.Item($RowCount,2) = ($adminGrp -contains $group1)&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Finally some final manipulation of the spreadsheet is done for neatness.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$a.Range("B2").Select()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$a.ActiveWindow.FreezePanes = $True&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000066;"&gt;$a.Columns.AutoFit()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Here is how the output looks on the screen looks when the script is run:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;$ .\list_admin_group_members.ps1&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;True&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;True&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;Processing server s30004w014011.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;Processing server 10.87.52.198.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;True&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;True&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#003300;"&gt;$&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Also here is a screenshot of how the spreadsheet looks once the script has run:&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_4l4BAxpJHoY/SKgvPu3lN5I/AAAAAAAAABk/80F2Su189Is/s1600-h/dir.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5235486514143901586" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_4l4BAxpJHoY/SKgvPu3lN5I/AAAAAAAAABk/80F2Su189Is/s400/dir.bmp" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_4l4BAxpJHoY/SKgvPu3lN5I/AAAAAAAAABk/80F2Su189Is/s1600-h/dir.bmp"&gt;&lt;/a&gt;&lt;a href="http://2.bp.blogspot.com/_4l4BAxpJHoY/SKgvPu3lN5I/AAAAAAAAABk/80F2Su189Is/s1600-h/dir.bmp"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;That's it for this script. Please let me know if you have any questions, or issues when running this script.&lt;br /&gt;&lt;br /&gt;Thanks&lt;br /&gt;Patrick&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4308036351571310943-186430879587713895?l=scriptingjournal.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingjournal.blogspot.com/feeds/186430879587713895/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4308036351571310943&amp;postID=186430879587713895&amp;isPopup=true' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/186430879587713895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/186430879587713895'/><link rel='alternate' type='text/html' href='http://scriptingjournal.blogspot.com/2008/08/get-or-add-local-group-members-to.html' title='Get or Add Local Group Members to a Remote Computer'/><author><name>Patrick</name><uri>http://www.blogger.com/profile/00138059907679045968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_4l4BAxpJHoY/SK3UIG65rGI/AAAAAAAAABs/iShSDdBcBOk/S220/DSC01338.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_4l4BAxpJHoY/SKc6J6nS9cI/AAAAAAAAABc/gaS2IPWM7T8/s72-c/dir.bmp' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4308036351571310943.post-6237379808279920708</id><published>2008-07-28T15:18:00.000-05:00</published><updated>2008-07-28T15:38:12.945-05:00</updated><title type='text'>Get-QADGroupMember</title><content type='html'>A friend of mine posed the following question to me today at work:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;Do you have any script to input a security group (GG or DLG, etc) and dump/extract the members (SAMID and e-mail address) into a file (txt or csv)?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As a matter of fact I do have a script to do that, actually it is more of a one liner. Here is the text. The text in red would be replaced with whatever group you wanted:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;Get-QADGroupMember &lt;span style="color:#ff0000;"&gt;grp-wism-admins&lt;/span&gt;  select samaccountname, displayname, email  Export-Csv -Path groupsearch.csv –NoTypeInformation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;One caveat. For this to run you have to install the AD cmdlets from Quest Software. These are available free from Quest. These are very powerful, useful cmdlets which make working with Active Directory a breeze in Powershell.&lt;br /&gt;&lt;br /&gt;The software download  is available here:&lt;br /&gt;&lt;a href="http://www.quest.com/powershell/activeroles-server.aspx"&gt;http://www.quest.com/powershell/activeroles-server.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You'll want to download and install the 32 or 64 bit version based on your hardware. You'll also want to download the PDF based Administrator's Guide. It details the install, and also gives good examples of the Quest cmdlets. Help on the Quest cmdlets is also available through standard Powershell help methods. i.e. help get-qadgroupmember -full&lt;br /&gt;&lt;br /&gt;Let me know if you have any questions or comments.&lt;br /&gt;&lt;br /&gt;Thanks&lt;br /&gt;Patrick&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4308036351571310943-6237379808279920708?l=scriptingjournal.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingjournal.blogspot.com/feeds/6237379808279920708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4308036351571310943&amp;postID=6237379808279920708&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/6237379808279920708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/6237379808279920708'/><link rel='alternate' type='text/html' href='http://scriptingjournal.blogspot.com/2008/07/get-qadgroupmember.html' title='Get-QADGroupMember'/><author><name>Patrick</name><uri>http://www.blogger.com/profile/00138059907679045968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_4l4BAxpJHoY/SK3UIG65rGI/AAAAAAAAABs/iShSDdBcBOk/S220/DSC01338.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4308036351571310943.post-1536629625884555203</id><published>2008-07-26T09:49:00.000-05:00</published><updated>2008-07-28T11:49:16.903-05:00</updated><title type='text'>Working with ACLS</title><content type='html'>One thing I frequently do is to migrate data from one server to another. With that data migration comes lots of clean up in the form of security permissions. I've been working on a way to use Powershell to get the security perms on a folder. Here is what I have so far. It works pretty well. Currently the data written to the screen, as well as to a spreadsheet called Output.xls.&lt;br /&gt;&lt;br /&gt;Some more areas I want to add:&lt;br /&gt;1. Make the spreadsheet an option by adding a switch /excel.&lt;br /&gt;2. Make the spreadsheet activity part of a function call.&lt;br /&gt;&lt;br /&gt;Let me know if you have any quesitons, or recommendations.&lt;br /&gt;&lt;br /&gt;Here is the script text:&lt;br /&gt;***********************************************************************************&lt;br /&gt;&lt;span style="color:#000099;"&gt;&lt;br /&gt;# Inputbox - Prompt for path to scan&lt;br /&gt;$x = New-Object -comobject MSScriptControl.ScriptControl&lt;br /&gt;$x.language = "vbscript"&lt;br /&gt;$x.addcode("function getInput() getInput = inputbox(`"Enter the path to scan.`",`"Path`") end function")&lt;br /&gt;$path = $x.eval("getInput")&lt;br /&gt;#delete old output file.&lt;br /&gt;Remove-Item .\output.xls -force  Out-Null&lt;br /&gt;#Open a spreadsheet&lt;br /&gt;#Region&lt;br /&gt;$RowCount = 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000099;"&gt;#Nice reference for the Excel activity.&lt;br /&gt;#http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept06/hey0908.mspx&lt;br /&gt;$a = New-Object -comobject Excel.Application&lt;br /&gt;#$a.Visible = $True&lt;br /&gt;$b = $a.Workbooks.Add()&lt;br /&gt;$c = $b.Worksheets.Item(1)&lt;br /&gt;$c.Cells.Item($RowCount,1) = "Path"&lt;br /&gt;$c.Cells.Item($RowCount,2) = "Owner"&lt;br /&gt;$c.Cells.Item($RowCount,3) = "Account and Perm"&lt;br /&gt;#EndRegion&lt;br /&gt;function scanACLs($strPath )&lt;br /&gt;{&lt;br /&gt;$owner = ($strPath  Get-Acl  select owner)&lt;br /&gt;$ownerTemp = $owner.Owner&lt;br /&gt;#$pathTemp = $strPath.PSChildName&lt;br /&gt;$strPath  Get-Acl  select accesstostring  fl  Out-File -Force -Width 200 -filepath .\temp.txt&lt;br /&gt;#Combine path and perms for output.&lt;br /&gt;foreach ($i in(gc .\temp.txt))&lt;br /&gt;{&lt;br /&gt;#Split if string contains 'AccessToString'&lt;br /&gt;if ($i.contains("AccessToString"))&lt;br /&gt;{&lt;br /&gt;$strTemp = (($i.split(":"))[1]).trim()&lt;br /&gt;Write-Host "Owner:$ownerTemp Perms:$strTemp"&lt;br /&gt;$script:RowCount += 1&lt;br /&gt;$c.Cells.Item($RowCount,1) = $strPath&lt;br /&gt;$c.Cells.Item($RowCount,2) = $ownerTemp&lt;br /&gt;$c.Cells.Item($RowCount,3) = $strTemp&lt;br /&gt;}&lt;br /&gt;elseif ($i.length -gt 0)&lt;br /&gt;{&lt;br /&gt;$strTemp = $i.trim()&lt;br /&gt;Write-Host "Owner:$ownerTemp Perms:$strTemp"&lt;br /&gt;$script:RowCount += 1&lt;br /&gt;$c.Cells.Item($RowCount,1) = $strPath&lt;br /&gt;$c.Cells.Item($RowCount,2) = $ownerTemp&lt;br /&gt;$c.Cells.Item($RowCount,3) = $strTemp&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;#Main&lt;br /&gt;#This will go through the folder obtained in the Message Box at the launch of the script.&lt;br /&gt;#The function scanACLS is called for each child item.&lt;br /&gt;foreach ($i in(dir $path  sort name))&lt;br /&gt;{&lt;br /&gt;Write-Host "Scanning "$path"\"$i&lt;br /&gt;scanACLs($path+"\"+$i)&lt;br /&gt;#&lt;br /&gt;}&lt;br /&gt;#Save the spreadsheet and make it visible once it is loaded with all of the data from the scanning.&lt;br /&gt;$b.SaveAs("$pwd\output.xls")&lt;br /&gt;$a.Visible = $True&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4308036351571310943-1536629625884555203?l=scriptingjournal.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingjournal.blogspot.com/feeds/1536629625884555203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4308036351571310943&amp;postID=1536629625884555203&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/1536629625884555203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/1536629625884555203'/><link rel='alternate' type='text/html' href='http://scriptingjournal.blogspot.com/2008/07/working-with-acls.html' title='Working with ACLS'/><author><name>Patrick</name><uri>http://www.blogger.com/profile/00138059907679045968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_4l4BAxpJHoY/SK3UIG65rGI/AAAAAAAAABs/iShSDdBcBOk/S220/DSC01338.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4308036351571310943.post-328917746789355264</id><published>2008-07-24T09:29:00.000-05:00</published><updated>2008-07-24T09:42:02.955-05:00</updated><title type='text'>Powershell - Get AD User Info</title><content type='html'>Frequently during my daily work I need to gather information on users that are contained in our Active Directory listing.&lt;br /&gt;This script is used to quickly gather information on a users home folder, SAM account name, their email address,  and the size of their home folder.&lt;br /&gt;&lt;br /&gt;I use this a lot when I am moving users home folders from one server to another. To save time I frequently have the line that gathers home folder size remarked out with #.&lt;br /&gt;&lt;br /&gt;The user account names that I am searching for are contained in a text file called&lt;br /&gt;accounts.txt. This file is contained in the same folder as this script. The output is sent to the screen as well as a log file called output.csv.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#330099;"&gt;$userArray = @("SAMID,HomeDirectory,EmailAdress,HomeFolderSize")&lt;br /&gt;$allUsers = gc .\accounts.txt&lt;br /&gt;$tempArray = @()&lt;br /&gt;function logfile($strData)&lt;br /&gt;{&lt;br /&gt;Out-File -filepath output.csv -inputobject $strData -append&lt;br /&gt;}&lt;br /&gt;function getAccountInfo&lt;br /&gt;{&lt;br /&gt;$strName = $currentUser&lt;br /&gt;$strFilter = "(&amp;amp;(objectCategory=User)(samAccountName=$strName))"&lt;br /&gt;#Get User AD info&lt;br /&gt;$objSearcher = New-Object System.DirectoryServices.DirectorySearcher&lt;br /&gt;$objSearcher.Filter = $strFilter&lt;br /&gt;$objPath = $objSearcher.FindOne()&lt;br /&gt;$objUser = $objPath.GetDirectoryEntry()&lt;br /&gt;[string]$folder = $objUser.homeDirectory&lt;br /&gt;[string]$email = $objUser.mail&lt;br /&gt;[string]$samID = $objUser.sAMAccountName&lt;br /&gt;[string]$folderSize= getFolderSize($objUser.homeDirectory)&lt;br /&gt;#$objUser.memberOf&lt;br /&gt;&lt;br /&gt;$result = "$samID,$folder,$email,$folderSize"&lt;br /&gt;$result #This causes the output to steam out, and be piped as the return from the function.&lt;br /&gt;$folderSize = $null&lt;br /&gt;$fs = $null&lt;br /&gt;}&lt;br /&gt;function getFolderSize($strPath)&lt;br /&gt;{&lt;br /&gt;$fs = New-Object -comobject Scripting.FileSystemObject&lt;br /&gt;#Check validity of $strPath&lt;br /&gt;if ($fs.FolderExists($strPath))&lt;br /&gt;{&lt;br /&gt;[double]$tempSize = ($fs.GetFolder($strPath).size) / 1024 / 1024&lt;br /&gt;$tempSize = '{0:N}' -f[double]$tempSize&lt;br /&gt;$tempSize&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;$tempSize = "Bad folder path!"&lt;br /&gt;$tempSize&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;$header = "SAMID,HomeDirectory,EmailAdress,HomeFolderSize"&lt;br /&gt;Out-File -filepath output.csv -inputobject $header&lt;br /&gt;foreach ($currentUser in $allUsers)&lt;br /&gt;{&lt;br /&gt;$tempOutput = getAccountInfo $currentUser&lt;br /&gt;$tempOutput&lt;br /&gt;$userArray += [string[]]$tempOutput&lt;br /&gt;logfile($tempOutput)&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Let me know if you have any questions about this, or if it is helpful.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Thanks&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;Patrick&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4308036351571310943-328917746789355264?l=scriptingjournal.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptingjournal.blogspot.com/feeds/328917746789355264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4308036351571310943&amp;postID=328917746789355264&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/328917746789355264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4308036351571310943/posts/default/328917746789355264'/><link rel='alternate' type='text/html' href='http://scriptingjournal.blogspot.com/2008/07/powershell-get-ad-user-info.html' title='Powershell - Get AD User Info'/><author><name>Patrick</name><uri>http://www.blogger.com/profile/00138059907679045968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_4l4BAxpJHoY/SK3UIG65rGI/AAAAAAAAABs/iShSDdBcBOk/S220/DSC01338.JPG'/></author><thr:total>0</thr:total></entry></feed>
