It takes the account created by OIM and passes 2 fields 2 my script and my script enables the mailbox, sets notes and such, then creates an O drive for the user. You might not need this exact functionality but hopefully if you need any of these things you can use my script to help you.
PARAM ($Argument1,$Argument2)
function Set-WindowsInfomation ($UserPrincipalName, $Location){
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
Import-Module ActiveDirectory
$cluster = ""
$attribute = ""
$server = ""
$Group = ""
$networkserver = ""
$networkdrive = ""
$networkfolder = ""
$w2k = ""
$domainname = ""
$Date = date
switch -wildcard ($Location)
{
"LOCATION1"
{
$cluster = "LOC1MBCluster"
New-PSDrive -Name LOC1DOMAIN -PSProvider ActiveDirectory -root 'DC=location1,DC=local' -server DC1.location1.local
$server = "DC1"
$Group = "Location1 users"
$attribute = "Location 1"
$networkserver = "FILESERVER1"
$networkdrive = "D"
$networkfolder = "Users"
$w2k = "LOCATION1"
$domainname = "location1.local"
; break
}
"LOCATION2"
{
$cluster = "LOC2MBCluster"
New-PSDrive -Name LOC2DOMAIN -PSProvider ActiveDirectory -root 'DC=location2,DC=local' -server DC2.location2.local
$server = "DC2"
$Group = "Location2 users"
$attribute = "Location 2"
$networkserver = "FILESERVER2"
$networkdrive = "D"
$networkfolder = "Users"
$w2k = "LOCATION2"
$domainname = "location2.local"
; break
}
"FIELDLOC1*"
{
$cluster = "LOC1MBCluster"
New-PSDrive -Name LOC1DOMAIN -PSProvider ActiveDirectory -root 'DC=location1,DC=local' -server DC1.location1.local
$server = "DC1"
$Group = "Location1 users"
$attribute = "Location 1"
$attribute2 = "Remote"
$networkserver = "FILESERVER1"
$networkdrive = "D"
$networkfolder = "Users"
$w2k = "LOCATION1"
$domainname = "location1.local"
$field = "On"
; break
}
Default
{
$cluster = "LOC1MBCluster"
New-PSDrive -Name LOC1DOMAIN -PSProvider ActiveDirectory -root 'DC=location1,DC=local' -server DC1.location1.local
$server = "DC1"
$Group = "Location1 users"
$attribute = "Location 1"
$networkserver = "FILESERVER1"
$networkdrive = "D"
$networkfolder = "Users"
$w2k = "LOCATION1"
$domainname = "location1.local"
}
}
$LeastBusyDB = (Get-Mailbox -Server $cluster -Resultsize Unlimited | ?{$_.database -notmatch 'RSG'} | Group-Object -Property:Database | Select-Object Name,Count | Sort-Object count | select -first 1 -expand name)
Enable-Mailbox -Identity $UserPrincipalName -Database $LeastBusyDB -ManagedFolderMailboxPolicy CleanDeletedItems60Days -ManagedFolderMailboxPolicyAllowed
Start-Sleep -s 30
Set-Mailbox -Identity $UserPrincipalName -CustomAttribute1 $attribute -CustomAttribute2 $attribute2
Start-Sleep -s 20
Set-User -Identity $UserPrincipalName -Notes "Account created on $Date by OIM" -Company "Your Corporate Name"
$alias = Get-Mailbox $UserPrincipalName | Select Alias
if ($Group -ne "")
{
Add-ADGroupMember $Group $alias.alias -Server $server -Confirm:$false
}
if($field -ne "On"){
$sharename = $alias.alias + "$"
$rawalias = $alias.alias
$userdrive = "$networkdrive" + ":\$networkfolder\$rawalias"
New-Item -Path "\\$networkserver\$networkdrive$\$networkfolder\$rawalias" -type directory | Out-Null
(Get-WmiObject -List -ComputerName $networkserver | Where-Object -FilterScript {$_.Name -eq "Win32_Share"}).InvokeMethod("Create",("$userdrive","$sharename",0,16777216,"Created by OIM"))
$GetACL = Get-Acl "\\$networkserver\$networkdrive$\$networkfolder\$rawalias"
$Allinherit = [system.security.accesscontrol.InheritanceFlags]'ContainerInherit, ObjectInherit'
$Allpropagation = [system.security.accesscontrol.PropagationFlags]'None'
$AccessRule = New-Object system.security.AccessControl.FileSystemAccessRule("$w2k\$rawalias", "Modify", $AllInherit, $Allpropagation, 'Allow')
$GetACL.AddAccessRule($AccessRule)
Set-Acl -aclobject $GetACL -Path "\\$networkserver\$networkdrive$\$networkfolder\$rawalias"
Start-Sleep -s 30
set-Sharepermissions -share "$sharename" -server "$networkserver" -user "$rawalias" -Domain "$domainname" -mode "Change"
Set-ADuser -Identity $rawalias -ScriptPath "kix32.exe"
}
}
Function set-Sharepermissions ($share,$server,$user,$Domain,$mode) {
$sd = (new-object management.managementclass Win32_SecurityDescriptor).CreateInstance()
$ace = (new-object management.managementclass Win32_ace).CreateInstance()
$Trustee = (new-object management.managementclass win32_trustee).CreateInstance()
$Account = new-object system.security.principal.NtAccount($user)
$SID = $Account.translate([system.security.principal.securityidentifier])
$Trustee.Domain = $Domain
$Trustee.Name = $user
$Trustee.SIDString = $sid.Value
switch ($mode)
{
"Full" {$ace.AccessMask = 2032127}
"Change" {$ace.AccessMask = 1245631}
"Read" {$ace.AccessMask = 1179817}
}
$ace.AceType = 0
$ace.AceFlags = 3
$ace.trustee = $trustee
$SD.DACL = @($ACE.psobject.baseObject)
$share = get-wmiObject -ComputerName $server win32_share -filter "name='$share'"
$inparams = $share.GetMethodParameters("setShareInfo")
$inParams["Access"] = $SD.psobject.baseObject
$inParams["Description"] = "Created by OIM on $Date"
$share.invokemethod("setshareInfo",$inparams,$null)
}