Skip to content

Instantly share code, notes, and snippets.

@jkbryan
jkbryan / GrantServicePrincipleAzureSubscriptionReadAccess.ps1
Created January 30, 2019 23:12
Grants an Azure Service Principle READ access to the Subscription
$Subscription = "<Subscription-GUID>"
$ApplicationName = "<AppName>"
$ServicePrincipal = Get-AzureRMADServicePrincipal -DisplayName $ApplicationName
Set-AzureRmContext -Subscription $Subscription
$NewRole = $null
$Retries = 0;
While ($NewRole -eq $null -and $Retries -le 6) {
Sleep 15
New-AzureRMRoleAssignment -ResourceGroupName -RoleDefinitionName Reader -ServicePrincipalName $ServicePrincipal.ApplicationId | Write-Verbose -ErrorAction SilentlyContinue
$NewRole = Get-AzureRMRoleAssignment -ObjectId $ServicePrincipal.Id -ErrorAction SilentlyContinue
@jkbryan
jkbryan / openssl.cfg
Last active January 8, 2019 23:11
Basic OpenSSL configuration file for generating server authentication SSL certificates
#
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#
# This definition stops the following lines choking if HOME isn't
# defined.
HOME = .
RANDFILE = $ENV::HOME/.rnd
@jkbryan
jkbryan / logging-example.vb
Created October 2, 2018 22:59
logging-example.vb
'Within the "Public Class MAExtensionObject" section, add:
'Date & Logginglevel variables for logging files:
Dim dtDateNowDay As Integer = Date.Now.Day
Dim dtDateNowMonth As Integer = Date.Now.Month
Dim dtDateNowYear As Integer = Date.Now.Year
Dim loggingLevel As Integer = 0
'================================================
'With the Sub or Function that you want logging - e.g. "Public Sub MapAttributesForImport"
Dim dtFileTime As DateTime
'Define Logfile Name then setup the logfile
@jkbryan
jkbryan / santizing-employeeenddate.vb
Created October 2, 2018 22:58
santizing-employeeenddate.vb
Case "employeeEndDate-CDRMA-PA-Import"
'CDR attributes required are: EndDate
'Code to define the employeeEndDate in the MV and Portal - needs to be in the correct format!
Dim dtFileTime As DateTime
If csentry("EndDate").IsPresent Then
dtFileTime = DateTime.Parse(csentry("EndDate").Value).Date
'Convert to the date/time string format that the Portal requires:
Dim employeeEndDate As String = dtFileTime.ToLocalTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.000'")
Dim arremployeeEndDate As String() = Split(employeeEndDate, "T")
employeeEndDate = arremployeeEndDate(0) & "T23:59:59.000"
@jkbryan
jkbryan / filterfordisconnection-example.vb
Created October 2, 2018 22:56
filterfordisconnection-example.vb
Public Function FilterForDisconnection(ByVal csentry As CSEntry) As Boolean Implements IMASynchronization.FilterForDisconnection
'Filter to prevent those who are not being returned by the CDR FIM View from being presented by this table (which contains lots of historical data!)
Dim dtFileTime As DateTime
Dim dtDateNow As DateTime = Date.Now
'CS attributes required are: pid, enddate
If csentry("pid").IsPresent And csentry("enddate").IsPresent Then
dtFileTime = DateTime.Parse(csentry("EndDate").Value).AddDays(190)
If dtFileTime <= dtDateNow Then
'employeeEndDate has passed, so disconnect
FilterForDisconnection = True
Case "functionalIDFlag-ADMA-Import"
If csentry.DN.ToString.ToLower.Contains("functional") Then
mventry("functionalID").Value = "True"
ElseIf csentry.DN.ToString.ToLower.Contains("ou=fim") Then
mventry("functionalID").Value = "True"
ElseIf csentry("employeeID").IsPresent Or csentry("stfc-pid").IsPresent Then
'Real users - e.g. those created by the User Office process and those historical users no longer in CDR
mventry("functionalID").Value = "False"
Else
Throw New Exception("FunctionalID flag setting for: " & csentry.DN.ToString.ToLower)
@jkbryan
jkbryan / shouldprojecttomv-example.vb
Created October 2, 2018 22:49
shouldprojecttomv-example.vb
Public Function ShouldProjectToMV(ByVal csentry As CSEntry, ByRef MVObjectType As String) As Boolean Implements IMASynchronization.ShouldProjectToMV
If csentry.DN.ToString.ToLower.Contains("functional") Then
MVObjectType = "functionalID"
ShouldProjectToMV = True
ElseIf csentry.DN.ToString.ToLower.Contains("fimaccess") Then
'Those people who need to administer FIM, need a user account in the portal, so treat them as such and Project!
MVObjectType = "person"
ShouldProjectToMV = True
ElseIf csentry("employeeID").IsPresent Then
'Real users - e.g. those created by the User Office process and those historical users no longer in CDR (Initial Pre-Load) - But CDR is authoratative for all new users - so Projection occurs there also - this handles "normal" users - e.g. those fed from CDR directly.
@jkbryan
jkbryan / clear-adou-attribute.ps1
Last active October 2, 2018 22:46
clear-adou-attribute.ps1
Import-Module LithnetRMA
# Setup the XPath Query - get all users
$z=New-XPathQuery -AttributeName AccountName -Operator IsPresent
# Use that query in the XPath Expression
$Query=New-XPathExpression -ObjectType Person -QueryObject $z
# Do the search
$Users=Search-Resources -XPath $query -AttributesToGet AccountName, adOU
ForEach ($u in $users)
{
# If adOU is not NULL, then make it so!
@jkbryan
jkbryan / export-policy.ps1
Created October 2, 2018 22:43
export-policy.ps1
if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation}
$workDir = "C:\FIMConfig\Temp\"
$policy_filename = $workDir+"FIM-Policy.xml"
Write-Host "Exporting configuration objects from pilot."
# In many production environments, some Set resources are larger than the default message size of 10 MB.
$policy = Export-FIMConfig -policyConfig -portalConfig -MessageSize 9999999
if ($policy -eq $null)
{
Write-Host "Export did not successfully retrieve configuration from FIM. Please review any error messages and ensure that the arguments to Export-FIMConfig are correct."
}
@jkbryan
jkbryan / example-html-mail-template.html
Created October 2, 2018 22:40
example-html-mail-template.html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>OBU Account created</title>
</head>
<body>
<h1 style="padding-left: 30px; font-family: verdana; font-size: 150%">OBU Account created</h1>
<h2 style="padding-left: 30px; font-family: verdana; font-size: 150%">Attributes:</h2>