Lansweeper
Jeg har over det sidste år benytte lansweeper (free) da jeg er lang under 100 assets, som lille cmdb.
i stedet for at lade en service account scanne alle maskine, som jeg ser giver lidt forskellige udfordringer, har jeg lavet en scheduler task som bliver deployed via gpo, der starter lspush.exe modulet.
Det giver mig mulighed for at være event driven, dvs. bærbar som sjældent er på hoved netværket, men ofte kommer ind via VPN, levere data få minutter efter at en vpn forbindelse er lavet, kun efter logon, såfremt at der er netværks forbindelse, dvs. maskinen ikke er i offline mode, osv.
Jeg har på maskine som har lansweeper installeret delt mappen "client" som LansweeperClient (det er mappen hvor lspush etc. ligger i), her har jeg også lagt en "Files.tsv" file, sådan denne feature for custom søgning efter data også er muligt.
Nedestående powershell scripts, laver jeg om til base64, når jeg ligger disse i schedulertask, så er det blot en lang streng, som skal køres, hvilket er lidt simplere.
Del 1 af scheduler task er vedligehold af filerne:
$lspushfile = "\\lansweeper.install.local\LanSweeperClient\lspush.exe"
$lspushscan = "\\lansweeper.install.local\LanSweeperClient\Files.tsv"
$locallspushfolder = ${env:ProgramFiles(x86)}+"\lansweeperClient\"
$locallspushfile = $locallspushfolder + "lspush.exe"
$locallspushscan = $locallspushfolder + "Files.tsv"
if (test-path $lspushfile)
{
Write-Host "server connection is here"
if (test-path $locallspushfile ) {
Write-Host "file is here"
$lspushfilehash = Get-FileHash $lspushfile -Algorithm MD5
write-host $lspushfilehash
$locallspushfilehash = Get-FileHash $locallspushfile -Algorithm MD5
write-host $locallspushfilehash
if ($lspushfilehash.Hash -ne $locallspushfilehash.Hash ){
copy-item $lspushfile $locallspushfolder -Force
}
}
else{
Write-Host "file not here"
if (!(test-path $locallspushfolder)) {New-Item -Path $locallspushfolder -ItemType directory}
copy-item $lspushfile $locallspushfolder -Force
}
if (test-path $lspushscan){
if (test-path $locallspushscan ){
Write-Host "file is here"
$lspushscanhash = Get-FileHash $lspushscan -Algorithm MD5
write-host $lspushscanhash
$locallspushscanhash = Get-FileHash $locallspushscan -Algorithm MD5
write-host $locallspushfilehash
if ($lspushscanhash.Hash -ne $locallspushscanhash.Hash ){
copy-item $lspushscan $locallspushfolder -Force
}
}
else{
copy-item $lspushscan $locallspushfolder -Force
}
}
}
else{
Write-Host "server connection is not here"
}
Step 2) er naturligvis at køre lspush.exe med dns på pc'en hvor lansweeper er installeret.
$lansweeper = "lansweeper.install.local"
$locallspushfolder = ${env:ProgramFiles(x86)}+"\lansweeperClient\"
$locallspushfile = $locallspushfolder + "lspush.exe"
$locallspushscan = $locallspushfolder + "Files.tsv"
if (Test-Connection -ComputerName $lansweeper -Quiet )
{
Start-Process -FilePath $locallspushfile -ArgumentList $lansweeper -Wait -WindowStyle Hidden
}
Base64 Decode - stjålet fra nettet:
$EncodedText ´minebase64streng´
$DecodedText = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedText))
$DecodedText > c:\temp\scheduler.ps1
Base64 encode - stjålet fra nettet:
$Text = ´script som skal laves til base64'
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText > C:\temp\newscheduler.ps1