Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Setting the default printer based on network subnet.
$homeRange = "10.1.1.*"
$remoteRange = "10.7.104.*"
$remotePrinter = "W3Printer_01"
$homePrinter = "AdminPrinter"
function Set-DefaultPrinter([string]$printerPath) {
$printers = gwmi -class Win32_Printer -computer .
Write-Host -fore cyan "Default Printer: $printerPath"
$dp = $printers | ? { $_.deviceID -match $printerPath }
$dp.SetDefaultPrinter() | Out-Null
}
$ipAddress = @()
$ipAddress = gwmi win32_NetworkAdapterConfiguration |
? { $_.IPEnabled -eq $true } |
% { $_.IPAddress } |
% { [IPAddress]$_ } |
? { $_.AddressFamily -eq 'internetwork' } |
% { $_.IPAddressToString }
Write-Host -fore cyan "Your current network is $ipAddress."
switch -wildcard ($ipAddress) {
$homeRange { Set-DefaultPrinter $homePrinter }
$remoteRange { Set-DefaultPrinter $remotePrinter }
default { Set-DefaultPrinter $homePrinter }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.