Showing results for 
Show  only  | Search instead for 
Did you mean: 
Engaged Sweeper
I have made this PowerShell script that collects all connected printers from a computer, and puts them together in a text file:
#Elevate script and exit current non-elevated runtime
Start-Process `
-FilePath 'powershell' `
-ArgumentList (
#Flatten to single array
'-File', $MyInvocation.MyCommand.Source, $args `
| ForEach-Object{ $_ }
) `
-Verb RunAs
#Name of computer
Add-Content -Path "\\kdtict004\Printers\PrinterList.txt" -Value "Printers connected to $env:COMPUTERNAME :"
#Getting the printer-data
$string = (Get-ChildItem Registry::\HKEY_Users |
Where-Object { $_.PSChildName -NotMatch ".DEFAULT|S-1-5-18|S-1-5-19|S-1-5-20|_Classes" } |
Select-Object -ExpandProperty PSChildName |
ForEach-Object { Get-ChildItem Registry::\HKEY_Users\$_\Printers\Connections -Recurse | Select-Object -ExpandProperty Name })
#Adding data to temporary file to easily edit
Add-Content -Path "\\kdtict004\Printers\Temporary.txt" -Value $string

#Deleting unnecessary information e.g. Print to PDF
$string = [System.IO.File]::ReadAllText("\\kdtict004\Printers\Temporary.txt").Replace("HKEY_USERS\S-1-5-21-1317024371-770855282-313073093-22032\Printers\Connections\,,","")
[System.IO.File]::WriteAllText("\\kdtict004\Printers\Temporary.txt", $string)
$string = [System.IO.File]::ReadAllText("\\kdtict004\Printers\Temporary.txt").Replace('"Verzenden naar OneNote 2013"',"")
[System.IO.File]::WriteAllText("\\kdtict004\Printers\Temporary.txt", $string)
$string = [System.IO.File]::ReadAllText("\\kdtict004\Printers\Temporary.txt").Replace('"Send To OneNote 2016"',"")
[System.IO.File]::WriteAllText("\\kdtict004\Printers\Temporary.txt", $string)
$string = [System.IO.File]::ReadAllText("\\kdtict004\Printers\Temporary.txt").Replace('"OneNote"',"")
[System.IO.File]::WriteAllText("\\kdtict004\Printers\Temporary.txt", $string)
$string = [System.IO.File]::ReadAllText("\\kdtict004\Printers\Temporary.txt").Replace('"Microsoft Print to PDF"',"")
[System.IO.File]::WriteAllText("\\kdtict004\Printers\Temporary.txt", $string)

#Move data from temporary file to permanent file
(Get-Content "\\kdtict004\Printers\Temporary.txt") | Where-Object {$_.trim() -ne "" } | Add-Content "\\kdtict004\Printers\PrinterList.txt"
Add-Content -Path "\\kdtict004\Printers\PrinterList.txt" -Value "`n"
#Delete temporary file
Clear-Content -Path "\\kdtict004\Printers\Temporary.txt"

This script works perfectly fine on its own and on multiple pc's, but when i try to deploy it using LanSweeper, it only adds blank lines. I presume this is because LanSweeper is somehow unable to collect the data I want. Does anyone know how to fix this?