Posts

Showing posts with the label Automation

Powershell - Add Users / Computers to AD Group

The below script can be used to add multiple user or computer to an AD group. The list of users / computers to be provided in the text file. Usage: See below example. To see full help Type script name and press enter. You have to provide computer name or user name (SAM Account) in text file. Add computer to AD Group     .\AddObjectsToADGroup.ps1 -FileName Computers.txt -ADGroupName "TestGroup" -ObjectType Computer .Add user to AD group     .\AddObjectsToADGroup.ps1 -FileName Computers.txt -ADGroupName "TestGroup" -ObjectType User Github Repostiorty Raw File #Script #Version: 1.0 #Author: Equebal Ahmad <# .SYNOPSIS     Add the computers / users account to an AD Group .DESCRIPTION     Add the computers / users account to an AD Group     The script can add user and computer in an AD group. You need to pass this with ObjectType parameter. .EXAMPLE     .\AddObjectsToADGrou...

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...

PowerShell - Retrieve AD Computers Properties

# Retrieve AD computer properties such as LastLogonDate. # The list of machine need to be added in hosts.txt file in script folder # The result will be saved to Output.csv file in script folder Import-Module ActiveDirectory $invocation = (Get-Variable MyInvocation).Value $directorypath = Split-Path $invocation.MyCommand.Path $input = $directorypath + "\host.txt" $output = $directorypath + "\output.csv" Get-Content $input | ForEach-Object { Get-ADComputer $_ -Properties * | Select-Object Name,LastLogonDate,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,WhenCreated,Description }   | Export-Csv $output