Refactored main, currently broke job system but there is a plan to rework the job system
This commit is contained in:
parent
61038d43e5
commit
e17f7e6ba3
|
|
@ -78,6 +78,9 @@ function Get-Devices {
|
|||
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
|
||||
$out += $item
|
||||
}
|
||||
$item = [PSCustomObject]@{ }
|
||||
$item.PSObject.TypeNames.Insert(0,'GetPC.Devices')
|
||||
$out += $item
|
||||
|
||||
Write-Output $out
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,30 @@
|
|||
function Get-Hostname ([string]$name) {
|
||||
$errMsg = ''
|
||||
if ($name.Length -eq 5) {
|
||||
$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
|
||||
if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") {
|
||||
$res = Resolve-DnsName $name
|
||||
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) {
|
||||
$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
|
||||
if ($name -match "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$") {
|
||||
$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
|
||||
}
|
||||
|
|
@ -8,8 +8,12 @@
|
|||
Write-Host "Current Hostname: $ComputerName"
|
||||
$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
|
||||
} else {
|
||||
Write-Host "Failed to rename PC. Check user credentials" -ForegroundColor Red
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@
|
|||
} elseif ($site -eq $numSites) {
|
||||
$BackupDestination = Read-Host "Enter a PC asset, hostname, or custom path"
|
||||
# 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
|
||||
if (Test-Connection -ComputerName $BackupDestination -Count 1) {
|
||||
# If so, get the filesystem path
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#region Module Import Block
|
||||
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
#$ErrorActionPreference = 'SilentlyContinue'
|
||||
#DevStage can take either Dev or Prod as values
|
||||
$devStage = 'Dev'
|
||||
#Locations for dev build and prod build
|
||||
|
|
@ -53,7 +53,6 @@ Function Get-PC {
|
|||
-PCReboot | reboots computer
|
||||
-PCRename | renames computer
|
||||
-RemoteDesktopApp | remote into computer using RDP
|
||||
-RequestLauncher | starts request launcher
|
||||
-ResetRepository | remotely resets repository
|
||||
-Resources | more details about system resources
|
||||
-PrinterPurge | removes printer from all online computers
|
||||
|
|
@ -104,7 +103,6 @@ Function Get-PC {
|
|||
[Switch]$PCRename,
|
||||
[Switch]$Quiet,
|
||||
[Switch]$RemoteDesktopApp,
|
||||
[Switch]$RequestLauncher,
|
||||
[Switch]$Resources,
|
||||
[Switch]$ResetRepository,
|
||||
[Switch]$PrinterPurge,
|
||||
|
|
@ -127,35 +125,6 @@ Function Get-PC {
|
|||
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
|
||||
if ($Update) {
|
||||
#updates get pc
|
||||
|
|
@ -163,9 +132,6 @@ Function Get-PC {
|
|||
return
|
||||
}
|
||||
|
||||
$NumberofComputers = $ComputerName.Count
|
||||
foreach ($comp in $ComputerName) {
|
||||
|
||||
if ($PatchNotes) {
|
||||
$scriptparent = (get-item $PSScriptRoot ).parent.FullName
|
||||
Write-Host "`n"
|
||||
|
|
@ -173,6 +139,13 @@ Function Get-PC {
|
|||
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
|
||||
if ($SHSUser) {
|
||||
$user = Get-SHSUser $comp
|
||||
|
|
@ -181,16 +154,9 @@ Function Get-PC {
|
|||
}
|
||||
|
||||
$oldcomp = $comp
|
||||
$comp = Get-Hostname $comp
|
||||
if (($oldcomp -eq $comp) -and (($comp.length -eq 5 -and !$SHSPrinter) -or ($comp.length -eq 7))) {
|
||||
if ($comp.length -eq 5 -and !$SHSPrinter) {
|
||||
$msg = "$comp Asset Tag not in SMBIOS or CMDB"
|
||||
$comp,$msg = Get-Hostname $comp
|
||||
if ($msg) {
|
||||
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]@{
|
||||
Hostname = "$msg"
|
||||
|
|
@ -256,7 +222,7 @@ Function Get-PC {
|
|||
else {
|
||||
Write-Output $out
|
||||
}
|
||||
break
|
||||
continue
|
||||
}
|
||||
|
||||
if ($PrinterPurge) {
|
||||
|
|
@ -264,12 +230,6 @@ Function Get-PC {
|
|||
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
|
||||
if ($NextPrinterName) {
|
||||
Find-NextPrinterName $comp
|
||||
|
|
@ -350,11 +310,11 @@ Function Get-PC {
|
|||
|
||||
if ($compStatus -ne 'Online') {
|
||||
Write-Warning "$comp is $compStatus unable to proccess command"
|
||||
break
|
||||
continue
|
||||
}
|
||||
|
||||
Get-ResetRepository $comp
|
||||
break
|
||||
continue
|
||||
}
|
||||
|
||||
#Backs up user profile to specified destination
|
||||
|
|
@ -415,7 +375,7 @@ Function Get-PC {
|
|||
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) {
|
||||
Get-Apps $comp $TableView
|
||||
continue
|
||||
|
|
@ -473,7 +433,7 @@ Function Get-PC {
|
|||
}
|
||||
|
||||
Get-ViewerRemote $comp
|
||||
continue
|
||||
break
|
||||
}
|
||||
|
||||
#Runs Remote Desktop Connection Application
|
||||
|
|
@ -568,8 +528,6 @@ Function Get-PC {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Monitor list of PCs for change in online status or
|
||||
if ($Monitor) {
|
||||
Invoke-PCMonitor $getPCComputers
|
||||
|
|
|
|||
Loading…
Reference in a new issue