Finding the logon scripts

What logon scripts are in your environment

"`nMicrosoft"            
Get-ADUser -LDAPFilter "(&(objectclass=user)(objectcategory=user)(scriptpath=*))" -Properties *|            
Format-Table Name, DistinguishedName, ScriptPath -AutoSize            
            
"`nAD provider"            
Get-ChildItem -Filter "(&(objectclass=user)(objectcategory=user)(scriptpath=*))" `
 -Path Ad:\"DC=Manticore,DC=org" -Recurse |             
foreach {             
 $user = [adsi]"LDAP://$($_.DistinguishedName)"            
 $user | select @{N="Name"; E={$_.name}},             
 @{N="DistinguishedName"; E={$_.distinguishedname}},            
 @{N="LogonScript"; E={$_.scriptpath}}            
} | Format-Table -AutoSize            
             
"`nQuest"            
Get-QADUser -LDAPFilter "(&(objectclass=user)(objectcategory=user)(scriptpath=*))" -IncludeAllProperties |            
Format-Table Name, DN, ScriptPath -AutoSize            
            
"`nScript"            
$root = [ADSI]""            
$search = [adsisearcher]$root            
$search.Filter = "(&(objectclass=user)(objectcategory=user)(scriptpath=*))"             
$search.SizeLimit = 3000            
$search.FindAll() | foreach {            
             
$user = $_.GetDirectoryEntry()            
$user | select @{N="Name"; E={$_.name}},             
 @{N="DistinguishedName"; E={$_.distinguishedname}},            
 @{N="LogonScript"; E={$_.scriptpath}}            
} | Format-Table -AutoSize

Standard search for any user that has the scriptpath attribute set and then display name, distinguished name and scriptpath (logon script name).

To search for a given logon script – change the search filter

“(&(objectclass=user)(objectcategory=user)(scriptpath=<logon_script_name>))”

To just get a list of active logon scripts change the Format-Table as shown below

Get-ADUser -LDAPFilter “(&(objectclass=user)(objectcategory=user)(scriptpath=*))” -Properties *|
sort scriptpath | select ScriptPath -Unique

Advertisements
This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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