Showing posts with label Get-ADComputer. Show all posts
Showing posts with label Get-ADComputer. Show all posts

Tuesday, August 21, 2012

Powershell &Active Directory : Active Directory Reports in Excel.

Hi,

Active Directory reporting, some time we thinks what should a Active Directory reports contains, should i need a tool to do that reporting job? or should i purchase a active Directory tool to do this task.

One of my friend want an Active Directory Reporting tool and he was planning to buy it, i asked what are your requirements, he told me that, I want a tool which can export a data in to the Excel, and i have a list of disabled Computer accounts, User Account so that i can delete them,

I told this that that can be done easily with powershell and for him i wrote a little powershell script. this script is based on RSAT , Active Directory module. Make sure you have RSAT tools installed before running the script.

when you run the script , that will Import Active Directory Module First and then open an Excel workbook. In excel you can find 4 sheets for now. they are contains
  1. List of inactive Users Accounts
  2. List of inactive Computer Accounts
  3. Users Accounts created within a period of week.
  4. List of Users with password never expires enabled.
Script Download link : http://gallery.technet.microsoft.com/scriptcenter/Active-Directory-Reports-bb8c1cc7

21-08-2012 13-19-01
and this excel file will be saved on users Desktop.

Script Download link : http://gallery.technet.microsoft.com/scriptcenter/Active-Directory-Reports-bb8c1cc7

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Monday, June 11, 2012

Powershell and Active Directory: Find inactive Computer Accounts in Active Directory using Powershell.

 

HI,

As you know my IT manager always keep me busy. These days we are cleaning our Active Directory. My Today's "Target of the Day" is to find all in-active computer accounts.

first i start thinking how to do it ? to use some filter in "Active Directory Computer and users" or i need to do something else. After few minutes of thinking i thoughts, why not try Powershell. :)

Let's Start.

 Make sure you have "RSAT" installed on you laptop.

Now Import the Active Directory module.

Import-Module ActiveDirectory

30-04-2012 23-21-03 

..

ok, Module is imported,

we are going to use the Active Directory module cmdlet "Get-ADComputer"

"Get-ADComputer" has a property of Enabled which either is "false" or "True", the true means computer account is "enabled" and false means "Computer account is "disabled"

To find all the properties of a single computer account , use the below command.

Get-ADComputer R92DA6V -Properties *

11-06-2012 14-05-15

Ok..not lets find all disabled/in-active computer accounts.

we are going to -filter to to find all inactive account and in Filter we are defining that show all computer who has the value of $false in the property Enabled.

Get-ADComputer -Filter "Enabled -eq '$false'"

11-06-2012 14-05-39

all done ..but lets filter the output to show  us only names.

Get-ADComputer -Filter "Enabled -eq '$false'" | Select Name

11-06-2012 13-56-39

Ahh !! now it's look better...

Now i have the name of all inactive computer accounts in my AD.

Thanks for reading.

Thanks!

Aman Dhally

Buy-More-Twitter-Followers   4fb29548b6adc

Rabbit_Wants_beer

Tuesday, May 1, 2012

Powershell and Active Directory: Find all windows 7 computers with Service Pack 1 installed using PowerShell.

 

Hi,

In Our company we have "Domain Environment" or we can say "Active Directory" is deployed.  By using "Active Directory" lots of things gets easy to manage. The main things that Powershell works great with "Active Directory". To use Active Directory related CMDLETS on your client laptopt we  need to install "RSAT" tool.

Problem: On some of our company laptop there are "Automatic Updates" are on, due to these auto updates Windows 7 Service Pack 1 is installed on those laptops, and Windows 7 SP1 is not compatible with some of our in-house developed software. So we need to identify these laptops.

Let's Start : Before doing anything make sure that "RSAT" tools are installed.

Import the Active Directory module first.

Import-Module ActiveDirectory

30-04-2012 23-21-03 

After importing the Module, we are going to use Get-ADComputer cmdlet.

To view all the computer on AD we can use the below cmdlet.

Get-ADComputer -Filter *

01-05-2012 12-07-05

Lets filter it more . .. this time we want to see only those computers which have windows 7 installed.

Get-ADComputer -Filter 'OperatingSystem -eq "Windows 7 Professional"'  | select Name

Ok. now it is showing all those computers which have windows 7 installed.. let filter it more.

01-05-2012 12-09-59

As we know our main purpose is to find the "Windows 7 Computers with Service Pack 1" Installed.

Get-ADComputer -Filter '(OperatingSystem -eq "Windows 7 Professional") -and (OperatingSystemServicePack  -eq "ServicePack1")'

So finally we have the list of all windows 7 computers with SP-1 installed on them.

01-05-2012 12-43-08

Let just select Name Only.

Get-ADComputer -Filter '(OperatingSystem -eq "Windows 7 Professional") -and (OperatingSystemServicePack  -eq "Service Pack 1")' | select Name

01-05-2012 12-55-57

All sorted., Now i have the list of my all windows 7 computers which have Service Pack 1 installed on it.

Thanks

Aman Dhally

Friday, March 2, 2012

Remove Computer Account from All Domain controllers using PowerShell


Hi,

If you are using Active Directory environment in you infrastructure then you does the one thing for sure , remove / add computers to the domain.

Some times when you format user computer and add it again to the Domain it gives an error that "Computer Already exists in the domain". Or you can say that you have multiple remote offices and syncing / replication between those  all DC's are slow  and you need to delete that computer from All DC including the local and remote domain Controllers.

I wrote this small script which delete the provided "computer" in to all DC which is on you replicated Server List. Before running this script make sure you have "Active Directory" module installed.

This script works for me and hope this works for you too.

You can Download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Remove-Computer-Account-326f1e22

#########################################################
## make sure you have Active Directory Moudle Installed ##
# Import Module
Import-Module ActiveDirectory
# Variables
       $computer = $env:Computername     # Computername which you want to use
       $localdc = "Dc-XXXX"               # Chnage with ur local DC
       $credentials = Get-Credential   # This should be Admin Credentials
# AD  
       $ADResult = (Get-ADComputer -Filter {cn -like $computer}  -Server "$localdc" -Credential $credentials  ).name -eq $computer
       $dclist = (Get-ADDomain -Server "$localdc" -Credential $credentials).ReplicaDirectoryServers   
       $arrDc = @()
       foreach ($obj in $dclist) {
       $nlist = $obj.Replace("`.XYZ.com","")  # Replace XYZ.com with your Domain Name
       $arrDc += $nlist
       }
      
# If you want to remove it from AD remove -wahtif and un-commnted -confirm:$false
      
       if ($ADResult -eq $true) {      
       Write-Host -ForegroundColor  Red "$computer exists in AD, I am going to remove it"
       foreach ( $dc in $arrdc) {
              Remove-ADComputer -Identity "$computer"  -Server $dc  -Credential $credentials  -whatif  #-confirm:$false
              write-host $([char]7)
              write-Host "$computer is deleted on $dc " -ForegroundColor Green
              }     
              }
                          
## ENd of Script##### a m a n   d h a l l y ________                
02-03-2012 15-35-04

You can Download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Remove-Computer-Account-326f1e22

Thanks for Reading.
New Delhi PowerShell User Group
Aman Dhally