Difference between revisions of "Quest powershell to create a batch of users"
From MyWiki
(19 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<source lang="powershell"> | <source lang="powershell"> | ||
− | New-QADUser -name 'psych001' -ParentContainer 'OU=Visitors_and_Guests,OU= | + | 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!' | set-qaduser psych001 -UserPassword 'Banana5454!' | ||
+ | ## Some assorted notes below | ||
− | $myArray = "Banana","Carrot","Pineapple","Cabbage","Turnip","Cauliflower","Beetroot","Celery","Potato","Mushroom","Onion" | + | ## 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 1 -maximum 101 | ||
− | ($a = "Dasher","Dancer","Prancer","Vixen","Comet","Cupid","Donder","Blitzen" ) | Get-Random | + | Get-Random -minimum 100000 -maximum 999999 |
− | Get-Random -input "Dasher","Dancer","Prancer","Vixen","Comet","Cupid","Donder","Blitzen" | + | |
− | ($a = "Dasher","Dancer","Prancer","Vixen","Comet","Cupid","Donder","Blitzen" ) | Get-Random -count 3 | + | ## Variations |
− | Get-Content C:\Scripts\Test.txt | Get-Random | + | ($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 ? | ||
+ | </source> | ||
+ | |||
+ | Generate a 6 digit random number with a random character replaced by exclamation mark. | ||
+ | <source lang="powershell"> | ||
+ | $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 | ||
+ | |||
+ | </source> | ||
+ | '''Complete script to generate random passwords like the following'''<br> | ||
+ | Onion7!9065<br> | ||
+ | Cabbage!71544<br> | ||
+ | Onion4571!7<br> | ||
+ | Scorpio11!427<br> | ||
+ | Cygnus9481!2<br> | ||
+ | Mushroom15!584<br> | ||
+ | Turnip!96236<br> | ||
+ | Pineapple997!08<br> | ||
+ | |||
+ | <source lang="powershell"> | ||
+ | $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 | ||
+ | |||
</source> | </source> |
Latest revision as of 14:09, 9 February 2015
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