Advertisement
Guest User

Untitled

a guest
Jan 15th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Because reasons
  2. clear
  3.  
  4. Write-Host "======= Organizational Structure Creation Script ======="
  5.  
  6. # Run Script
  7. Script
  8.  
  9. # Main
  10. function Script
  11. {
  12.     $OU = GetOrganizationalUnits
  13.    
  14.     CreateOrganizationalUnits($OU)
  15. }
  16.  
  17. # Gets and verifies Organizational Unit input
  18. function GetOrganizationalUnits
  19. {
  20.     #Loop until input is satisfying all requirements
  21.     do
  22.     {
  23.         try
  24.         {
  25.             Write-Host "Insert names of Organizational Units to create - Separate by a comma if multiple (Defaults to Odense, Horsens and Skive if empty)"
  26.        
  27.             $OrganizationalUnits = Read-Host
  28.            
  29.             # Set to defaults if blank input
  30.             if(!$OrganizationalUnits)
  31.             {
  32.                 $OrganizationalUnits = "Odense,Horsens,Skive"
  33.             }
  34.             # Verify that first character is a letter
  35.             elseif($OrganizationalUnits[0] -notMatch "^[a-zA-Z]*$")
  36.             {
  37.                 throw
  38.             }
  39.             # Verify that string does not contain any special characters that aren't allowed
  40.             elseif($OrganizationalUnits -notMatch "^[a-zA-Z0-9,_-]*$")
  41.             {
  42.                 throw
  43.             }
  44.         }
  45.         catch
  46.         {
  47.             Write-Host "Input has to start with a letter and may have numbers, dashes and underscores - Commas are separators" -foreground "Red"
  48.             #Reset variable so loop doesn't break.
  49.             $OrganizationalUnits = ""
  50.             continue
  51.         }
  52.     }
  53.     until($OrganizationalUnits)
  54.    
  55.     #Return value
  56.     return $OrganizationalUnits
  57.    
  58. }
  59.  
  60. # Checks and creates requested Organizational Units if they don't already exist
  61. function CreateOrganizationalUnits($Units) {
  62.  
  63.     Write-Host "We made it here bois"
  64.    
  65.     Write-Host "Our OUs are" $Units
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement