Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
powershellworkflow-send-mail-if-accountname-present.ps1
$VerbosePreference = 'Continue'
$Global:ErrorActionPreference="Stop"
$error.clear()
if (-not $fimwf)
{
Throw "Failed to get workflow details from the FIM Target"
}
Write-Verbose "Processing FIM WF with TargetId: $fimwf"
###
### Load the FIM PowerShell Module and snapin
###
add-pssnapin FIMAutomation
Import-Module C:\CodePlex\FimPowerShellModule\FimPowerShellModule.psm1 -Verbose:$false
###
### Get the Target
###
Write-Verbose ("Getting the Target by ObjectID: {0}" -F $fimwf.TargetId.Guid)
$Target= Export-FimConfig -Custom ("/*[ObjectID='{0}']" -F $fimwf.TargetId.Guid) -OnlyBaseResources | Convert-FimExportToPSObject
###
### Get attributes (where available) for the mail
###
Try
{
$AccountName=$Target.AccountName
If ($AccountName -ne $NULL) # If there is no AccountName, the user has been deleted, so don't continue trying to send a mail - it will have N/A for all attributes - not very useful!
{
Try
{
$DisplayName=$Target.DisplayName
If ($DisplayName -eq $NULL)
{
$DisplayName="N/A"
}
}
Catch
{
}
Try
{
$EmployeeType=$Target.EmployeeType
If ($EmployeeType -eq $NULL)
{
$EmployeeType="N/A"
}
}
Catch
{
}
Try
{
$Company=$Target.Company
If ($Company -eq $NULL)
{
$Company="N/A"
}
}
Catch
{
}
Try
{
$Directorate=$Target.Directorate
If ($Directorate -eq $NULL)
{
$Directorate="N/A"
}
}
Catch
{
}
Try
{
$Department=$Target.Department
If ($Department -eq $NULL)
{
$Department="N/A"
}
}
Catch
{
}
Try
{
$Division=$Target.Division
If ($Division -eq $NULL)
{
$Division="N/A"
}
}
Catch
{
}
Try
{
$Group=$Target.Group
If ($Group -eq $NULL)
{
$Group="N/A"
}
}
Catch
{
}
Try
{
$Section=$Target.Section
If ($Section -eq $NULL)
{
$Section="N/A"
}
}
Catch
{
}
Try
{
$Site=$Target.Site
If ($Site -eq $NULL)
{
$Site="N/A"
}
}
Catch
{
}
### Get the HTML body
$html=(Get-Content "C:\FIMScripts\PowerShellWorkflow\ROEUSERMOVEDOUT.HTML" | out-string )
### Send the mail
Send-MailMessage -From fimservice@blah.ac.uk -To jon.bryan@blah.ac.uk -Subject "ROE User Move Notification" -BodyAsHtml ($html -f $AccountName, $DisplayName, $EmployeeType, $Company, $Directorate, $Department, $Division, $Group, $Section, $Site) -SmtpServer exchsmtp.blah.ac.uk
}
}
Catch
{
#Write-Verbose -Message "Error: $_.Exception.Message"
Write-Verbose -Message "Deleted User falling out of a set - no further action to take"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.