Thursday, April 30, 2015

Using PowerShell to Create Sample AD and MIM Users

OK this blog post is just for me because I expect to have to do this a lot in the coming months as we see more exciting stuff with MIM 2016, and I often read my own blog to retrieve script snippets.

This little snippet creates an Active Directory user object, and the corresponding MIM person object.  This is handy if you just want to get the user into MIM with enough detail on the object for them to be able to logon and view the MIM Portal.

ipmo ActiveDirectory

asnp FimAutomation

ipmo FimPowerShellModule


### Create a SecureString for the AccountPassword

$newPassword = ConvertTo-SecureString 'HoofHearted?Icemelted.' -AsPlainText -Force


### Use a CSV string for the sample user data






'@ |

ConvertFrom-Csv |

ForEach-Object {

    ### Construct a couple of strings

    $AccountName = "$($_.FirstName)$($_.LastName)"

    $DisplayName = "$($_.FirstName) $($_.LastName)"


    ### Create the AD User

    New-ADUser -Name $AccountName -GivenName $_.FirstName -Surname $_.LastName -SamAccountName $AccountName -DisplayName $DisplayName -Enabled $true -AccountPassword $newPassword


    ### Create the MIM Person

    New-FimImportObject -ObjectType Person -State Create -Changes @{

       DisplayName  = $DisplayName

       AccountName  = $AccountName

       FirstName    = $_.FirstName

       Description  = 'Have any grapes?'

       EmployeeType = 'Contractor'

       LastName     = $_.LastName

       JobTitle     = $_.JobTitle

       Domain       = 'LITWARE'

       Email        = "$"

       ObjectSID    = (Get-ObjectSid -AccountName $AccountName)

    } -ApplyNow




No comments: