Last active
October 22, 2023 23:50
-
-
Save alexmags/7ce2b8f83efae8b59373bb714c7a6094 to your computer and use it in GitHub Desktop.
PowerShell to find print servers from AD
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
import-module ActiveDirectory # From Remote Server Admin Tools (RSAT) Windows Desktop/server OS feature | |
# get print queues published in Active Directory | |
$printqueues=Get-AdObject -filter "objectCategory -eq 'printqueue'" -Properties * | |
# list the print queue server names and filter out duplicates where one server has multiple print queues | |
$PrintServers=$printqueues | select servername | Sort-Object -property servername -Unique | |
# Export to CSV file reports (calculated property printshares as semicolon delimited list) https://ss64.com/ps/select-object.html | |
$PrintServers | Export-Csv -NoTypeInformation -Encoding UTF8 -path $env:temp\printservers.csv | |
$resultTable=$printqueues | Select-object serverName,Name, @{Name='ShareNames';Expression={$_.printShareName -join ';'}} | |
$resultTable | Export-Csv -NoTypeInformation -Encoding UTF8 -path $env:temp\printqueues.csv | |
# Open reports | |
invoke-item $env:temp\printservers.csv | |
invoke-item $env:temp\printqueues.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment