Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Because reasons
- clear
- Write-Host "======= Organizational Structure Creation Script ======="
- # Run Script
- Script
- # Main
- function Script
- {
- $OU = GetOrganizationalUnits
- CreateOrganizationalUnits($OU)
- }
- # Gets and verifies Organizational Unit input
- function GetOrganizationalUnits
- {
- #Loop until input is satisfying all requirements
- do
- {
- try
- {
- Write-Host "Insert names of Organizational Units to create - Separate by a comma if multiple (Defaults to Odense, Horsens and Skive if empty)"
- $OrganizationalUnits = Read-Host
- # Set to defaults if blank input
- if(!$OrganizationalUnits)
- {
- $OrganizationalUnits = "Odense,Horsens,Skive"
- }
- # Verify that first character is a letter
- elseif($OrganizationalUnits[0] -notMatch "^[a-zA-Z]*$")
- {
- throw
- }
- # Verify that string does not contain any special characters that aren't allowed
- elseif($OrganizationalUnits -notMatch "^[a-zA-Z0-9,_-]*$")
- {
- throw
- }
- }
- catch
- {
- Write-Host "Input has to start with a letter and may have numbers, dashes and underscores - Commas are separators" -foreground "Red"
- #Reset variable so loop doesn't break.
- $OrganizationalUnits = ""
- continue
- }
- }
- until($OrganizationalUnits)
- #Return value
- return $OrganizationalUnits
- }
- # Checks and creates requested Organizational Units if they don't already exist
- function CreateOrganizationalUnits($Units) {
- Write-Host "We made it here bois"
- Write-Host "Our OUs are" $Units
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement