none
Audit AD RRS feed

  • Question

  • Hello,

    I need to know the number of groups, users, pcs and shared folders of my domain.

    Can anybody tell me how I can write a script to do this?

    Thanks in advance

    Wednesday, June 19, 2013 8:49 AM

All replies

  • This is in the wrong forum which is probably why you've not received any replies yet

    OK I'm speed writing here and this is untested ...also you'll need the AD powershell module (RSAT or, god forbid run from a DC)

    This should get you started - word of warning though - if you only want to show shares on PC's you'll need to edit it appropriately ...also if you have a large domain it will take a while to iterate through each PC counting the shares.

    Finally the share count will currently count admin shares eg C$, ADMIN$, IPC$ - if you dont want these you'll have to filter the wmi query to remove them -eg add a | Where-Object {$_.Name -ne "C$" -or $Name -ne "ADMIN"} etc etc

    Import-Module ActiveDirectory $ShareCount = $Null $Computers = Get-ADComputer -Filter * | Select-Object Name $Users = Get-ADUser -Filter * | Select-Object Name $SecurityGroups = Get-ADGroup -Filter * | Where-Object {$_.GroupCategory -eq "Security"} | Select-Object Name $DistributionGroups = Get-ADGroup -Filter * | Where-Object {$_.GroupCategory -eq "Distribution"} | Select-Object Name ForEach ($Computer in $Computers) { $Ping = ping $Computer -n 1 If ($ping -like "Ping request could not find host*") #checks compter is on before continuing { Write-Host $Computer -ForeGroundColor Red -BackGroundColor Green Write-Host $Computer "Not Found - Probably Turned Off" -ForeGroundColor Red -BackGroundColor Cyan } Else { Write-Host $Computer -ForeGroundColor Red -BackgroundColor Green $Shares = Get-WMIObject -Class Win32_Share -ComputerName $Computer #gets shares on computer $Shares -ForeGroundColor Red -BackgroundColor Green #Shows shares that are being counted $Count = Shares.Count #counts shares $ShareCount = $ShareCount + $Count

    } } Write-Host "There Are" $Computers.Count "Computers In Your Domain" -ForeGroundColor Red -BackgroundColor Cyan Write-Host "There Are" $Users.Count "Users In Your Domain" -ForeGroundColor Red -BackgroundColor Cyan Write-Host "There Are" $SecurityGroups.Count "Security Groups In Your Domain" -ForeGroundColor Red -BackgroundColor Cyan Write-Host "There Are" $DistributionGroups.Count "Distribution Groups In Your Domain" -ForeGroundColor Red -BackgroundColor Cyan Write-Host "There Are" $ShareCount "Shares On All Computers In Your Domain" -ForeGroundColor Red -BackgroundColor Cyan

    Like I said ...very quick and dirty but should serve to get you started

    Cheers


    • Edited by IT Badger Thursday, June 20, 2013 8:22 AM spelling mistake in var
    Thursday, June 20, 2013 8:21 AM