Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############ New User (Canada) Automation ###########
  2.  
  3. cls
  4.  
  5. Set-ExecutionPolicy unrestricted -force
  6.  
  7.  
  8. #import active directory and group policy modules
  9. Import-Module activedirectory
  10. Import-Module grouppolicy
  11. cd ad:
  12. cd \
  13.  
  14. #variables
  15. $redtemp = '\\yyzpr01\c$\Users\bparks\Desktop\_RTemplate'
  16. $userred = '\\yyzpr01\redirects'
  17.  
  18. $gpobuid = '248F236C-9E9A-48FB-8B83-94FAE8DDC7A1'
  19. $gpotemp = '_templatecompanygpo'
  20. $gpocopy = "c:\users\bparks\desktop"
  21. $gpodrives = 'C:\Users\bparks\Desktop\{248F236C-9E9A-48FB-8B83-94FAE8DDC7A1}\DomainSysvol\GPO\User\Preferences\Drives\Drives.xml'
  22. [xml]$gpoxml = Get-Content "C:\users\bparks\desktop\drives.xml"
  23.  
  24. $userarray = New-Object system.collections.arraylist
  25.  
  26. $qbavail = "yyzxaqbent0??"
  27. $qbserver = $null
  28. $qbnum = $null
  29. $qbflav = $null
  30.  
  31. $qbou = 'OU=QuickBooks,OU=CitrixApps7.8,OU=SecurityGroups,DC=canada,DC=local'
  32.  
  33. $adobe = 'ctxdgappadobereader'
  34. $excel = 'ctxdgappexcelviewer'
  35. $fileex = 'ctxdgappfileexplorer'
  36. $word = 'ctxdgappwordviewer'
  37. $apparray = $adobe, $excel, $fileex, $word
  38.  
  39. $rootou = 'OU=CitrixUsers7.8,OU=Accounts,DC=canada,DC=local'
  40.  
  41. #functions
  42. function CreateRedirect
  43. {
  44.     Copy-Item -Path $redtemp -Recurse -Destination "$($userred)\$($userarray[0])"
  45.    
  46.     icacls ("$($userred)\$($userarray[0])") /grant ("$($userarray[0])" + ':(OI)(CI)F') /t  
  47.    
  48.     $prodcode = Read-Host "Enter Product Code: "
  49.    
  50.     $licnum = Read-Host "Enter License Number: "
  51.    
  52.     (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"
  53.     (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"
  54.  
  55.     Copy-Item -Path "$($qbnum)\c$\ProgramData\Intuit\Entitlement Client\v8.orig" -Recurse -Destination "$($userred)\$($userarray[0])\Redirect\quickbooks\qblic\entitlementclient\v8"
  56.  
  57.     Write-Host "Please log in and activate QB on the first user" | cmd /c pause
  58.    
  59.     foreach($user in $userarray)
  60.     {
  61.         if ($user -eq $userarray[0])
  62.         {
  63.             continue
  64.         }
  65.        
  66.         Copy-Item -Path "$($userred)\$($userarray[0])" -Recurse -Destination "$($userred)\$($user)"
  67.        
  68.         icacls ("$($userred)\$($user)") /grant ("$($user)"+ ':(OI)(CI)f') /t
  69.        
  70.     }      
  71. }
  72.  
  73. function CreateGPO
  74. {
  75.     Copy-GPO -SourceName $gpotemp -TargetName "Company$($ou)GPO"
  76.    
  77.     New-GPLink -Name "Company$($ou)GPO" -Target "ou=$($ou),ou=citrixusers7.8,ou=accounts,dc=canada,dc=local"
  78.    
  79.     $gpoxml.Drives.Drive.Properties.path = "\\$($qbnum)\qbw\$($ou)"
  80.    
  81.     $poxml.Drives.Drive.Filters.FilterGroup.sid = $ou.sid
  82.    
  83.     $gpoxml.Drives.Drive.Filters.FilterGroup.name = "CANADA\$($ou)"
  84.    
  85.     $gpoxml.save($gpodrives)
  86.    
  87.     Import-GPO -BackupId $gpobuid -Path $gpocopy -TargetName "Company$($ou)GPO"
  88.    
  89.     CreateRedirect
  90. }
  91.  
  92. function CreateQ
  93. {
  94.     cd c:
  95.    
  96.     New-Item -Path "\\$qbnum\qbw\" -Name $ou -ItemType 'directory'
  97.     New-Item -Path "\\$qbnum\qbw\$ou" -Name 'QBBackup' -ItemType 'directory'
  98.     New-Item -Path "\\$qbnum\qbw\$ou" -Name 'test.qbw' -ItemType 'file'
  99.    
  100.     icacls ("\\$qbnum\qbw\$ou") /grant ("$ou"+ ':(OI)(CI)M') /t    
  101.    
  102.     CreateGPO
  103. }
  104.  
  105. function CreateUser
  106. {
  107.     $numusers = Read-Host "Enter the number of users: "
  108.    
  109.     for($i=1; $i -le $numusers; $i++)
  110.     {
  111.         $username = Read-Host "Enter username: "
  112.        
  113.         $userarray.Add($username)
  114.        
  115.         New-ADUser -Name $username -AccountExpirationDate $null -PasswordNeverExpires $true -AccountPassword (Read-Host -AsSecureString "Enter Password: ") -Enabled $true -UserPrincipalName "$($username).canada.local"
  116.        
  117.         Add-ADGroupMember -Identity $ou -Members $username
  118.     }
  119.    
  120.     CreateQ
  121. }
  122.  
  123. function CreateGroup
  124. {
  125.     cd ou=$ou
  126.  
  127.     New-ADGroup $ou -GroupScope global
  128.    
  129.     foreach($i in $apparray)
  130.     {
  131.         Add-ADGroupMember -Identity $i -Members $ou      
  132.     }
  133.    
  134.     While($true)
  135.     {    
  136.         $qbnum = Read-Host "Enter Server: "
  137.        
  138.         if ($qbnum -notmatch $qbavail)
  139.         {
  140.             Write-Host "Server does not match any avaiable servers.  Please try again."
  141.         }
  142.         else
  143.         {
  144.             While ($true)
  145.             {
  146.                 $qbflav = Read-Host "Please enter the flavor (i.e. EAE): "
  147.            
  148.                 if ($qbflav -notmatch '/?/?/?')
  149.                 {
  150.                     Write-Host "Please enter valid flavor."
  151.                 }
  152.                 else
  153.                 {
  154.                     Get-ADGroup -Filter * -SearchBase $qbou| Where {$_.name -match $qbnum -and $_.name -match $qbflav} | Add-ADGroupMember -Members $ou
  155.                     CreateUser
  156.                     break
  157.                 }
  158.             }
  159.             break
  160.         }
  161.     }
  162. }
  163.  
  164. function CreateOU
  165. {
  166.   cd  $rootou
  167.   New-ADOrganizationalUnit $ou
  168.  
  169.  CreateGroup    
  170. }
  171.  
  172. #Script Starts Here
  173.  
  174. $ou = Read-Host "Enter Organizational Unit/Group Name: "
  175.  
  176. CreateOU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement