PowerShell bietet Commandlets zum Abfragen von Active Directory, die selbst für Administratoren ohne fundierte Programmierkenntnisse sehr einfach zu verwenden sind. Diese Commandlets werden über die RSAT-Tools für Active Directory installiert. Lansweeper-Bewertungen werden am besten über meine API-Lansweeper-Schnittstelle durchgeführt. Der einfachste Weg, auf Ivanti DSM-Informationen zuzugreifen, sind die PSX PowerShell-Erweiterungen. Ich habe in meinem Blog häufig Artikel über die PSX PowerShell-Erweiterungen geschrieben.
PowerShell Script - Sektionen
Das PowerShell-Skript ist in mehrere Abschnitte unterteilt.
- Im ersten Schritt werden alle Computerinformationen aus der Softwareverteilung gelesen.
- Dann bestimme ich alle Clients aus dem Active Directory
- Dann bekomme ich alle Computerinformationen von Lansweeper von API-Lansweeper
- Im letzten Schritt fasse ich Informationen in einer Liste zusammen, die alle erforderlichen Berichtsdaten enthält, und gebe sie als CSV-Datei aus.
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"
Wie verwende ich das Script?
- Installieren Sie die RSAT-Tools
- Installieren Sie PSX PowerShell-Erweiterungen
- Ersetzen Sie URLs für die Lansweeper-API und den BLS-Server
- In der Zuordnung. Ersetzen Sie "your.fqdn" durch Ihre Domain