Refactored main, currently broke job system but there is a plan to rework the job system

This commit is contained in:
Zachary Gorman 2024-07-24 15:37:27 -07:00
parent 61038d43e5
commit e17f7e6ba3
5 changed files with 374 additions and 403 deletions

View file

@ -78,6 +78,9 @@ function Get-Devices {
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices') $item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
$out += $item $out += $item
} }
$item = [PSCustomObject]@{ }
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
$out += $item
Write-Output $out Write-Output $out
} }

View file

@ -1,24 +1,30 @@
function Get-Hostname ([string]$name) { function Get-Hostname ([string]$name) {
$errMsg = ''
if ($name.Length -eq 5) { if ($name.Length -eq 5) {
$res = Get-AssetConversion $name $res = Get-AssetConversion $name
if ($res) { return $res } if ($res) { return $res,'' }
else { $errMsg += "$name Asset Tag not in SMBIOS or CMDB. "}
} }
# Regex to match IP Address brought to you by https://stackoverflow.com/a/36760050 # Regex to match IP Address brought to you by https://stackoverflow.com/a/36760050
if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") { if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") {
$res = Resolve-DnsName $name $res = Resolve-DnsName $name
if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) { if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) {
return $Matches[1] return $Matches[1],''
} else {
$errMsg += "$name IP Address couldn't be resolved to hostname"
} }
} }
if ($name.Length -eq 7) { if ($name.Length -eq 7) {
$res = Get-ServiceTagConversion $name $res = Get-ServiceTagConversion $name
if ($res) { return $res } if ($res) { return $res,'' }
else { $errMsg += "$name Service Tag not found in SCCM"}
} }
# Regex to match MAC Address brought to you by https://stackoverflow.com/a/4260512 # Regex to match MAC Address brought to you by https://stackoverflow.com/a/4260512
if ($name -match "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$") { if ($name -match "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$") {
$res = Get-SCCM_PCFromMAC $name $res = Get-SCCM_PCFromMAC $name
if ($res) { return $res } if ($res) { return $res,'' }
else { $errMsg += "$name MAC Address not found in SCCM"}
} }
return $name return $name, $errMsg
} }

View file

@ -8,8 +8,12 @@
Write-Host "Current Hostname: $ComputerName" Write-Host "Current Hostname: $ComputerName"
$NewHostName = Read-Host "New Hostname" $NewHostName = Read-Host "New Hostname"
Rename-Computer -ComputerName $ComputerName -NewName $NewHostName -DomainCredential $DomainUser -force -Restart $res = Rename-Computer -ComputerName $ComputerName -NewName $NewHostName -DomainCredential $DomainUser -force -Restart -PassThru
if ($res.HasSucceeded) {
Write-Host "Renamed PC, successful. Restarting PC... Old Hostname: $ComputerName, New Hostname: $NewHostName" -ForegroundColor Green Write-Host "Renamed PC, successful. Restarting PC... Old Hostname: $ComputerName, New Hostname: $NewHostName" -ForegroundColor Green
} else {
Write-Host "Failed to rename PC. Check user credentials" -ForegroundColor Red
}
}else{ }else{

View file

@ -136,7 +136,7 @@
} 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"
# Will attempt to convert to Hostname if possible, doesn't change if not # Will attempt to convert to Hostname if possible, doesn't change if not
$BackupDestination = Get-Hostname $BackupDestination $BackupDestination,$null = Get-Hostname $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 @@
#region Module Import Block #region Module Import Block
$ErrorActionPreference = 'SilentlyContinue' #$ErrorActionPreference = 'SilentlyContinue'
#DevStage can take either Dev or Prod as values #DevStage can take either Dev or Prod as values
$devStage = 'Dev' $devStage = 'Dev'
#Locations for dev build and prod build #Locations for dev build and prod build
@ -53,7 +53,6 @@ Function Get-PC {
-PCReboot | reboots computer -PCReboot | reboots computer
-PCRename | renames computer -PCRename | renames computer
-RemoteDesktopApp | remote into computer using RDP -RemoteDesktopApp | remote into computer using RDP
-RequestLauncher | starts request launcher
-ResetRepository | remotely resets repository -ResetRepository | remotely resets repository
-Resources | more details about system resources -Resources | more details about system resources
-PrinterPurge | removes printer from all online computers -PrinterPurge | removes printer from all online computers
@ -104,7 +103,6 @@ Function Get-PC {
[Switch]$PCRename, [Switch]$PCRename,
[Switch]$Quiet, [Switch]$Quiet,
[Switch]$RemoteDesktopApp, [Switch]$RemoteDesktopApp,
[Switch]$RequestLauncher,
[Switch]$Resources, [Switch]$Resources,
[Switch]$ResetRepository, [Switch]$ResetRepository,
[Switch]$PrinterPurge, [Switch]$PrinterPurge,
@ -127,35 +125,6 @@ Function Get-PC {
break break
} }
<#$charA = $ComputerName.ToCharArray()
if($charA -contains '*'){
if($charA -lt 4){
Write-Host "Wildcard searches need to be at least 4 characters long" -ForegroundColor Red
return
}
Write-Host "Starting CMDB Wildcard Search..."
$searchResults = Search-CMDB -hostname $ComputerName.Replace('*','') | Sort-Object -Property Hostname
Write-Output $searchResults
if($TableView){
$searchResults | Out-GridView -Title 'Get-PC Wildcard Search'
}
return
}
#>
$getPCComputers = @() #List of computers that will get a batch query
$outPutArray = @() #For use near the end of the script to output to users screen in a specified format
$PCID = 1 #This is a helper variable for the progress bar
if ($Jobsprinters) {
#runs the printer query as a set of jobs
$outPutArray = Get-PCBatchJob($ComputerName) -printers
Write-Output $outPutArray
}
if (!$Jobsprinters) {
# Stuff only run once # Stuff only run once
if ($Update) { if ($Update) {
#updates get pc #updates get pc
@ -163,9 +132,6 @@ Function Get-PC {
return return
} }
$NumberofComputers = $ComputerName.Count
foreach ($comp in $ComputerName) {
if ($PatchNotes) { if ($PatchNotes) {
$scriptparent = (get-item $PSScriptRoot ).parent.FullName $scriptparent = (get-item $PSScriptRoot ).parent.FullName
Write-Host "`n" Write-Host "`n"
@ -173,6 +139,13 @@ Function Get-PC {
break break
} }
$getPCComputers = @() #List of computers that will get a batch query
$outPutArray = @() #For use near the end of the script to output to users screen in a specified format
$PCID = 1 #This is a helper variable for the progress bar
$NumberofComputers = $ComputerName.Count
foreach ($comp in $ComputerName) {
#Pulls user data from AD #Pulls user data from AD
if ($SHSUser) { if ($SHSUser) {
$user = Get-SHSUser $comp $user = Get-SHSUser $comp
@ -181,16 +154,9 @@ Function Get-PC {
} }
$oldcomp = $comp $oldcomp = $comp
$comp = Get-Hostname $comp $comp,$msg = Get-Hostname $comp
if (($oldcomp -eq $comp) -and (($comp.length -eq 5 -and !$SHSPrinter) -or ($comp.length -eq 7))) { if ($msg) {
if ($comp.length -eq 5 -and !$SHSPrinter) {
$msg = "$comp Asset Tag not in SMBIOS or CMDB"
Write-Host "`n$msg" -ForegroundColor Red Write-Host "`n$msg" -ForegroundColor Red
}
elseif ($comp.length -eq 7) {
$msg = "$comp Service Tag not found in SCCM"
Write-Host "`n$msg" -ForegroundColor Red
}
$props = [Ordered]@{ $props = [Ordered]@{
Hostname = "$msg" Hostname = "$msg"
@ -256,7 +222,7 @@ Function Get-PC {
else { else {
Write-Output $out Write-Output $out
} }
break continue
} }
if ($PrinterPurge) { if ($PrinterPurge) {
@ -264,12 +230,6 @@ Function Get-PC {
continue continue
} }
#Launches the request launcher script which containts landesk request template scripts
if ($RequestLauncher) {
Invoke-Expression \\int.samhealth.net\files\team\SHSISDesktopSolutions\Powershell\RequestLauncher\RequestLauncher.lnk
break
}
#Generates an available printer hostname. Useful for supplying a new hostname in new printer requests #Generates an available printer hostname. Useful for supplying a new hostname in new printer requests
if ($NextPrinterName) { if ($NextPrinterName) {
Find-NextPrinterName $comp Find-NextPrinterName $comp
@ -350,11 +310,11 @@ Function Get-PC {
if ($compStatus -ne 'Online') { if ($compStatus -ne 'Online') {
Write-Warning "$comp is $compStatus unable to proccess command" Write-Warning "$comp is $compStatus unable to proccess command"
break continue
} }
Get-ResetRepository $comp Get-ResetRepository $comp
break continue
} }
#Backs up user profile to specified destination #Backs up user profile to specified destination
@ -415,7 +375,7 @@ Function Get-PC {
continue continue
} }
#Pulls a list of installed programs from SCCM. May not be up to date if changes were made after the last sccm scan #Pulls a list of installed programs from SCCM and Get-Package
if ($Apps) { if ($Apps) {
Get-Apps $comp $TableView Get-Apps $comp $TableView
continue continue
@ -473,7 +433,7 @@ Function Get-PC {
} }
Get-ViewerRemote $comp Get-ViewerRemote $comp
continue break
} }
#Runs Remote Desktop Connection Application #Runs Remote Desktop Connection Application
@ -568,8 +528,6 @@ Function Get-PC {
} }
}
# Monitor list of PCs for change in online status or # Monitor list of PCs for change in online status or
if ($Monitor) { if ($Monitor) {
Invoke-PCMonitor $getPCComputers Invoke-PCMonitor $getPCComputers