Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############ New User (Canada) Automation ###########
- cls
- Set-ExecutionPolicy unrestricted -force
- #import active directory and group policy modules
- Import-Module activedirectory
- Import-Module grouppolicy
- cd ad:
- cd \
- #variables
- $redtemp = '\\yyzpr01\c$\Users\bparks\Desktop\_RTemplate'
- $userred = '\\yyzpr01\redirects'
- $gpobuid = '248F236C-9E9A-48FB-8B83-94FAE8DDC7A1'
- $gpotemp = '_templatecompanygpo'
- $gpocopy = "c:\users\bparks\desktop"
- $gpodrives = 'C:\Users\bparks\Desktop\{248F236C-9E9A-48FB-8B83-94FAE8DDC7A1}\DomainSysvol\GPO\User\Preferences\Drives\Drives.xml'
- [xml]$gpoxml = Get-Content "C:\users\bparks\desktop\drives.xml"
- $userarray = New-Object system.collections.arraylist
- $qbavail = "yyzxaqbent0??"
- $qbserver = $null
- $qbnum = $null
- $qbflav = $null
- $qbou = 'OU=QuickBooks,OU=CitrixApps7.8,OU=SecurityGroups,DC=canada,DC=local'
- $adobe = 'ctxdgappadobereader'
- $excel = 'ctxdgappexcelviewer'
- $fileex = 'ctxdgappfileexplorer'
- $word = 'ctxdgappwordviewer'
- $apparray = $adobe, $excel, $fileex, $word
- $rootou = 'OU=CitrixUsers7.8,OU=Accounts,DC=canada,DC=local'
- #functions
- function CreateRedirect
- {
- Copy-Item -Path $redtemp -Recurse -Destination "$($userred)\$($userarray[0])"
- icacls ("$($userred)\$($userarray[0])") /grant ("$($userarray[0])" + ':(OI)(CI)F') /t
- $prodcode = Read-Host "Enter Product Code: "
- $licnum = Read-Host "Enter License Number: "
- (Get-Content "$($userred)\$($userarray[0])\Redirect\quickbooks\qblic\enterprise\qbregistration.dat") | ForEach-Object {$_ -replace "2016$($qbflav)-ID", "$($prodcode)"} | Set-Content "$($userred)\$($userarray[0])\Redirect\quickbooks\qblic\enterprise\qbregistration.dat"
- (Get-Content "$($userred)\$($userarray[0])\Redirect\quickbooks\qblic\enterprise\qbregistration.dat") | ForEach-Object {$_ -replace "2016$($qbflav)-KEY", "$($licnum)"} | Set-Content "$($userred)\$($userarray[0])\Redirect\quickbooks\qblic\enterprise\qbregistration.dat"
- Copy-Item -Path "$($qbnum)\c$\ProgramData\Intuit\Entitlement Client\v8.orig" -Recurse -Destination "$($userred)\$($userarray[0])\Redirect\quickbooks\qblic\entitlementclient\v8"
- Write-Host "Please log in and activate QB on the first user" | cmd /c pause
- foreach($user in $userarray)
- {
- if ($user -eq $userarray[0])
- {
- continue
- }
- Copy-Item -Path "$($userred)\$($userarray[0])" -Recurse -Destination "$($userred)\$($user)"
- icacls ("$($userred)\$($user)") /grant ("$($user)"+ ':(OI)(CI)f') /t
- }
- }
- function CreateGPO
- {
- Copy-GPO -SourceName $gpotemp -TargetName "Company$($ou)GPO"
- New-GPLink -Name "Company$($ou)GPO" -Target "ou=$($ou),ou=citrixusers7.8,ou=accounts,dc=canada,dc=local"
- $gpoxml.Drives.Drive.Properties.path = "\\$($qbnum)\qbw\$($ou)"
- $poxml.Drives.Drive.Filters.FilterGroup.sid = $ou.sid
- $gpoxml.Drives.Drive.Filters.FilterGroup.name = "CANADA\$($ou)"
- $gpoxml.save($gpodrives)
- Import-GPO -BackupId $gpobuid -Path $gpocopy -TargetName "Company$($ou)GPO"
- CreateRedirect
- }
- function CreateQ
- {
- cd c:
- New-Item -Path "\\$qbnum\qbw\" -Name $ou -ItemType 'directory'
- New-Item -Path "\\$qbnum\qbw\$ou" -Name 'QBBackup' -ItemType 'directory'
- New-Item -Path "\\$qbnum\qbw\$ou" -Name 'test.qbw' -ItemType 'file'
- icacls ("\\$qbnum\qbw\$ou") /grant ("$ou"+ ':(OI)(CI)M') /t
- CreateGPO
- }
- function CreateUser
- {
- $numusers = Read-Host "Enter the number of users: "
- for($i=1; $i -le $numusers; $i++)
- {
- $username = Read-Host "Enter username: "
- $userarray.Add($username)
- New-ADUser -Name $username -AccountExpirationDate $null -PasswordNeverExpires $true -AccountPassword (Read-Host -AsSecureString "Enter Password: ") -Enabled $true -UserPrincipalName "$($username).canada.local"
- Add-ADGroupMember -Identity $ou -Members $username
- }
- CreateQ
- }
- function CreateGroup
- {
- cd ou=$ou
- New-ADGroup $ou -GroupScope global
- foreach($i in $apparray)
- {
- Add-ADGroupMember -Identity $i -Members $ou
- }
- While($true)
- {
- $qbnum = Read-Host "Enter Server: "
- if ($qbnum -notmatch $qbavail)
- {
- Write-Host "Server does not match any avaiable servers. Please try again."
- }
- else
- {
- While ($true)
- {
- $qbflav = Read-Host "Please enter the flavor (i.e. EAE): "
- if ($qbflav -notmatch '/?/?/?')
- {
- Write-Host "Please enter valid flavor."
- }
- else
- {
- Get-ADGroup -Filter * -SearchBase $qbou| Where {$_.name -match $qbnum -and $_.name -match $qbflav} | Add-ADGroupMember -Members $ou
- CreateUser
- break
- }
- }
- break
- }
- }
- }
- function CreateOU
- {
- cd $rootou
- New-ADOrganizationalUnit $ou
- CreateGroup
- }
- #Script Starts Here
- $ou = Read-Host "Enter Organizational Unit/Group Name: "
- CreateOU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement