Bad commit with many changes, see full message
- Fixed wildcard search so Spark can return more than 25 results - Added ports to Dell P2417H monitor in Devices query - Better error messages from hostname resolution step - Better CMDB error messages - Removed NoResolve flag since hostname resolution on correct hostnames isn't very intensive. Considering skipping AD queries or restructuring get-pc so each pc is processed asynchrounously, and each query is processed async (like in BatchInvokes)
This commit is contained in:
parent
c039beac33
commit
2991af9df2
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
.vscode
|
||||
Get-PC VS Code.code-workspace
|
||||
ISMTools
|
||||
MusicPlayer
|
||||
|
|
@ -175,7 +175,7 @@ Function Find-ISMBusinessObject {
|
|||
|
||||
$Skip = $Results.Count
|
||||
|
||||
$URI = "$Tenant/api/odata/businessobject/$BusinessObject`?`$top=100&`$skip=$Skip`$search=$SearchQuery"
|
||||
$URI = "$Tenant/api/odata/businessobject/$BusinessObject`?`$top=100&`$skip=$Skip&`$search=$SearchQuery"
|
||||
|
||||
$SkipQuery = Invoke-RestMethod -Method GET -uri $URI -headers $Headers -TimeoutSec 15
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ function Get-Devices {
|
|||
'DELL P2319H'= @('DP','HDMI','VGA');
|
||||
'DELL P2422H'= @('DP','HDMI','VGA');
|
||||
'DELL P2412H'= @('DP','HDMI','VGA');
|
||||
'DELL P2417H'= @('DP','HDMI','VGA');
|
||||
}
|
||||
|
||||
foreach($item in $monitors){
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ function Get-Hostname ([string]$name) {
|
|||
if (Resolve-DnsName $cmdbData.Name) {
|
||||
Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
|
||||
return $cmdbData.Name,''
|
||||
} else { $errMsg += "CMDB name associated with Asset tag $name doesn't resolve to IP Address"}
|
||||
} else { $errMsg += "Asset tag not in CMDB" }
|
||||
} else { $errMsg += "CMDB name associated with Asset tag $name doesn't resolve to IP Address`n"}
|
||||
} else { $errMsg += "Asset tag not in CMDB`n" }
|
||||
}
|
||||
Write-Progress -Activity "Resolving hostname for $name" -Status 'CMDB MAC Address search' -PercentComplete 80 -ParentId 1
|
||||
if ($name -match "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$") {
|
||||
|
|
@ -85,8 +85,8 @@ function Get-Hostname ([string]$name) {
|
|||
if (Resolve-DnsName $cmdbData.Name) {
|
||||
Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
|
||||
return $cmdbData.Name,''
|
||||
} else { $errMsg += "CMDB name associated with MAC Address $name doesn't resolve to IP Address"}
|
||||
} else { $errMsg += "MAC Address not in CMDB" }
|
||||
} else { $errMsg += "CMDB name associated with MAC Address $name doesn't resolve to IP Address`n"}
|
||||
} else { $errMsg += "MAC Address not in CMDB`n" }
|
||||
}
|
||||
# Serial number
|
||||
Write-Progress -Activity "Resolving hostname for $name" -Status 'CMDB Serial Number search' -PercentComplete 80 -ParentId 1
|
||||
|
|
@ -97,8 +97,8 @@ function Get-Hostname ([string]$name) {
|
|||
if (Resolve-DnsName $cmdbData.Name) {
|
||||
Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
|
||||
return $cmdbData.Name,''
|
||||
} else { $errMsg += "CMDB name associated with Serial Number $name doesn't resolve to IP Address"}
|
||||
} else { $errMsg += "Serial Number not in CMDB" }
|
||||
} else { $errMsg += "CMDB name associated with Serial Number $name doesn't resolve to IP Address`n"}
|
||||
} else { $errMsg += "Serial Number not in CMDB`n" }
|
||||
$errMsg += "Many CMDB matches found`n"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -314,11 +314,22 @@
|
|||
$uri = "$Tenant/api/odata/businessobject/cis`?`$filter=Name eq '$ENV:COMPUTERNAME'&`$top=1&`$skip=0"
|
||||
try {
|
||||
$Query = Invoke-RestMethod -Method GET -uri $uri -headers $Headers -TimeoutSec $timeout
|
||||
if ($Query) {
|
||||
$cmdbData = $Query.Value
|
||||
} else {
|
||||
$cmdbData = @{
|
||||
SHS_LocationDetails = "CMDB Mismatch!"
|
||||
Status = "CMDB Mismatch!"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
#Write-Host $_.Exception.Message
|
||||
Write-Warning "Failed querying Spark!"
|
||||
#Write-Warning "Failed querying Spark!"
|
||||
$cmdbData = @{
|
||||
SHS_LocationDetails = "Failed querying Spark!"
|
||||
Status = "Failed querying Spark!"
|
||||
}
|
||||
}
|
||||
$cmdbData = $Query.Value
|
||||
|
||||
$LocationConstructors = @(
|
||||
"SHS_AssetLocality",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ Function Get-SCCMQueryBlock {
|
|||
[int]$PCID = 1
|
||||
)
|
||||
#CONST
|
||||
$SITENAME="100"
|
||||
$SCCMSERVER="shscm01.int.samhealth.net"
|
||||
$SCCMNAMESPACE="root\sms\site_100"
|
||||
# Spark connection params
|
||||
|
|
@ -242,14 +241,25 @@ $Headers = @{
|
|||
Write-Progress -Activity "Getting SCCM data for $comp" -Status 'Querying for CMDB data' -PercentComplete $progress -ParentID 0 -Id $PCID
|
||||
|
||||
$timeout = if ($SparkQueryTimeoutSec) {$SparkQueryTimeoutSec} else {5}
|
||||
$uri = "${using:Tenant}/api/odata/businessobject/cis`?`$filter=Name eq '$comp'&`$top=1&`$skip=0"
|
||||
$uri = "$Tenant/api/odata/businessobject/cis`?`$filter=Name eq '$comp'&`$top=1&`$skip=0"
|
||||
try {
|
||||
$Query = Invoke-RestMethod -Method GET -uri $uri -headers ${using:Headers} -TimeoutSec $timeout
|
||||
$Query = Invoke-RestMethod -Method GET -uri $uri -headers $Headers -TimeoutSec $timeout
|
||||
if ($Query) {
|
||||
$cmdbData = $Query.Value
|
||||
} else {
|
||||
$cmdbData = @{
|
||||
Loc = "CMDB Mismatch!"
|
||||
Status = "CMDB Mismatch!"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
#Write-Host $_.Exception.Message
|
||||
Write-Warning "Failed querying Spark!"
|
||||
#Write-Warning "Failed querying Spark!"
|
||||
$cmdbData = @{
|
||||
Loc = "Failed querying Spark!"
|
||||
Status = "Failed querying Spark!"
|
||||
}
|
||||
}
|
||||
$cmdbData = $Query.Value
|
||||
|
||||
$LocationConstructors = @(
|
||||
"SHS_AssetLocality",
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ Function Get-PC {
|
|||
-LogOffUser | remotely logs off user
|
||||
-Monitor | monitors computers for changes in status
|
||||
-NextPrinterName | generates next open printer name
|
||||
-NoResolve | skips hostname resolution, assumes provided name is a hostname
|
||||
-Orion | opens orion to the mac address of the pc
|
||||
-PatchNotes | read the patch notes
|
||||
-PCCleanup | removes temp files and inactive user profiles
|
||||
|
|
@ -130,7 +129,6 @@ Function Get-PC {
|
|||
[Switch]$LogOffUser,
|
||||
[Switch]$Monitor,
|
||||
[Switch]$NextPrinterName,
|
||||
[Switch]$NoResolve,
|
||||
[switch]$Orion,
|
||||
[Switch]$PatchNotes,
|
||||
[Switch]$PCCleanup,
|
||||
|
|
@ -188,7 +186,7 @@ begin {
|
|||
if ($Update) {
|
||||
#updates get pc
|
||||
Update-GetPC
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
if ($PatchNotes) {
|
||||
|
|
@ -202,7 +200,7 @@ begin {
|
|||
#runs the printer query as a set of jobs
|
||||
$outPutArray = Get-PCBatchJob($ComputerName) -printers
|
||||
Write-Output $outPutArray
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
if($locationSearch){
|
||||
|
|
@ -212,34 +210,27 @@ begin {
|
|||
Write-Host "Searching CMDB for $searchInput ..."
|
||||
if($searchInput.ToCharArray().Length -lt 3){
|
||||
Write-Host 'Location searches much contain more than 2 characters' -ForegroundColor Yellow
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
$searchResults = Search-CMDB -Location $searchInput | Sort-Object -Property Hostname
|
||||
if($null -eq $searchResults){
|
||||
Write-Host 'No results for given search' -ForegroundColor Yellow
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
Write-Output $searchResults
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
#Generates an available printer hostname. Useful for supplying a new hostname in new printer requests
|
||||
if ($NextPrinterName) {
|
||||
Find-NextPrinterName $ComputerName[0]
|
||||
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
|
||||
break
|
||||
}
|
||||
Write-Host "Starting CMDB Wildcard Search..."
|
||||
# $searchResults = Search-CMDB -hostname $ComputerName.Replace('*','') | Sort-Object -Property Hostname
|
||||
|
|
@ -254,8 +245,15 @@ begin {
|
|||
if($TableView){
|
||||
$output | Out-GridView -Title 'Get-PC Wildcard Search'
|
||||
}
|
||||
return $output
|
||||
#return $output
|
||||
Write-Output $output
|
||||
break
|
||||
}
|
||||
|
||||
#Generates an available printer hostname. Useful for supplying a new hostname in new printer requests
|
||||
if ($NextPrinterName) {
|
||||
Find-NextPrinterName $ComputerName[0]
|
||||
break
|
||||
}
|
||||
|
||||
$getPCComputers = @() #List of computers that will get a batch query
|
||||
|
|
@ -275,9 +273,7 @@ begin {
|
|||
continue
|
||||
}
|
||||
|
||||
if (-not ($NoResolve)) {
|
||||
$comp,$msg = Get-Hostname $comp
|
||||
}
|
||||
Write-Progress -Activity "Get-PC flags processing" -Status "$comp ($PCID/$NumberofComputers)" -PercentComplete ($PCID*100/$NumberOfComputers) -Id 1
|
||||
if ($msg -and -not $SHSPrinter) {
|
||||
if ($SoundEnabled) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
Path: 2024-10-24
|
||||
Patch:
|
||||
-Add Powershell input pipeline support, unoptimized
|
||||
-Add CMDB fields now hold Spark warnings rather than printing to console in SCCM and normal queries
|
||||
-Add ports for DELL P2417H in Devices query
|
||||
|
||||
Patch: 2024-10-24
|
||||
-Fix Enable flag also removes workstation from Disabled Computers group
|
||||
-Update Orion url
|
||||
-Perf. Devices and Unplugged Devices are now 70% faster!
|
||||
|
|
|
|||
Loading…
Reference in a new issue