Checking the status of active users and disabling them if required.

REST is used to create users

    #Param must be the first executable line
Param(
    [string] $ContactComment = "Inital Entry",
    [string] $SystemLoginID = "12345",
    [string] $IsActive = "0",
    [string] $Name = "HALL, NICHOLAS A",
    [string] $DefaultTemplateID = "T1201",
    [string] $AppliedTemplateID = "T1201",
    [string] $LinkedTemplateID1 = "T1201",
    [string] $LinkedTemplateID2 = "T2100303",
    [string] $UserSubtemplateIDs1 = "T063",
    [string] $UserSubtemplateIDs2 = "ST5083",
    [string] $CustomUserDictionaries = "\\\\epic-server\\User_Dictionaries\\12345dictionary.tlx"
 )

#Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host

#https://vm9008.info.sys/Interconnect-REL-EDI/DeveloperView/Main.aspx?clientid=1

$Request = '{"LinkedTemplatesConfig":{"DefaultTemplateID":{"ID":"' + $DefaultTemplateID + '","Type":"external"},"AppliedTemplateID":{"ID":"' + "$AppliedTemplateID" + '","Type":"external"},"AvailableLinkableTemplates":[{"StartDate":"","EndDate":"","LoginTypes":[],"LinkedTemplateID":{"ID":"' + "$LinkedTemplateID1" + '","Type":"external"}},{"StartDate":"","EndDate":"","LoginTypes":[],"LinkedTemplateID":{"ID":"' + "$LinkedTemplateID2" + '","Type":"external"}}]},"UserSubtemplateIDs":[{"Index":"1","Identifier":{"ID":"' + "$UserSubtemplateIDs1" + '","Type":"external"}},{"Index":"2","Identifier":{"ID":"' + "$UserSubtemplateIDs2" + '","Type":"external"}}],"CustomUserDictionaries":[{"Index":"1","Value":"' + $CustomUserDictionaries + '"}],"LinkedProviderID":{"ID":"","Type":""},"IdentityIDs":[],"ExternalIdentifiers":[{"Identifier":"e12345","IdentifierType":"EMC Mckesson Document Imaging","IsActive":"true"}]}'
try
{
    $RestResults = Invoke-RestMethod -Method Put $url -contentType "application/json" -Body $Request
    foreach($id in $RestResults.UserIDs)
    {
        Write-Host $id.ID - $id.Type
    }
    if ($RestResults.UserIDs.Count -eq 4)
    {
        Write-Host "SUCCESS!"
    }
    $RestResults.Messages
}
catch
{
    if ($_.exception.Response.StatusCode -eq "BadRequest")
    {
        #$_.exception.Response.StatusDescription
        if ($_.exception.Response.StatusDescription -match '^.*System login ID must be unique\.')
        {
            Write-Host "Already Exist!"
        }
        else
        {
            Write-Host "BadRequest: " $_.exception.Response.StatusDescription
        }
    }
    else
    { 
        $_.Exception | gm
        $_.Exception | Select-Object -Property *
        $_.exception.Response.StatusCode
    }
    #$_.exception.message
    #$_.exception.InnerException
    #$_.Exception.ItemName
}

WSDL is used to Terminate/SoftDelete / Inactivate users

Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host

$where = 'https://EpicServer/Interconnect-REL-EDI/wcf/Epic.Security.GeneratedServices/PersonnelManagement.svc'
$ws = New-WebServiceProxy -uri $where -UseDefaultCredential 

$namespace = $ws.getType().namespace

foreach($line in get-content "c:\termList.txt")
{
    try
    {
        $recipients = $line -split [RegEx]::Escape("|")
        $samAccountName = $recipients[1].trim()
        [Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy61rvices_PersonnelManagement_svc.PersonnelManagementViewUserResponse] $ViewUserResponse = $ws.ViewUser($samAccountName, "SystemLogin", $null, $null, $null, $false, $null)
        if ($ViewUserResponse.IsActive)
        {
            Write-Host "Is user active in REL:" $samAccountName
        }
    }
    catch
    {
    }
}

pause

[Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy61rvices_PersonnelManagement_svc.PersonnelManagementInactivateUserResponse] $response = $ws.InactivateUser($samAccountName, "SystemLogin", $null, $null, $null)
Write-Host "Messages:" $response.Messages

[Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy61rvices_PersonnelManagement_svc.PersonnelManagementViewUserResponse] $ViewUserResponse = $ws.ViewUser($samAccountName, "SystemLogin", $null, $null, $null, $false, $null)
Write-Host "Is user active:" $ViewUserResponse.IsActive

pause

[Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy61rvices_PersonnelManagement_svc.PersonnelManagementActivateUserResponse] $ActivateResponse = $ws.ActivateUser($samAccountName, "SystemLogin", $null, $null, $null)
Write-Host "Messages:" $ActivateResponse.Messages

[Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy61rvices_PersonnelManagement_svc.PersonnelManagementViewUserResponse] $ViewUserResponse = $ws.ViewUser($samAccountName, "SystemLogin", $null, $null, $null, $false, $null)
Write-Host "Is User Active:" $ViewUserResponse.IsActive

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax