Advertisement
darksim905

RADTools is RAD

Apr 30th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. ----------------------------------------
  3.  
  4. RADToolkit                        
  5.   Created By : Ryan Abbott            
  6.   Date: 04-30-2014                    
  7.   Purpose: Toolkit for working with AD
  8.                                        
  9. ----------------------------------------
  10. #>
  11.  
  12. #Set Script Params here:
  13. $waitDuration = 2
  14.  
  15. #Create outerloop
  16. :OuterLoop do
  17. {
  18.  
  19. #Begin Main Loop
  20. Do {
  21.  
  22. clear
  23.  
  24. #Write Menu
  25. Write-Output "
  26.  
  27.    --------------Main Menu------------------
  28.      
  29.         1 = Query Specific User
  30.         2 = Query All Users
  31.         3 = Unlock Account
  32.         4 = Script Settings
  33.         99 = Quit
  34.  
  35.       Created by: Ryan Abbott
  36.  
  37.    -----------------------------------------"
  38.  
  39.    $m1Choice = read-host -prompt "Select an Option and press Enter"
  40.    } until($m1Choice -eq "1" -or $m1Choice -eq "2" -or $m1Choice -eq "3" -or $m1Choice -eq "4" -or $m1Choice -eq "99")
  41.  
  42.    Switch($m1Choice){
  43.  
  44.     "1" {
  45.           clear
  46.           $userName = read-host -prompt "Enter Username to Query"
  47.           $c = Get-ADUser -Identity $userName -Properties MemberOf, LastLogonDate, LastBadPasswordAttempt
  48.          
  49.           echo $c
  50.  
  51.           $prompt = read-host -prompt "Do you wish to save to file? (Y/N)"
  52.           if ($prompt -eq 'y')
  53.           {
  54.             $c | export-csv "$fPath\ADUser-Export_$userName.csv"
  55.             Write-Output "File saved as: $fPath\ADUser-Export_$userName.csv"
  56.             Start-Sleep -s $waitDuration
  57.           }
  58.          
  59.         }
  60.  
  61.     "2" {
  62.           clear
  63.           Write-Output "Exporting AD Users to CSV"
  64.  
  65.           Get-ADUser -Filter * -Properties MemberOf, LastLogonDate, LastBadPasswordAttempt | export-csv "$fPath\FullAD-Export.csv"
  66.           Write-Output "File saved as: $fPath\FullAD-Export.csv"
  67.           Start-Sleep -s $waitDuration
  68.  
  69.         }
  70.  
  71.  
  72.  
  73.     "3" {
  74.             $userName = read-host -prompt "Enter Username to Unlock"
  75.             Unlock-ADAccount -Identity $userName
  76.             Write-Output "User Account $userName has been unlocked!"
  77.             Start-Sleep -s $waitDuration
  78.         }
  79.  
  80.    
  81.     "4" {
  82.        Do{
  83.         Do{
  84.          clear
  85.          Write-Output "-------------- Settings ------------------
  86.          
  87.             1 = Set Domain
  88.             2 = Set Output File Path
  89.             3 = Main Menu
  90.             "      
  91.         Write-host "  Selected Domain:"$domain -fore "Yellow" -back "black"
  92.         Write-host "  File Path:"$fPath -fore "Yellow" -back "black"
  93.         Write-host "------------------------------------------"
  94.  
  95.          $m2Choice = read-host -prompt "Select a setup option and press Enter"
  96.          } until($m2Choice -eq "1" -or $m2Choice -eq "2" -or $m2Choice -eq "3")
  97.        
  98.          Switch($m2Choice){
  99.  
  100.           "1" {
  101.                   $domain = read-host -prompt "Enter Domain (ie. contoso.local) "
  102.               }
  103.  
  104.           "2" {
  105.                   $fPath = read-host -prompt "Enter File Path Do not include trailing '\' (ie. C:\output) "
  106.               }
  107.                      
  108.           "3" {
  109.                 $setExit=1
  110.               }        
  111.        
  112.        
  113.           }
  114.        } while($setExit -ne 1)
  115.     }
  116.        
  117.  
  118.            
  119.     "99" {
  120.             Write-Output "Exiting"
  121.          
  122.             #clear out the vars
  123.             Remove-Variable fPath
  124.             Remove-Variable userName
  125.             Remove-Variable domain
  126.             Remove-Variable finish
  127.             Remove-Variable end
  128.             Remove-Variable setexit
  129.             Remove-Variable c
  130.             $end = 1
  131.             break OuterLoop
  132.         }
  133.    }
  134.  
  135. #End OuterLoop
  136. } while ($end -ne 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement