Showing posts with label Format-Table. Show all posts
Showing posts with label Format-Table. Show all posts

Wednesday, May 2, 2012

Powershell and Active Directory: Find all distribution groups in AD with their Email-ID along with the date of creation using Powershell.

 

Hi,

Today i got task from my IT Manager to create a list of all distribution group in our AD along with there Email-Id's also he required the date of creations of those distribution groups.

I thought lets try this with PowerShell. I was planning to use Get-ADGroup cmdlet to fulfil my purpose. This cmdlet only available if you have  "RSAT" installed on you laptop.

Lets Start.

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

To view all the group n your Active Directory we can use below command. This will show all the Groups.

Get-ADGroup -Filter *

02-05-2012 15-06-02

Lets filter the output and choose to view only "Distribution Groups"

Get-ADGroup -Filter 'GroupCategory -eq "Distribution"'

So we have the the list of distribution Groups. but our purpose is still not resolved. now we need Mail and Date of creation of these Groups.

02-05-2012 15-11-10

To view the mail, creation date we need to add -Properties *  to the  Get-ADGroup cmdlet.

Get-ADGroup -Filter 'GroupCategory -eq "Distribution"' -Properties * | select Name,mail,whenCreated | ft -AutoSize

02-05-2012 15-25-28 

All Sorted, our purpose is fulfil. If required we can also export the out to .CSV or .TXT format.

I Hope that it helps someone.

Thanks

Aman Dhally

spiderlove02

Tuesday, November 22, 2011

Outputting Text Reports without Truncating

 

PowerTip of the Day, from PowerShell.com:

If you want to capture PowerShell results in a text file, you can redirect the results or pipe them to Out-File. In any case, what you capture is the exact representation of what would have been displayed in your PowerShell console. So, depending on the amount of data, columns may be missing or truncated.
Here is a function called Out-Report. You can pipe any result to it to create a text file that does not truncate columns. In addition, with the –Open switch parameter, you can open the resulting text file, too:
   1: function Out-Report {
   2:  
   3:  param(
   4:  
   5:   $Path = "$env:temp\report.txt",
   6:  
   7:   [switch]$Open
   8:  
   9:  )
  10:  
  11:  
  12:  
  13:  $Input |
  14:  
  15:   Format-Table -AutoSize |
  16:  
  17:   Out-File $Path -Width 10000
  18:  
  19:  
  20:  
  21:   if($Open) { Invoke-Item $Path }
  22:  
  23: }

Try it:

Get-Process | Out-Report -Open

Thanks

Aman