From b20d2f22a6623fb3e5e2b2dd6f4dc4faf529f8e1 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Fri, 12 Jul 2024 14:05:22 -0700 Subject: [PATCH] Refactored places that could use Get-Hostname --- Private/PrinterPurge.ps1 | 6 ++++++ Private/UserProfileBackup.ps1 | 6 ++---- Private/UserProfileTransfer.ps1 | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Private/PrinterPurge.ps1 b/Private/PrinterPurge.ps1 index 8f47833..d180abc 100644 --- a/Private/PrinterPurge.ps1 +++ b/Private/PrinterPurge.ps1 @@ -5,17 +5,23 @@ function Invoke-PrinterPurge ($printer) { if (-not ($comps -is [array])) { $comps = @($comps) } + $res = Read-Host "$($comps.Length) computers found, remove $printer from all of them? (y/N)" if (-not ($res -match "^[yY]")) { return } + for ($i = 0; $i -lt $comps.Length; $i += 1) { $comp = $comps[$i] 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 (-not (Test-Connection $comp -Count 1)) { Write-Output "$printer | $comp Offline" continue } + Remove-Printer $printer -ComputerName $comp -AsJob + Write-Output "$printer | $comp Job Sent" } Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -Completed diff --git a/Private/UserProfileBackup.ps1 b/Private/UserProfileBackup.ps1 index dbc22eb..fcec9cb 100644 --- a/Private/UserProfileBackup.ps1 +++ b/Private/UserProfileBackup.ps1 @@ -135,10 +135,8 @@ New-Item -Path $Destination -ItemType Directory | Write-Verbose } elseif ($site -eq $numSites) { $BackupDestination = Read-Host "Enter a PC asset, hostname, or custom path" - # Parse input for asset tag, hostname, then full path - if ($BackupDestination -match "^[1-9]{5}$") { - $BackupDestination = Get-AssetConversion $BackupDestination - } + # Will attempt to convert to Hostname if possible, doesn't change if not + $BackupDestination = Get-Hostname $BackupDestination # Treat as hostname and see if it's reachable if (Test-Connection -ComputerName $BackupDestination -Count 1) { # If so, get the filesystem path diff --git a/Private/UserProfileTransfer.ps1 b/Private/UserProfileTransfer.ps1 index f4923bd..e60e412 100644 --- a/Private/UserProfileTransfer.ps1 +++ b/Private/UserProfileTransfer.ps1 @@ -4,7 +4,7 @@ .SYNOPSIS Backs up a user profile to a specified filepath. .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. #>