Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Test for Elevated Rights
- $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
- $testadmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
- if ($testadmin -eq $false) {
- Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
- exit $LASTEXITCODE
- }
- #Define Variables
- $ports = Get-Content '\\protaskadm\scripts\portArray.txt'
- $userPrinters = Get-Printer
- $printerArray = @()
- $printerCount = 0
- $currentPort = 0
- $currentName = 0
- #Define variables for deployment waves
- $wave1 = New-Object System.Management.Automation.Host.ChoiceDescription '&1','Your Choice: Wave 1'
- $wave2 = New-Object System.Management.Automation.Host.ChoiceDescription '&2','Your Choice: Wave 2'
- $wave3 = New-Object System.Management.Automation.Host.ChoiceDescription '&3','Your Choice: Wave 3'
- $wave4 = New-Object System.Management.Automation.Host.ChoiceDescription '&4','Your Choice: Wave 4'
- $wave5 = New-Object System.Management.Automation.Host.ChoiceDescription '&5','Your Choice: Wave 5'
- $wave6 = New-Object System.Management.Automation.Host.ChoiceDescription '&6','Your Choice: Wave 6'
- $wave7 = New-Object System.Management.Automation.Host.ChoiceDescription '&7','Your Choice: Wave 7'
- $wave8 = New-Object System.Management.Automation.Host.ChoiceDescription '&8','Your Choice: Wave 8'
- $wave9 = New-Object System.Management.Automation.Host.ChoiceDescription '&9','Your Choice: Wave 9'
- $wave10 = New-Object System.Management.Automation.Host.ChoiceDescription '&10','Your Choice: Wave 10'
- $options = [System.Management.Automation.Host.ChoiceDescription[]]($wave1, $wave2, $wave3, $wave4, $wave5, $wave6, $wave7, $wave8, $wave9, $wave10)
- #Title Banner
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
- Write-Host ' '
- Write-Host ' PT PRINTER REFRESH '
- Write-Host ' .----. '
- Write-Host ' | | '
- Write-Host ' __|____|__ '
- Write-Host ' `| ______--| '
- Write-Host ' -/.::::.\- '
- Write-Host ' '`--------' '
- Write-Host ' '
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
- #Get user input for wave deployment
- $title = 'Select your Wave'
- $message = 'Please select your wave. Reference the email if necessary'
- $result = $host.ui.PromptForChoice($title, $message, $options, 0)
- #enumerate user printers
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++++' -ForegroundColor Yellow
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host ' We are gathering your installed printers ' -ForegroundColor Yellow
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++++' -ForegroundColor White
- Start-Sleep -s 5
- foreach ($userPrinter in $userPrinters){
- $enumeratePrt = [PSCustomObject]@{
- Name = $userPrinter.Name
- Port = $userPrinter.PortName
- }
- $printerArray += $enumeratePrt
- }
- #step through printers
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' -ForegroundColor Yellow
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host ' We are checking for any printers to be uninstalled ' -ForegroundColor Red
- Write-Host ' and uninstalling them ' -ForegroundColor Red
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++++' -ForegroundColor White
- :parent foreach ($printer in $printerArray){
- :child1 foreach ($port in $ports){
- #write-host 'The current printer is ' $printer.Name
- #Write-Host 'The current port is ' $port
- if (($printer.Port -eq $port) -or ($printer.Port -like 'WSD*')){
- Remove-Printer -Name $printer.Name -ErrorAction Stop
- #Write-Host 'Printer ' $printer.Name ' found'
- $printerCount++
- break child1
- }else{
- #do nothing
- }
- }
- }
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' -ForegroundColor Yellow
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host $printerCount ' printer(s) were uninstalled ' -ForegroundColor Green
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++++' -ForegroundColor White
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' -ForegroundColor Yellow
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host ' We are installing your new printer(s) ' -ForegroundColor Green
- Write-Host ' ' -ForegroundColor Yellow
- Write-Host '++++++++++++++++++++++++++++++++++++++++++++++++++++++++' -ForegroundColor White
- #Add Printers
- switch ($result){
- 0 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 1 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 2 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 3 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 4 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 5 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 6 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 7 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 8 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 9 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- 10 {Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '\\<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Yellow
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'
- Write-Host 'Adding Printer <printernamehere>' -ForegroundColor Green
- Add-Printer -ConnectionName '<printserverhere>\<printernamehere>'}
- }
- Start-Sleep -s 3
Advertisement
Add Comment
Please, Sign In to add comment