I'M BACK!! It has been way too long but I am back.
I will be posting more scripts that we create and use in the company I work for. They will be mostly GET- scripts against Active Directory, as well as the PowerShell commands we use in our Microsoft Identity Management (MIM) environment.
So, let's get started with a MIM script that we use to look for unique first name and last name within the MIM portal.
As you may or may not know, the MIM portal has PowerShell
version 2.0 embedded in the portal. In
order to use the get-ADuser, you need to be running PowerShell version 3.0. I
was able to find a workaround so that the main script can be executed using PowerShell
3.0.
I created two scripts, the main scripts and the script that
runs inside the activity.
This is the code that is running within the PowerShell activity:
As you can see, the command that starts with $templastname runs the PowerShell command but it runs it under version 3.0. This was how I was able to work around the PowerShell 2.0 limit within the MIM portal.
PARAM(
[parameter(mandatory=$true)]$FirstName
,[parameter(mandatory=$true)]$LastName
)
$tempLastName = powershell -version 3.0 -command "c:\scripts\test_unique_lastname.ps1
$firstName $lastname"
$tempLastName
This is the main script.
#This
makes the variables available to the script.
PARAM(
[parameter(mandatory=$true)]$FirstName
,[parameter(mandatory=$true)]$LastName
)
#This
loads the module in case it isn’t already loaded
import-module activedirectory
#This
sets the counter for
[int]$counter = 2
$tempLastName = $LastName
#This command looks for an account that contains the first name and last name similar to what was entered in the portal
$results = get-aduser -filter * -properties * | where-object {$_.givenName
-eq $FirstName -and $_.sn -like $tempLastName} | select-object givenname,sn | Measure-object
While ($results.count
-eq 1)
#this checks if there is an account with the first name and last name. If $results.count is zero, the while loop is exited.
{
$tempLastName = $LastName + $counter
#This command now looks for a first name and last name+counter.
$results = get-aduser -filter * -properties * | where-object {$_.givenName -eq $FirstName -and $_.sn -like $tempLastName} | select-object givenName,sn | measure-object
$counter++
}
#This value is returned to the PowerShell activity in the portal
$tempLastName
The scripts and the screenshots of the PowerShell activity
are available in my GitHub account, https://github.com/mikeegan400/MIM-Test-for-Unique-First-and-Last-Name. Please feel free to contact me if you have
any questions or comments.