Advertisement
Lee_Dailey

WhatTheHomePod_-_error_line_91

Aug 16th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #INPUT PROMPTS
  2.  
  3. $Firstname   = Read-Host 'Firstname'
  4. $Lastname    = Read-Host 'Lastname'
  5. $initials    = Read-Host 'Initials (please use periods for example - J.A.)'
  6. $UserID      = Read-Host 'UserID'
  7. $department  = Read-Host 'Department'
  8. $title       = Read-Host 'Title'
  9. $description = Read-Host 'Employee ID'
  10. $tstnr     = Read-Host 'Office Phone'
  11. $CopyFromUser = Read-Host 'Copy rights from to (if not - push on enter)'
  12. $OUPath      = Read-Host 'Intern or Extern'
  13.  
  14.  
  15.  
  16. function New-DisplayName
  17.     {
  18.  
  19.     <#
  20.     CBH [Comment Based Help] goes here
  21.     #>
  22.  
  23.     [CmdletBinding ()]
  24.     Param
  25.         (
  26.         [Parameter (
  27.             Mandatory,
  28.             Position = 0
  29.             )]
  30.             [string]
  31.             $FirstName,
  32.  
  33.         [Parameter (
  34.             Mandatory,
  35.             Position = 1
  36.             )]
  37.             [string]
  38.             $LastName
  39.  
  40.         )
  41.  
  42.     begin {}
  43.  
  44.     process
  45.         {
  46.         $SplitLName = $LastName.Split(' ')
  47.         $PartOne = $SplitLName[-1]
  48.         $PartTwo = $FirstName[0]
  49.  
  50.         if ($SplitLName.Count -gt 1)
  51.             {
  52.             $PartThree = $SplitLName[0..($SplitLName.Count - 2)] -join ' '
  53.  
  54.             '{0}, {1}. {2} ({3})' -f $PartOne, $PartTwo, $PartThree, $FirstName
  55.             }
  56.             else
  57.             {
  58.             '{0}, {1}. ({2})' -f $PartOne, $PartTwo, $FirstName
  59.             }
  60.  
  61.         }
  62.  
  63.     end {}
  64.  
  65.     } # end >> function New-DisplayName
  66.  
  67. #USED FOR OUPATH
  68. $OUPathValidate = $true
  69. While ($OUPathValidate) {
  70.     If ($OUPath.ToUpper() -eq 'Intern') {
  71.         $OUPath = 'OU=Intern,OU=Users,OU=ZERO,DC=int,DC=rpz,DC=nl'
  72.         $OUPathValidate = $false
  73.     } ElseIf ($OUPath.ToUpper() -eq 'Extern') {
  74.         $OUPath = 'OU=Extern,OU=Users,OU=ZERO,DC=int,DC=rpz,DC=nl'
  75.         $OUPathValidate = $false
  76.     } Else {
  77.         Write-Host 'Unknown value - User Intern or Extern'
  78.     }
  79. }
  80.  
  81. # check if the user ID exists in AD
  82. if (Get-ADUser -Filter { SamAccountName -eq $UserID })
  83. {
  84.     # if it exists, create a loop and get the first free name with a number behind, starting at 2
  85.     $userNotFound = $true
  86.     $count = 1
  87.     while($userNotFound -eq $true)
  88.     {
  89.         $count++
  90.         # create a temporary variable with the new name to check with
  91.         $tempID = "$userid$count"
  92.         if (-not (Get-ADUser -Filter { SamAccountName -eq $tempID }))
  93.         {
  94.             $userNotFound = $false
  95.         }
  96.     }
  97.     # set the user ID to the new name
  98.     $UserID = "$($UserID)$count"
  99. }
  100.  
  101. #STATIC VARIABLES
  102. $Password     = (ConvertTo-SecureString -AsPlainText 'ZERO' -Force)
  103. $company      = 'ZERO'
  104. $Displayname = New-DisplayName -FirstName $FirstName -LastName $LastName
  105. $profilePath  = "\\int.ZERO.nl\Users\Profiles\$UserID"
  106. $OfficePhone  = $tstnr
  107. $aliasid      = $UserID.Insert(1,'.')
  108.  
  109.  
  110. #USED TO ADD PARAMETERS
  111. $Parameters = @{
  112.     'SamAccountName'        = $UserID
  113.     'UserPrincipalName'     = $UserID
  114.     'Name'                  = "$Firstname $Lastname"
  115.     'GivenName'             = $Firstname
  116.     'Surname'               = $Lastname
  117.     'DisplayName'           = $Displayname
  118.     'AccountPassword'       = $password
  119.     'ChangePasswordAtLogon' = $true
  120.     'Enabled'               = $true
  121.     'Path'                  = $OUPath
  122.     'company'               = $company
  123.     'department'            = $department
  124.     'description'           = $description
  125.     'title'                 = $title
  126.     'profilePath'           = $profilePath
  127.     'OfficePhone'           = $OfficePhone
  128.     'initials'              = $initials
  129.  
  130. }
  131.  
  132. "Username = $UserID"
  133. New-ADUser @Parameters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement