Tag: PowerShellCode

Oct 07

PowerShell Code: Find User in Active Directory Forest

  PowerShell Code: Find User in Active Directory Forest There are times when you have a userid, but don’t know where in a multi-domain forest a user is located. Here’s some PowerShell code for locating the user’s domain. PowerShell code leverages the Active Directory PowerShell module to query a local Global Catalog (GC) server in …

Continue reading

Sep 25

PowerShell Code: Find Active Directory Site Containing AD Subnet

Here’s a quick script that returns the site in the Active Directory forest given a subnet (ex. 10.20.30.0). Match-Subnet2Site.ps1   Param ( [string]$Subnet ) $IPSubnetRegEx = ‘\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0)\b’ # $IPRegEx = ‘\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b’ IF ($Subnet -match $IPSubnetRegEx) { Write-Output “Searching the AD forest for subnet: $Subnet ” } ELSE { Write-Error “The provided subnet ($Subnet) is not …

Continue reading

Sep 21

PowerShell: Parse a Large Multi-Line Text Field Based on String Value & Extract Text

Parsing a large multi-line text field (variable) for a specific string and extract text from it: $EventMessage = @” An account was successfully logged on. Subject: Security ID:  SYSTEM Account Name:  METCORPWKS201$ Account Domain:  METCORP Logon ID:  0x2b5 Logon Type:10 New Logon: Security ID:  METCORP\Administrator Account Name:  Administrator Account Domain:  METCORPWKS201 Logon ID:  0bc123d Logon …

Continue reading

Jul 02

PowerShell: Get the Dates When the Active Directory Schema Was Updated

  The Microsoft Scripting Guys blog has a great article on determining when schema updates were performed along with some information about the schema changes – at least enough to see if it was an Exchange update.   ########################### # Get Schema Update Dates # ########################### # Code from: http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/05/how-to-find-active-directory-schema-update-history-by-using-powershell.aspx write-output “Reading all schema data… …

Continue reading

Jun 26

PowerShell: Get Active Directory Instantiation Date

  The Scripting Guys blog posted a very useful script on how to determine when the Active Directory Forest was stood up.   ############################# # Get AD Instantiation Date # ############################# # Code from: http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/05/how-to-find-active-directory-schema-update-history-by-using-powershell.aspx write-output “Checking Active Directory Creation Date… ” `r write-output “Displaying AD partition creation information ” `r Import-Module ActiveDirectory Get-ADObject -SearchBase …

Continue reading

Jun 24

PowerShell: Using a HashTable to Identify Active Directory Schema & Exchange Version

It’s easy to get the Active Directory schema version as well as the installed Exchange (schema) version by using the Active Directory PowerShell cmdlet, Get-ADObject. This script leverages a built-out HashTable to perform a lookup against the version numbers. ################################### # Create Schema Version Hashtable # 20140606-14 ################################### Write-Verbose “Create Schema Version HashTable `r ” …

Continue reading

May 27

PowerShell Code: Get & Set Active Directory Tombstone Lifetime and Active Directory Delete & Recycle Operations

Active Directory is a multi-master database replicated among multiple Domain Controllers. In order to ensure that objects are fully replicated before deletions are processed (purged), objects that are marked for deletion before they are completely purged from Active Directory. Active Directory marks the object as deleted by performing the following actions on the object: The …

Continue reading