daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # $Domains would be an input variable, its just a collection of strings: 'dadsuswe.dads.navy.mil','dadsusea.dads.navy.mil'
  2. # The input can come from a text file, or just a flat typed array in powershell, or it can just be one or two domains at a time
  3. <#
  4.     Examples:
  5.     $Domains = Get-Content .\domains.txt
  6.     $Domains = @('dadsuswe...','dadsusea...','dmci-isf...')
  7.  
  8.     Then we could just do
  9.  
  10.     This-Cmdlet -Domains $Domains -File users.csv
  11. #>
  12. foreach ($Domain in $Domains){
  13.     $psdriveObj = @{
  14.         Server = $Domain
  15.         Name = ($Domain.ToString().split('.')[0])
  16.         PSProvider = ActiveDirectory
  17.         Root = ''
  18.         Credential = $cred
  19.     }
  20.     $Domain_PSDrives.Add((New-PSDrive @psdriveObj))
  21. }
  22.  
  23. foreach ($drive in $Domain_PSDrives){
  24.     Set-Location ($drive.Name + ':\')
  25.  
  26.     $i = ($drive.Server).Split('.')
  27.     $cnStr = [System.Collections.ArrayList]::New()
  28.     for($c=0;$c -lt ($i.count);$c++){
  29.         $cnStr.Add(("OU="+$i[$c])) | Out-Null
  30.     }
  31.     $OUPath = ($ouStr + $cnStr) -Join ','
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top