Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=============================================passgenerator=====================================================================================================
- Function MakeUp-String([Int]$Size = 8, [Char[]]$CharSets = "ULNS", [Char[]]$Exclude) {
- $Chars = @(); $TokenSet = @()
- If (!$TokenSets) {$Global:TokenSets = @{
- U = [Char[]]'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- L = [Char[]]'abcdefghijklmnopqrstuvwxyz'
- N = [Char[]]'0123456789'
- S = [Char[]]'!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~'
- }}
- $CharSets | ForEach {
- $Tokens = $TokenSets."$_" | ForEach {If ($Exclude -cNotContains $_) {$_}}
- If ($Tokens) {
- $TokensSet += $Tokens
- If ($_ -cle [Char]"Z") {$Chars += $Tokens | Get-Random} #Character sets defined in upper case are mandatory
- }
- }
- While ($Chars.Count -lt $Size) {$Chars += $TokensSet | Get-Random}
- ($Chars | Sort-Object {Get-Random}) -Join "" #Mix the (mandatory) characters and output string
- }; Set-Alias Create-Password MakeUp-String -Description "Generate a random string (password)"
- $randompassword = MakeUp-string
- $rndpass = $randompassword | Out-String
- $pass = ConvertTo-SecureString -string $rndpass -AsPlainText -Force
- #=============================================COLLECT DATA=========================================================================================================
- #$manager = read-Host ("manager")
- #copy properties from first direct report of manager:
- $copy_from = (Get-Aduser -Identity $manager -Properties directreports | Select-Object -ExpandProperty directreports | Get-Aduser -Properties Samaccountname | Select-Object -first 1 | Select-Object -ExpandProperty samaccountname)
- $olduser = get-aduser $copy_from -Properties *
- #$newuserfirstname = read-host ("First Name")
- #$newuserlastname = read-host ("Last Name")
- #$expdate = read-host ("Expiration Date dd.mm.rrrr")
- #test
- $manager = "mtestowy"
- $newuserfirstname = "JOHN"
- $newuserlastname = "DOE"
- $expdate = "31.03.2019"
- $name = "$newuserlastname $newuserfirstname" #create username
- $samaccountname = "$($newuserfirstname[0])$newuserlastname" #create samaccountname
- #todo: check if user exists
- #new user
- $params =@{
- "AccountExpirationDate" = $expdate
- "SamAccountName" = $samaccountname
- "Department" = $olduser.department
- "AccountPassword" = $pass
- #"ChangePasswordAtLogon" = 'Enabled'
- "city" = $olduser.city
- "Company" = $olduser.company
- #"Description" = $olduser.description #nie działa
- "DisplayName" = $name
- #"Enabled" = 'Enabled'
- "GivenName" = $newuserfirstname
- "Manager" = $manager
- "Name" = $name
- "Office" =$olduser.office
- #"PasswordNeverExpires" = 'Disabled'
- #"Path" = $olduser.path #error
- "ScriptPath" = $olduser.scriptpath
- "StreetAddress" = $olduser.streetaddress
- "surname" = $newuserlastname
- "title" = $olduser.title
- }
- #todo: memberof
- New-ADUser @params
- $ErrorActionPreference = "silentlycontinue"
- Set-ADUser -Identity $samaccountname -UserPrincipalName $samaccountname@vectradom.vec
- Set-Aduser -Identity $samaccountname -Replace @{office=$olduser.office; description=$olduser.description}
- #todo: home folder
- #todo: new email
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement