WordPress.com



$ErrorActionPreference = "Stop"c:\windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe `-NonInteractive -Command {$Firstname = 'Input firstname Here'$Lastname = 'Input lastname Here'$Type = 'Input Type Here'if($Type -eq 'PC'){$Type = '_PC'}else{$Type = ''}$Manager = 'Input Manager Here'$Phone = 'Input Phone here'$Title = 'Input Title Here'$Department = 'Input Department Here'$Company = 'Input Company Here'if($Company -eq 'Test1'){$Office = 'Office 1'$Country = 'SE'$City = 'City 1'$Street = 'Street 1'$State = 'State 1'$Zip = '12345'$tempuser = 'Template Test'}ElseIf($Company -eq 'Test2') {$Office = 'Office 2'$Country = 'GB'$City = 'City 1'$Street = 'Street 2'$State = 'State 2'$Zip = '12345'$tempuser = 'Template Test'}Else{$Company = 'Test3'$Office = 'Office 3'$Country = 'SE'$City = 'City 3'$Street = 'Street 3'$State = 'State 3'$Zip = '12345'$tempuser = 'Template Test'}# Password must be read from Console as Secure String to be applied. If you're manipulate this to a Batch User process, you can use this one password as a default. The Exchange New-Mailbox has the "Change Password at login" enabled by default $TempPassword = ConvertTo-SecureString "Input Password from Generate Password" -AsPlainText -Force# SAM name will appear as Company + first 2 letters of firstname and 2 first letters in lastname # $FirstName = $Firstname.Text.Substring(0,1).ToUpper()+$Firstname.Text.Substring(1,$Firstname.Text.Length-1).ToLower()# $LastName = $Lastname.Text.Substring(0,1).ToUpper()+$Lastname.Text.Substring(1,$Lastname.Text.Length-1).ToLower() $Sam=$Company+""+$FirstName.Substring(0,2).ToUpper()+$LastName.Substring(0,2).ToUpper()$max=$Sam.Length # Format firstname and lastname to always be first letter capital and rest lowercase#The SAM account cannot be greater than 20 characters. You have to account for this. A better functionn would stop query and say "Too big stupid" but this is my first time out if ($max -gt 20) {$max=20} $Sam=$Sam.Substring(0,$max) # This is handy if your organization must have the names listed by Lastname, Firstname. Exchange 2007 cannot do this natively (as least not that I have found) $Name=$Lastname+" "+$FirstName $DisplayName=$Lastname+" "+$FirstName# User Alias Displaying as Firstname.Lastname $Alias=$Sam # UPN will be your internal login ID. Typically Alias@domain.local or Username@ $UPN=$Sam+"@labb.local" # UNC Pathname to a share where all user folders reside. Path must exist. Recommend adding $ to sharename to hide from User Browsing $HomeDir='\\labbcon\vol2$\Konfig_Citrix\'+$Company+"\"+$Sam# Drive Letter assigned to H:$HomeDrive='H:' # Default web site $Web='' # A generic description for the user $Description='User '+$Company# Organizational Unit$Domain='labb.local'$Ou=$Domain+"/"+$Company+"_CTX"+$Type# The ending part of the domain @ @ etc etc $ourdomain='@labb.local' $TSHome='\\labbcon\prof\'+$Sam# This first line is done within the Microsoft Exchange Management Shell from Exchange 2007. I add it's ability to my Powershell with the command add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010New-Mailbox -Name $Name -Alias $Alias -OrganizationalUnit $Ou -UserPrincipalName $UPN -SamAccountName $SAM -FirstName $FirstName -LastName $LastName -Password $TempPassword -ResetPasswordOnNextLogon $false -Database 'Test' # This command l add-pssnapin quest.activeroles.admanagementStart-Sleep -Seconds 5set-qaduser -City $City -StreetAddress $Street -StateOrProvince $State -PostalCode $Zip -Identity $UPN -Office $Office -Manager $Manager -Title $Title -PhoneNumber $Phone -TsRemoteControl 2 -TsHomeDirectory $HomeDir -TsHomeDrive $HomeDrive -TsProfilePath $TSHome -Description $Description -company $Company -webpage $web -displayname $displayname (Get-QADUser $tempuser).MemberOf | Add-QADGroupMember -Member $UPN # Set CountryImport-Module ActiveDirectorySet-ADUser -Identity $Sam -Country $Country# Enable User for Lync# Import-Module Lync# Enable-CsUser -Identity $UPN -RegistrarPool "lablync.labb.local" -SipAddressType FirstLastName -SipDomain labb.local#Make User Home Folder and Apply NTFS permissions$HomeFolderMasterDir='\\labbcon\vol2$\Konfig_Citrix\'+$Company+"\"new-item -path $HomeFolderMasterDir -name $Sam -type directory $Foldername=$HomeFolderMasterDir+$Sam $DomainUser='labb.local\'+$Sam $ACL=Get-acl $Foldername $Ar = New-Object system.security.accesscontrol.filesystemaccessrule($DomainUser,"FullControl","Allow") $Acl.SetAccessRule($Ar) Set-Acl $Foldername $AclCopy-Item \\labbcon\vol2$\Notes -Destination $HomeDir -Recurse} ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download