Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Get-LithnetAutoSyncStatus
{
<#
.Synopsis
Checks the Lithnet AutoSync Execution monitor status
.DESCRIPTION
This command checks the status of the Lithnet AutoSync execution monitor. If the monitor is started it will retun "running". If is
is not running, it will return "stopped". Cmdlet must be executed on host which has the AutoSync service installed.
More information about AutoSync is available here: https://github.com/lithnet/miis-autosync
.EXAMPLE
Get-LithnetAutoSyncStatus
.OUTPUTS
String output
.NOTES
Created by: @toregroneng, tore.groneng@gmail.com
Created: 2019
.COMPONENT
Microsoft Identity Manager and Lithnet AutoSync
.ROLE
Query AutoSync Execution Monitor
#>
[cmdletbinding()]
Param()
Write-Verbose -Message "Checking if assemblies are loaded"
$loadedAssemblies = [System.AppDomain]::CurrentDomain.GetAssemblies()
$isLithNetLoaded = $false
foreach ($dll in $loadedAssemblies)
{
if ($dll.Fullname -like "Lithnet.Miiserver.AutoSync*")
{
$isLithNetLoaded = $true
Write-Verbose -Message "Found the AutoSync assembly"
break
}
}
if ($isLithNetLoaded -eq $false)
{
Write-Verbose -Message "Assemblies not loaded, loading assemblies..."
$programPath = Join-Path -Path $env:SystemDrive -ChildPath 'Program files' |
Join-Path -ChildPath Lithnet |
Join-Path -ChildPath Autosync
if (-not (Test-Path -Path $programPath))
{
$service = Get-CimInstance -ClassName win32_service -Filter "name like 'autosync'"
$pathName = $service.PathName.replace('"','') | Split-Path -Parent
$testPath = Get-ChildItem -Path $pathName
if ($testPath.psiscontainer -eq $false)
{
$programPath = $pathName | Split-Path -Parent
}
else
{
$programPath = $pathName
}
}
if (-not (Test-Path -Path $programPath))
{
Write-Error -Message "Unable to find path [$programPath]" -ErrorAction Stop
}
$mainAssembly = Join-Path -Path $programPath -ChildPath Lithnet.Miiserver.AutoSync.exe
$editorAssembly = Join-Path -Path $programPath -ChildPath Lithnet.Miiserver.AutoSync.Editor.exe
$null = [System.Reflection.Assembly]::LoadFrom($mainAssembly)
$null = [System.Reflection.Assembly]::LoadFrom($editorAssembly)
$isLithNetLoaded = $true
}
if ($isLithNetLoaded)
{
$autoSyncConfigClient = [Lithnet.Miiserver.AutoSync.UI.App]::GetDefaultConfigClient()
Write-Verbose -Message "ConfigClient state is $($autoSyncConfigClient.State)"
if ($autoSyncConfigClient.State -ne [System.ServiceModel.CommunicationState]::Created)
{
Write-Error -Message "Autosync Service is not running" -ErrorAction Stop
}
Write-Verbose -Message "ChannelFactory state is $($autoSyncConfigClient.ChannelFactory.State)"
if ($autoSyncConfigClient.ChannelFactory.State -ne [System.ServiceModel.CommunicationState]::Created)
{
Write-Error -Message "Unable to communicate with the AutoSync service" -ErrorAction Stop
}
$autoSyncConfigClient.GetEngineState()
}
else
{
Write-Error -Message "Failed to load Lithnet assemblies"
}
}
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.