Quest powershell to create a batch of users

From MyWiki
Revision as of 14:09, 9 February 2015 by George2 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
New-QADUser -name 'psych001' -ParentContainer 'OU=Visitors_and_Guests,OU=Boldsmiths_Users,DC=camping,DC=boldsmiths,DC=ac,DC=uk' -samAccountName 'psych001' -UserPassword 'Banana5454!' -Description "Job 87241 in IT Services" -UserPrincipalName "psych001@campus.goldsmiths.ac.uk"
set-qaduser psych001 -UserPassword 'Banana5454!'
 
 
## Some assorted notes below
 
## Creating an array
$myArray = "Banana","Carrot","Pineapple","Cabbage","Turnip","Cauliflower","Beetroot","Celery","Potato","Mushroom","Onion","Jupiter","Scorpio","Andromeda","Andromeda","Capricorn","Centaurus","Cygnus","Phoenix"
 
## Generating a random number
Get-Random -minimum 1 -maximum 101
Get-Random -minimum 100000 -maximum 999999
 
## Variations
($a = "Dasher","Dancer","Prancer","Vixen","Comet","Cupid","Donder","Blitzen" ) | Get-Random   ## Select a random name
Get-Random -input "Dasher","Dancer","Prancer","Vixen","Comet","Cupid","Donder","Blitzen"     ## Select a random name
($a = "Dasher","Dancer","Prancer","Vixen","Comet","Cupid","Donder","Blitzen" ) | Get-Random -count 3  ## Select multiple 
Get-Content C:\Scripts\Test.txt | Get-Random    ## Select a random line ?
Get-ChildItem C:\Scripts | Get-Random -count 3   ## Select a random file name ?

Generate a 6 digit random number with a random character replaced by exclamation mark.

$random1_to_6 =  Get-Random -minimum 1 -maximum 6  ## to generate the numberical characters
$random_main =  Get-Random -minimum 100000 -maximum 999999  ## to generate the main numerical part
 
$temp="$random_main"       # convert integer to string
$random_main = $temp
 
# subract 1 from $random1_to_6 to get the length of first string
$first_length= $random1_to_6 - 1
# There will be two strings to concatenate with a "!" between them
$first_string = $random_main.substring(1,$first_length)
 
$second_string = $random_main.substring($random1_to_6)
$final_string = $first_string + "!" + $second_string
 
 
Write-Host $final_string

Complete script to generate random passwords like the following
Onion7!9065
Cabbage!71544
Onion4571!7
Scorpio11!427
Cygnus9481!2
Mushroom15!584
Turnip!96236
Pineapple997!08

$myArray="Banana","Carrot","Pineapple","Cabbage","Turnip","Cauliflower","Beetroot","Celery","Potato","Mushroom","Onion","Jupiter","Scorpio","Andromeda","Andromeda","Capricorn","Centaurus","Cygnus","Phoenix"
$random_word = Get-Random $myArray
 
$random1_to_6 =  Get-Random -minimum 1 -maximum 6  ## to generate the numberical characters
$random_main =  Get-Random -minimum 100000 -maximum 999999  ## to generate the main numerical part
 
$temp="$random_main"       # convert integer to string
$random_main = $temp
 
# subract 1 from $random1_to_6 to get the length of first string
$first_length= $random1_to_6 - 1
# There will be two strings to concatenate with a "!" between them
$first_string = $random_main.substring(1,$first_length)
 
$second_string = $random_main.substring($random1_to_6)
$final_string = $random_word + $first_string + "!" + $second_string
 
 
Write-Host $final_string