Skip to main content

Posts

Showing posts with the label AD

Export Local Admin details for Computers in a particular OU

Needed to export the Computer Name and all the local Admins for a particular OU Used the following Powershell script to export the details $computers = Get-ADComputer -SearchBase "OU=Servers,OU=Computers,OU=ABC,DC=XYZ,DC=Domain,DC=com" -Filter * | %{$_.name} foreach($computer in $computers) { $computer $s1 = $null $ADSIComputer = [ADSI]("WinNT://$computer,computer") $adminGroup  = $ADSIComputer.psbase.children.find('Administrators', 'Group') $adminMembers = $adminGroup.psbase.invoke("members") | %{$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)} | %{$s1 += $_ + ","} $computer + "," + $s1.Trim(",") >> .\LocalAdmins.csv } Hope this helps

Find all active domain Users in a particular OU

Sometime s you need to find AD users in a particular OU who have logged on to any system  in past 90 days . I found this powershell query online that helped me to create a html report for all users with the logon times. $oldDate = (Get-Date).AddDays(-90).ToFileTime().toString() Get-ADUser -SearchBase 'OU=Users,dc=domain,dc=com' -Properties lastlogontimestamp -LDAPFilter "(lastlogontimestamp>=$oldDate)" |     select @{n='User';e={$_.name}}, @{n='LastLogOn';e={[datetime]::FromFileTime($_.lastlogontimestamp)}} |     ConvertTo-Html -Title 'Recent Users' | Out-File 'RecentUsers.html' Invoke-Item 'RecentUsers.html' Hope this helps.

Exporting Group Membership from AD

Sometimes you may find yourself in a situation where you have to export the members of a security group from AD. In such a situation we can use following commands : (On a server were AD tools - remote Administration tools are installed) dsquery group -name “Group Name” | dsget group -members > users.csv However this will give results with the respective LDAP paths e.g CN=Server01,OU=V,OU=Servers,OU=Computers,OU=Loc,DC=domain,DC=com You might have only wanted to get the name not the netire path. Just open the csv file you exported and  (Press Ctrl + H )  i.e Find and  Replace these 1 by 1 Use Replace All option , the image is shown here: OU=* CN= , Additionally you may also use the following command: net group “Group Name” /domain > users.csv Again you have to do some formatting of the results. Hope this helps.