forked from MicksITBlogs/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetDefaultPrinter.ps1
59 lines (55 loc) · 2.64 KB
/
GetDefaultPrinter.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<#
.SYNOPSIS
Get Default Printer
.DESCRIPTION
Gets the default printer and writes the printer to a text file in the %APPDATA% folder. If
this is executed through SCCM, it must be run as the user.
.Author
Mick Pletcher
.Date
06 April 2015
.EXAMPLE
powershell.exe -executionpolicy bypass -file GetDefaultPrinter.ps1
#>
#Declare Global Variables
Set-Variable -Name DefaultPrinter -Scope Global -Force
cls
If ((Test-Path $env:APPDATA"\DefaultPrinter.txt") -eq $true) {
Remove-Item -Path $env:APPDATA"\DefaultPrinter.txt" -Force
}
$DefaultPrinter = Get-WmiObject -Class win32_printer -ComputerName "localhost" -Filter "Default='true'" | Select-Object ShareName
Write-Host "Default Printer: " -NoNewline
If ($DefaultPrinter.ShareName -ne $null) {
$DefaultPrinter.ShareName | Out-File -FilePath $env:APPDATA"\DefaultPrinter.txt" -Force -Encoding "ASCII"
Write-Host $DefaultPrinter.ShareName
} else {
$DefaultPrinter = "No Default Printer"
$DefaultPrinter | Out-File -FilePath $env:APPDATA"\DefaultPrinter.txt" -Force -Encoding "ASCII"
Write-Host $DefaultPrinter
}
#Cleanup Global Variables
Remove-Variable -Name DefaultPrinter -Scope Global -Force
# SIG # Begin signature block
# MIID9QYJKoZIhvcNAQcCoIID5jCCA+ICAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUhdw3sg/U/uQ/R/tHR/0rdJFl
# PFygggITMIICDzCCAXyg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