Refactored places that could use Get-Hostname

This commit is contained in:
Zachary Gorman 2024-07-12 14:05:22 -07:00
parent f5224ff3fc
commit b20d2f22a6
3 changed files with 9 additions and 5 deletions

View file

@ -5,17 +5,23 @@ function Invoke-PrinterPurge ($printer) {
if (-not ($comps -is [array])) { if (-not ($comps -is [array])) {
$comps = @($comps) $comps = @($comps)
} }
$res = Read-Host "$($comps.Length) computers found, remove $printer from all of them? (y/N)" $res = Read-Host "$($comps.Length) computers found, remove $printer from all of them? (y/N)"
if (-not ($res -match "^[yY]")) { return } if (-not ($res -match "^[yY]")) { return }
for ($i = 0; $i -lt $comps.Length; $i += 1) { for ($i = 0; $i -lt $comps.Length; $i += 1) {
$comp = $comps[$i] $comp = $comps[$i]
Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -PercentComplete (100*$i / $comps.Length) -CurrentOperation "$comp $i/$($comps.Length)" Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -PercentComplete (100*$i / $comps.Length) -CurrentOperation "$comp $i/$($comps.Length)"
if ($comp -like "*EPIC*") { continue } if ($comp -like "*EPIC*") { continue }
if (-not (Test-Connection $comp -Count 1)) { if (-not (Test-Connection $comp -Count 1)) {
Write-Output "$printer | $comp Offline" Write-Output "$printer | $comp Offline"
continue continue
} }
Remove-Printer $printer -ComputerName $comp -AsJob Remove-Printer $printer -ComputerName $comp -AsJob
Write-Output "$printer | $comp Job Sent" Write-Output "$printer | $comp Job Sent"
} }
Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -Completed Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -Completed

View file

@ -135,10 +135,8 @@
New-Item -Path $Destination -ItemType Directory | Write-Verbose New-Item -Path $Destination -ItemType Directory | Write-Verbose
} elseif ($site -eq $numSites) { } elseif ($site -eq $numSites) {
$BackupDestination = Read-Host "Enter a PC asset, hostname, or custom path" $BackupDestination = Read-Host "Enter a PC asset, hostname, or custom path"
# Parse input for asset tag, hostname, then full path # Will attempt to convert to Hostname if possible, doesn't change if not
if ($BackupDestination -match "^[1-9]{5}$") { $BackupDestination = Get-Hostname $BackupDestination
$BackupDestination = Get-AssetConversion $BackupDestination
}
# Treat as hostname and see if it's reachable # Treat as hostname and see if it's reachable
if (Test-Connection -ComputerName $BackupDestination -Count 1) { if (Test-Connection -ComputerName $BackupDestination -Count 1) {
# If so, get the filesystem path # If so, get the filesystem path

View file

@ -4,7 +4,7 @@
.SYNOPSIS .SYNOPSIS
Backs up a user profile to a specified filepath. Backs up a user profile to a specified filepath.
.DESCRIPTION .DESCRIPTION
Takes a input of hostname and user and will make a copy of the user profile Takes a input of a user profile filepath, will make a copy of the user profile
and the Microsoft Roaming Folder and back it up to a specified filepath. and the Microsoft Roaming Folder and back it up to a specified filepath.
#> #>