Are they registered or not?

Published 11-01-2019 12:15 PM 58 Views
Microsoft

First published on MSDN on Oct 09, 2014

I Thought I would play around with the Scripts to query for users who have registered for SSPR and for those who have not. The following Script prompts the user running the script to Enter the number 1 to query all users who have registered for SSPR or to enter the number 2 to query all users who have not registered for SSPR.

 

Additionally I have added additional columns to show the queried users Account Name, Email address, and Manager.

 


set-variable -name URI -value " http://localhost:5725/resourcemanagementservice' " -option constant

 

clear

 

If(@(Get-PSSnapin | Where-Object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {Add-PSSnapin FIMAutomation}

 

$WFDFilter = "/WorkflowDefinition[DisplayName='Password Reset AuthN Workflow']"

 

$curObjectWFD = export-fimconfig -uri $URI –onlyBaseResources -customconfig ($WFDFilter) -ErrorVariable Err -ErrorAction SilentlyContinue

 

$WFDObjectID = (($curObjectWFD.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "ObjectID"}).value).split(":")[2]

 

### Registered or non registered users ###
## This section Prompts for input to determine query for registered or users not registered for sspr ##
function Prompt-ForInput
{
Param($message)
$success = "n"
while($success -ne "" -and $success.ToLower() -ne "yes")
{
$val = Read-Host $message
$success = Read-Host "You entered: $val. Is this correct? Enter Yes or No"
}
return $val
}

 

# Questions
$SSPRRegistration = Prompt-ForInput "Enter 1 for Registered   or   2 for NOT Registered"

 

if($SSPRRegistration -eq "1")
{
$Filter = "/Person[AuthNWFRegistered = '$WFDObjectID']"
set-variable -name CSV -value "Users Registered for Password Reset.csv"
}

elseif($SSPRRegistration -eq "2")
{
set-variable -name CSV -value "Users Not Registered for Password Reset.csv"
$Filter = "/Person[not(AuthNWFRegistered = '9c3aca59-a85c-437f-bb67-9ce5a70521d7')]"
}

 

$curObject = export-fimconfig -uri $URI –onlyBaseResources -customconfig ($Filter) -ErrorVariable Err -ErrorAction SilentlyContinue

 

[array]$users = $null

 

foreach($Object in $curObject)

 

{
$ResetPass = New-Object PSObject

$UserDisplayName = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "DisplayName"}).Value)
$ResetPass | Add-Member NoteProperty "DisplayName" $UserDisplayName

$UserAccountName = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "AccountName"}).Value)
$ResetPass | Add-Member NoteProperty "AccountName" $UserAccountName

$UserEmail = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "Email"}).Value)
$ResetPass | Add-Member NoteProperty "Email" $UserEmail

$UserManager = (($Object.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "Manager"}).Value)
$ResetPass | Add-Member NoteProperty "Manager" $UserManager

 

$Users += $ResetPass

 

}

 

$users | export-csv -path $CSV

 

 

 

## http://blogs.msdn.com/connector_space ##

 

Are they registered.ps1

%3CLINGO-SUB%20id%3D%22lingo-sub-972457%22%20slang%3D%22en-US%22%3EAre%20they%20registered%20or%20not%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-972457%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Oct%2009%2C%202014%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EI%20Thought%20I%20would%20play%20around%20with%20the%20Scripts%20to%20query%20for%20users%20who%20have%20registered%20for%20SSPR%20and%20for%20those%20who%20have%20not.%20The%20following%20Script%20prompts%20the%20user%20running%20the%20script%20to%20Enter%20the%20number%201%20to%20query%20all%20users%20who%20have%20registered%20for%20SSPR%20or%20to%20enter%20the%20number%202%20to%20query%20all%20users%20who%20have%20not%20registered%20for%20SSPR.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdditionally%20I%20have%20added%20additional%20columns%20to%20show%20the%20queried%20users%20Account%20Name%2C%20Email%20address%2C%20and%20Manager.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3Eset-variable%20-name%20URI%20-value%20%22%20%3CA%20href%3D%22http%3A%2F%2Flocalhost%3A5725%2Fresourcemanagementservice'%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%20http%3A%2F%2Flocalhost%3A5725%2Fresourcemanagementservice'%20%3C%2FA%3E%20%22%20-option%20constant%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eclear%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf(%40(Get-PSSnapin%20%7C%20Where-Object%20%7B%24_.Name%20-eq%20%22FIMAutomation%22%7D%20).count%20-eq%200)%20%7BAdd-PSSnapin%20FIMAutomation%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24WFDFilter%20%3D%20%22%2FWorkflowDefinition%5BDisplayName%3D'Password%20Reset%20AuthN%20Workflow'%5D%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24curObjectWFD%20%3D%20export-fimconfig%20-uri%20%24URI%20%E2%80%93onlyBaseResources%20-customconfig%20(%24WFDFilter)%20-ErrorVariable%20Err%20-ErrorAction%20SilentlyContinue%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24WFDObjectID%20%3D%20((%24curObjectWFD.ResourceManagementObject.ResourceManagementAttributes%20%7C%20Where-Object%20%7B%24_.AttributeName%20-eq%20%22ObjectID%22%7D).value).split(%22%3A%22)%5B2%5D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%23%23%20Registered%20or%20non%20registered%20users%20%23%23%23%20%3CBR%20%2F%3E%23%23%20This%20section%20Prompts%20for%20input%20to%20determine%20query%20for%20registered%20or%20users%20not%20registered%20for%20sspr%20%23%23%20%3CBR%20%2F%3Efunction%20Prompt-ForInput%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EParam(%24message)%20%3CBR%20%2F%3E%24success%20%3D%20%22n%22%20%3CBR%20%2F%3Ewhile(%24success%20-ne%20%22%22%20-and%20%24success.ToLower()%20-ne%20%22yes%22)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24val%20%3D%20Read-Host%20%24message%20%3CBR%20%2F%3E%24success%20%3D%20Read-Host%20%22You%20entered%3A%20%24val.%20Is%20this%20correct%3F%20Enter%20Yes%20or%20No%22%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Ereturn%20%24val%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%20Questions%20%3CBR%20%2F%3E%24SSPRRegistration%20%3D%20Prompt-ForInput%20%22Enter%201%20for%20Registered%26nbsp%3B%26nbsp%3B%20or%26nbsp%3B%26nbsp%3B%202%20for%20NOT%20Registered%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eif(%24SSPRRegistration%20-eq%20%221%22)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24Filter%20%3D%20%22%2FPerson%5BAuthNWFRegistered%20%3D%20'%24WFDObjectID'%5D%22%20%3CBR%20%2F%3Eset-variable%20-name%20CSV%20-value%20%22Users%20Registered%20for%20Password%20Reset.csv%22%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%3CBR%20%2F%3Eelseif(%24SSPRRegistration%20-eq%20%222%22)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Eset-variable%20-name%20CSV%20-value%20%22Users%20Not%20Registered%20for%20Password%20Reset.csv%22%20%3CBR%20%2F%3E%24Filter%20%3D%20%22%2FPerson%5Bnot(AuthNWFRegistered%20%3D%20'9c3aca59-a85c-437f-bb67-9ce5a70521d7')%5D%22%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24curObject%20%3D%20export-fimconfig%20-uri%20%24URI%20%E2%80%93onlyBaseResources%20-customconfig%20(%24Filter)%20-ErrorVariable%20Err%20-ErrorAction%20SilentlyContinue%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%5Barray%5D%24users%20%3D%20%24null%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eforeach(%24Object%20in%20%24curObject)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7B%20%3CBR%20%2F%3E%24ResetPass%20%3D%20New-Object%20PSObject%20%3CBR%20%2F%3E%3CBR%20%2F%3E%24UserDisplayName%20%3D%20((%24Object.ResourceManagementObject.ResourceManagementAttributes%20%7C%20Where-Object%20%7B%24_.AttributeName%20-eq%20%22DisplayName%22%7D).Value)%20%3CBR%20%2F%3E%24ResetPass%20%7C%20Add-Member%20NoteProperty%20%22DisplayName%22%20%24UserDisplayName%20%3CBR%20%2F%3E%3CBR%20%2F%3E%24UserAccountName%20%3D%20((%24Object.ResourceManagementObject.ResourceManagementAttributes%20%7C%20Where-Object%20%7B%24_.AttributeName%20-eq%20%22AccountName%22%7D).Value)%20%3CBR%20%2F%3E%24ResetPass%20%7C%20Add-Member%20NoteProperty%20%22AccountName%22%20%24UserAccountName%20%3CBR%20%2F%3E%3CBR%20%2F%3E%24UserEmail%20%3D%20((%24Object.ResourceManagementObject.ResourceManagementAttributes%20%7C%20Where-Object%20%7B%24_.AttributeName%20-eq%20%22Email%22%7D).Value)%20%3CBR%20%2F%3E%24ResetPass%20%7C%20Add-Member%20NoteProperty%20%22Email%22%20%24UserEmail%20%3CBR%20%2F%3E%3CBR%20%2F%3E%24UserManager%20%3D%20((%24Object.ResourceManagementObject.ResourceManagementAttributes%20%7C%20Where-Object%20%7B%24_.AttributeName%20-eq%20%22Manager%22%7D).Value)%20%3CBR%20%2F%3E%24ResetPass%20%7C%20Add-Member%20NoteProperty%20%22Manager%22%20%24UserManager%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24Users%20%2B%3D%20%24ResetPass%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24users%20%7C%20export-csv%20-path%20%24CSV%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%23%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fconnector_space%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20http%3A%2F%2Fblogs.msdn.com%2Fconnector_space%20%3C%2FA%3E%20%23%23%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmsdnshared.blob.core.windows.net%2Fmedia%2FMSDNBlogsFS%2Fprod.evol.blogs.msdn.com%2FCommunityServer.Components.PostAttachments%2F00%2F10%2F56%2F37%2F62%2FAre%2520they%2520registered.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%20Are%20they%20registered.ps1%20%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-972457%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Oct%2009%2C%202014%20%26nbsp%3BI%20Thought%20I%20would%20play%20around%20with%20the%20Scripts%20to%20query%20for%20users%20who%20have%20registered%20for%20SSPR%20and%20for%20those%20who%20have%20not.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-972457%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAnthonyMarsiglia%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Feb 20 2020 12:21 PM
Updated by: