Showing posts with label share. Show all posts
Showing posts with label share. Show all posts

Monday, October 13, 2014

Powershell: Find all shares on domain using Jobs


Purpose: This script will search AD for all servers and report any shares(includes printers)

This script will do 50 servers at a time
Requires RSAT tools powershell
cls

#Find Shares on all Domain computers 50 at a time
#www.tonyunger.com  
  
cls   
import-module activedirectory
  
#$Global:Servers = Get-Content "C:\temp\computers.txt"  
$Global:Servers = Get-ADComputer -Filter {(OperatingSystem -Like "Windows Server*")-and (enabled -eq "true")} -Property SamAccountName | Select -expand Name  
$Global:ReportPath = "C:\temp\Shares.txt"  
  
$scriptblock = {  
       param($server)  
    $pingResult = Test-Connection -count 1 -ErrorAction SilentlyContinue $server | select IPV4Address 
       $Shares = Get-WmiObject Win32_Share -ComputerName $Server | select name 
       $values = @()  
       if($Error){  
            if( $Error -like "*Access is denied*"){  
                return ($server+",AccessDenied")  
            }  
            $Error.Clear()  
            return ($server+",")  
       }  
     
     foreach ($Share in $shares) {            
  
         $values += ($Server + "," + $Share) 
             }  
       return $values  
}  
  
function getdata{  
    $jobs = Get-Job | ? { $_.State -eq "Completed" }  
     foreach( $job in $jobs){  
        $results = Receive-Job $job  
       Add-Content $ReportPath $results  
        Remove-Job $job  
     }     
}  
  
  
Add-Content $ReportPath "Server,share"  
foreach($server in $Servers){  
          
     while( (Get-Job).count -ge 50 ){ 
            sleep -Seconds 1  
            getdata  
     } 
  
     Start-Job -ScriptBlock $scriptblock -ArgumentList $server 
}  
  
while( (get-job).count -ne 0 ){  
      sleep -Seconds 1
            getdata  
              
 }  
   
 

Tuesday, May 28, 2013

Powershell: Get permissions on each vfiler cifs share.

Purpose: Get a list of all shares on each vfiler on each filer Notes: This script needs some work with the nested foreach loops and some error check cleanup.

Import-Module dataontap

Function Get-ACLPermissions($Share){
 $acl = Get-Acl -Path $Share
return $ACL
}

$myCol = @()

$AllNetappFiler = "filer03","filer02"

foreach ($NetappFiler In $AllNetappFiler){


  write-host "Scanning $NetappFiler"   
 connect-nacontroller $NetappFiler | out-null
    $Vfilers = get-navfiler * | Select -expand Name
 foreach ($Vfiler in $Vfilers){
  connect-nacontroller $Vfiler 
  $vfiler
  $Shares = get-nacifsshare | Select -expand ShareName
  foreach ($Share in $Shares){
   Write-Host "$Vfiler insideloop"
   
   #If $Vfiler Blank then scan shares on filer.. Need to add logic
   $fullpath = "\\$Vfiler\$Share"
   
   
   
   $ShareACL = Get-ACLPermissions $fullpath
   $o = 0
   $ShareACL.Access | ForEach-Object {
    $Detail = New-Object PSObject  
    $Detail | Add-Member Noteproperty SystemName $NetappFiler
    $Detail | add-member Noteproperty Vfiler $Vfiler
    $Detail | Add-Member noteProperty Share $Share 
    
    $FileSystemRights = $ShareACL.Access[$o] | Select -ExpandProperty FileSystemRights #Example ReadAndExecute 
    $AccessControlType = $ShareACL.Access[$o] | Select -ExpandProperty AccessControlType #Example Allow/Deny
    $IdentityReference = $ShareACL.Access[$o] | Select -ExpandProperty IdentityReference #Example Everyone,Username
    $IsInherited = $ShareACL.Access[$o] | Select -ExpandProperty IsInherited #Are Permissions inherited
    $InheritanceFlags = $ShareACL.Access[$o] | Select -ExpandProperty InheritanceFlags #Type of Inheritance ContainerInherit
    $PropagationFlags = $ShareACL.Access[$o] | Select -ExpandProperty PropagationFlags #PropagationFlags
    
    switch -wildcard ($FileSystemRights) 
        { 
            "268435456*" {$FileSystemRights = "FullControl"} 
            "-536805376*" {$FileSystemRights = "Modify, Synchronize"} 
            "-1610612736*" {$FileSystemRights = "ReadAndExecute, Synchronize"} 
        }
     
    $Detail | Add-Member noteProperty IdentityReference $IdentityReference  
    $Detail | Add-Member noteProperty FileSystemRights $FileSystemRights
    $Detail | Add-Member noteProperty AccessControlType $AccessControlType
    $Detail | Add-Member noteProperty IsInherited $IsInherited
    $Detail | Add-Member noteProperty InheritanceFlags $InheritanceFlags  
    $Detail | Add-Member noteProperty PropagationFlags $PropagationFlags 
    $o++
    
    $myCol += $Detail
    }
  }


 } 
}
$myCol | Export-Csv -Path "c:\temp\Audit_NetappVfilerCifis.csv" -NoTypeInformation

Powershell: Microsoft Graph to add new roles to application registration

PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...