Thursday, July 9, 2015

Powershell: Jobs - Search for shares in ad windows servers

Job script to search for shares in a active directory environment. Update $Domain to your domain and run
#Tony Unger
#Scans all AD servers for Shares 
#50 servers at a time
#Will Prompt for creds
$i =0  
import-module activedirectory 
$creds = Get-Credential 
$myCol = @()
$Domain = ""

$Servers = Get-ADComputer -server $Domain -Filter {(OperatingSystem -Like "Windows Server*")-and (enabled -eq "true")} -Property SamAccountName | Select -expand Name

$scriptblock = {
 Get-WmiObject Win32_Share -ComputerName $server -Credential $Creds | select *

foreach($server in $Servers){
    $running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
 Write-Progress -Activity "Gathering computer info" -status "Currently on $server -- $i of $Servers.count" -percentComplete ($i / $Servers.count*100)
 if ($running.Count -le 50) {
        Start-Job -ScriptBlock $scriptblock -Name $server -ArgumentList $server, $creds 
 else {
         $running | Wait-Job

while ($running.Count -ge 1) {
      sleep 1 
    $running = @(Get-Job | Where-Object { $_.State -eq 'Running' })

foreach ($job in Get-Job ){

 $recjobs = Receive-Job -Keep -Job $job 
 foreach ($recjob in $recjobs){
    $Detail = New-Object PSObject 
  $Detail | Add-Member Noteproperty Name $ 
  $Detail | Add-Member Noteproperty Path $recjob.path 
  $Detail | Add-Member Noteproperty Server $recjob.__SERVER
  $myCol += $Detail
$myCol | export-csv -Path c:\TEMp\shares\output.csv -notype 

1 comment:

  1. 3D printing opens up a whole new world of potentialities for small Bike Helmets for Kids businesses. You can use 3D printer models to create small products, prototypes, or elements for equipment. These machines permit you to create your own custom designs. But if you’re not excited about ranging from scratch, you'll be able to|you presumably can} simply search for current information. 3D printers use a variety of|quite lots of|a wide range of} different plastics or resins to build a real, physical model from a digital 3D model in your laptop. A digital model could be created using Computer Aided Drafting software, or different frequent 3D modeling software.


Powershell: AD DHCP scope information