Month: October 2014

PowerShell: Find the LDAP address from a User Account


Import-Module ActiveDirectory
$Account = Read-Host 'Enter User Account'
$DN = Get-ADuser $Account
Write-Host LDAP://$DN

Run the script from your domain controller.

The script will ask you for the user logon name, and will display the relative LDAP address in the form of: LDAP://CN=………,OU=…..,OU=………,DC=…….,DC=…..

One-Liner: Query Network Connection With a Specific IP/DNS/… (Powershell)

This line will come in handy when you want to change the settings of a network connection based on its configurations not the connection name…

The below example will return the network connections that have a static IP configurations, and the DNS servers match 10.10.10.x

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=TRUE and DHCPEnabled=FALSE" | Where-Object { $_.DNSServerSearchOrder -match '^10\.10\.10\.' }

You can replace $_.DNSServerSearchOrder by the required value ( $_.IPAddress, $_.DefaultIPGateway,…..etc)

In on of the rel life examples, I wanted to make a script to modify the DNS settings of Network connections with a specific DNS servers value regardless the name of the connection, so I can run the script on multiple servers. The final script looked something like this:

$DNSServers = "", ""
$Networks = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=TRUE and DHCPEnabled=FALSE" | Where-Object { $_.DNSServerSearchOrder -match '^10\.10\.10\.' }
Foreach ($Network in $Networks){

One-Liner: Move Multible Users to a Specific OU (Powershell)

This PowerShell command will read the users’ alias from a text file, and will move them to a specific OU.

  • On you domain controller, create a text file at C:\MoveUsers\Users.txt
  • In Users.txt add users aliases one per each line.
  • Get the DN for the destination OU, one easy common way, is to open ADSI Edit, expand the tree on the left till you reach the desired OU –> in the properties of the OU you will get the OU DN.
  • Open PowerShell and import the Active Directory Module:
Import-Module ActiveDirectory
The Command:
Get-Content C:\MoveUsers\Users.txt | Foreach{Get-ADUser $_ | Move-ADObject -TargetPath "OU=HR Users,OU=Users,DC=Masry,DC=Lab"}

Replace OU=HR Users,OU=Users,DC=Masry,DC=Lab with your OU DN obtained previously.

Change the Location of Outlook OST File

How to move Outlook.ost and Outlook0.ost to another location?

– Click Tools –> E-mail Accounts –> Next –> select your Exchange account

– Click Change –> More Settings –> select the Advanced tab.

– Unchecke “Use Chached Exchange Mode” –> then click OK –> answer the prompt that told your settings would take effect the next time you start Outlook –> click Next –> then Finish.

– Close Outlook

– Open the Mail applet in Control Panel –> Click E-mail Accounts –> again select your Exchange account –> click Change –> More Settings –> Advanced.

– Click “Offline Folder File Settings” –> “Disable Offline Use” –> OK –> OK –> Next.

– Reclick More Settings –> Advanced –> “Offline Folder File Settings”.

– Enter a new OST path. click OK

– Rechecked “Use Cached Exchange Mode” –> click OK –> Next –> Finish.

When I restarted Outlook, receiv a brief popup stating that Outlook was preparing for first time use.
When it finished opening, I was back in cached Exchange mode and my OST was in the new location.

Credits: Brian Tillman