Posts

Showing posts with the label Active Directory

Powershell Script: Validate if Computer account exists in Active Directory

The below script will let you quickly validate if given computers are exists in Active Directory. You have to keep both script and Computer.txt in same location. Add the computers name in text file separated by new line. The result will be saved in Output.csv file in script folder. $File = "$PSScriptRoot\Computers.txt"  $LogFile = "$PSScriptRoot\Output.csv"    # Function to WriteLog File  Function WriteLog($Msg)  {      $Text = $Msg      Add-Content -Path $LogFile  $text       Write-Host $Text  }      $ComputerList = Get-Content -Path $File  $TotalRecord = ($ComputerList).Count  foreach ($computer in $ComputerList){      $error.clear()      try{$ADComputer = Get-ADComputer $computer -Properties *}      catch{ WriteLog "$computer,Does not Exists in AD"}    ...

Powershell - List AD Organizational Unit and GPOs linked to them

The below script will search Active Directory for all Organizational Unit which contain specific name and list them along with all Group Policies linked to those OUs. Example: The below command will get a list of all OUs which name contains 'Test'. It will also show the details of all GPOs linked to OUs. Usage Example: .\Get-OUList.ps1 –OUName “Test” #Script [ CmdletBinding () ] Param (   [ Parameter (Mandatory = $True ) ]   [ string ] $OUName   ) $invocation = ( Get-Variable MyInvocation ) . Value $directorypath = Split-Path $invocation . MyCommand . Path $outputfile = $directorypath + "\Result.csv" $OUName = "*" + $OUName + "*" $Results = @() $OUList = Get-ADOrganizationalUnit -Filter * | Where-Object -FilterScript { $PSItem . distinguishedname -like $OUName } foreach ( $OU in $OUList ){     $LinkedGPOs = Get-ADOrganizationalUnit -Identity $OU | select -Expa...