Created
January 27, 2022 18:47
-
-
Save MarcoGriep88/fe809a9b6bdd6a451c09a4a72fc200a2 to your computer and use it in GitHub Desktop.
Ivanti DSM - Active Directory and Lansweeper Sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$argServer = 'mybls-server.intranet.int:8085', | |
[string]$argUser = 'domain\username', | |
[string]$argPassword = 'DSMPassoword', | |
[string]$context = "emdb:\rootDSE\Managed Users & Computers\*" | |
) | |
#============================================== | |
# IDENTIFY ALL DSM COMPUTERS | |
#============================================== | |
#Prepare PS to Use HEAT DSM | |
import-module psx7 -DisableNameChecking | |
#Create global Authentification | |
$Server = "\\$argServer"; $Username = $argUser; | |
$global:path = $context | |
$password = $argPassword | ConvertTo-SecureString -asPlainText -Force | |
$credential = New-Object System.Management.Automation.PSCredential($Username, $password) | |
Write-Host "Using context: " + $context | |
#Connect to HEAT DSM | |
new-psdrive -name emdb -root $Server -scope script -psprovider blsemdb -Credential $credential | |
emdb: | |
$DSMComputers = Get-EmdbComputer $context -Recurse | |
#============================================== | |
# IDENTIFY ALL ACTIVE DIRECTORY COMPUTERS | |
#============================================== | |
Import-Module ActiveDirectory | |
$ADComputers = Get-ADComputer -Filter * -Properties * | select DNSHostName, Created, LastLogonDate, OperatingSystem, IPv4Address, Description | |
#============================================== | |
# LANSWEEPER DATA | |
#============================================== | |
$response = Invoke-WebRequest -Uri "http://lansweeper-server:95/api/Values" # URL FOR API-LANSWEEPER | |
$LSAssetdata = ConvertFrom-Json $([String]::new($response.Content)) | |
#============================================== | |
#MERGE DATA FOR REPORTING | |
#============================================== | |
class OutputData { | |
| |
[string]$Hostname = "" | |
[string]$Description = "" | |
[string]$Model = "" | |
[string]$OS = "" | |
[string]$CreateDate = "" | |
[string]$LastLogon = "" | |
[boolean]$isInAD = $False | |
[boolean]$isInDSM = $False | |
[boolean]$isInLS = $False | |
[string]$LastSeenLansweeper = "" | |
[string]$LastDSMSync = "" | |
} | |
$reportData = @() | |
| |
foreach ($comp in $ADComputers) { | |
| |
$found = $false | |
$sync = "" | |
foreach ($dsmc in $DSMComputers) { | |
| |
if (!$comp.DNSHostName) { continue } | |
if ($dsmc.Name.ToLower() -eq $comp.DNSHostName.ToLower().Replace(".your.fqdn", "")) { | |
$found = $true | |
$sync = $dsmc.LastSyncDate.ToString() | |
break | |
} | |
} | |
$LSfound = $false | |
$LSsync = "" | |
foreach ($asset in $LSdata) { | |
| |
if (!$comp.DNSHostName) { continue } | |
if ($asset.AssetName.ToLower() -eq $comp.DNSHostName.ToLower().Replace(".your.fqdn", "")) { | |
| |
$LSfound = $true | |
$LSsync = $asset.LastSeen.ToString() | |
break | |
} | |
$x = $LSAssetdata | Where-Object { $_.AssetName -Match $asset.AssetName } | |
$model = "" | |
if ($x.Count -gt 0 ) { | |
| |
$model = $x[0].Model | |
} | |
} | |
$obj = @([OutputData]@{Hostname=$comp.DNSHostName; Description=$comp.Description; Model=$model; OS=$comp.OperatingSystem; CreateDate=$comp.Created.ToString(); LastLogon=$comp.LastLogonDate.ToString(); isInAD=$true; isInDSM=$found; LastDSMSync=$sync; isInLS=$LSfound; LastSeenLansweeper = $LSsync }) | |
$reportData += $obj | |
} | |
#============================================== | |
# OUTPUT | |
#============================================== | |
$reportData | Out-GridView | |
#$reportData | Export-CSV -Path "C:\temp\export.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment