Find users using printer server

Right now we are disposing  two old printer servers that we thought no one were using. After we began to log all prints we noticed that it still was hundreds of users using the old printer servers. We could link some of the prints to an old GPO with an VB logon-script but most of the users have probably mapped the printers manually, therefore the client-guys needed a list of users who had users the printer server the last 90 days. First of all you need to start logging all prints, to do so on an Windows 2008 R2 start Print Management and right-click on the server and select properties and check Log spooler information events.



Now you just have to wait 90 days and then run this script to get an report of which user that have users printer server.


#NAME: List_priter_users.ps1
#AUTHOR: Viktor Lindström
#COMMENTS: List all users that have used printer server last 90 days.

$date = get-date
$priterservers = "srv-print04", "srv-print05"

foreach ($server in $priterservers)
{$con = get-eventlog -ComputerName $server -log  system  -After $date.AddDays(-90) | where {$_.eventID -eq 10} | select UserName
$uni = $con | Sort-Object username | Get-Unique -AsString
$uni | Export-Csv c:\temp\$server.txt

Bulk modify AD users from CSV

The last post showed how to create AD users from CSV, here is how to bulk modify attributes from CSV

#Modify AD user from CSV file, in this case i Change the extensionAttribute1 and extensionAtribute2
$Import=Import-Csv C:\temp\csv.txt
    foreach($user1 in $Import)
    set-aduser $user1.anvandare -Replace @{extensionAttribute1=$user1.test; extensionAttribute2=$user1.Url} 

Bulk delete printers


Right now I´m working on project to dispose two old print servers.  A issue with these servers is that no one used a routine to delete printers from the server when they physically powered off the printers mapped on the server. To solve this I used powershell to collect all printers from the server and then do a ping to the portname of each printer and list the ones who didn’t respond, in an array. Then I use that array to delete the printers from the server.

#NAME: Delete_Printers.ps1
#AUTHOR: Viktor Lindström
#COMMENTS: Delete printers on remote server that don´t respond on ping.

#Collect all printers
$AllPrinters = Get-Printer -ComputerName srv-print05 | where portname -Like "*prn*"

#create an empty array
$DownPrinters = @()

#collect printers that don't respond on ping 
foreach ($printer in $AllPrinters)
    $DownPrinters += Test-NetConnection $printer.PortName -ErrorAction SilentlyContinue | where pingsucceeded -eq $false
    Write-Host "testar ping mot" $printer.PortName

# Delete printers that didn´t respond on ping
foreach ($Printer2 in $DownPrinters)
$Getprint = Get-Printer -ComputerName srv-print05 | where portname -EQ $printer2.computername 
Remove-Printer -InputObject $Getprint