Better CMDB queries
This commit is contained in:
parent
9649f47b8a
commit
d2e224cd69
|
|
@ -1,13 +1,25 @@
|
||||||
function Invoke-EnableComputer ($comp) {
|
function Invoke-EnableComputer ($comp) {
|
||||||
$site = switch -Regex ($comp) {
|
# This if statement attempts to place a workstation at a location. Workstations
|
||||||
'^A' {'SAGH'}
|
# that don't follow the old naming scheme with site indicators are just placed in
|
||||||
'^L' {'SLCH'}
|
# the Samaritan Workstations OU. We could query to see if they are online and use
|
||||||
'^S' {'SNLH'}
|
# the DNS servers to determine what site they are at, but that's too much trouble
|
||||||
'^P' {'SPCH'}
|
# for now
|
||||||
'^G(AV|CN|WN)' {'Avery'}
|
$site = if ($comp -match "^([WL][0-9]{5})|(PACS)") { $null } else {
|
||||||
default {'GSRMC'}
|
switch -Regex ($comp) {
|
||||||
|
'^A' {'SAGH'}
|
||||||
|
'^L' {'SLCH'}
|
||||||
|
'^S' {'SNLH'}
|
||||||
|
'^P' {'SPCH'}
|
||||||
|
'^G(AV|CN|WN)' {'Avery'}
|
||||||
|
'^G(?!AV|CN|WN)' {'GSRMC'}
|
||||||
|
default {$null}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($null -eq $site) {
|
||||||
|
$comp | Get-ADComputer | Enable-ADAccount -PassThru | Move-ADObject -TargetPath "OU=Samaritan Workstations,DC=int,DC=samhealth,DC=net"
|
||||||
|
} else {
|
||||||
|
$comp | Get-ADComputer | Enable-ADAccount -PassThru | Move-ADObject -TargetPath "OU=$site,OU=Samaritan Workstations,DC=int,DC=samhealth,DC=net"
|
||||||
}
|
}
|
||||||
$comp | Get-ADComputer | Enable-ADAccount -PassThru | Move-ADObject -TargetPath "OU=$site,OU=Samaritan Workstations,DC=int,DC=samhealth,DC=net"
|
|
||||||
if (Get-ADUser -Filter "Name -like 'K_$comp'") {
|
if (Get-ADUser -Filter "Name -like 'K_$comp'") {
|
||||||
Write-Host -ForegroundColor Yellow "Kiosk account found. Please re-submit a kiosk request and re-kiosk $comp."
|
Write-Host -ForegroundColor Yellow "Kiosk account found. Please re-submit a kiosk request and re-kiosk $comp."
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,14 @@
|
||||||
|
|
||||||
$timeout = if ($SparkQueryTimeoutSec) {$SparkQueryTimeoutSec} else {5}
|
$timeout = if ($SparkQueryTimeoutSec) {$SparkQueryTimeoutSec} else {5}
|
||||||
Write-Progress -Activity "Retrieving data from $Env:COMPUTERNAME" -Status "Querying Spark! for location details. Timeout $($timeout)s" -PercentComplete 95
|
Write-Progress -Activity "Retrieving data from $Env:COMPUTERNAME" -Status "Querying Spark! for location details. Timeout $($timeout)s" -PercentComplete 95
|
||||||
$uri = "$Tenant/api/odata/businessobject/cis`?`$filter=AssetTag eq '$assetTag'&`$top=1&`$skip=0"
|
$uri = if ($assetTag -ne '') {
|
||||||
|
"$Tenant/api/odata/businessobject/cis`?`$filter=AssetTag eq '$assetTag'"
|
||||||
|
} elseif ($serviceTag){
|
||||||
|
"$Tenant/api/odata/businessobject/cis`?`$filter=SerialNumber eq '$serviceTag'"
|
||||||
|
} else {
|
||||||
|
"$Tenant/api/odata/businessobject/cis`?`$filter=Name eq '$env:ComputerName'&`$top=1&`$skip=0"
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$Query = Invoke-RestMethod -Method GET -uri $uri -headers $Headers -TimeoutSec $timeout
|
$Query = Invoke-RestMethod -Method GET -uri $uri -headers $Headers -TimeoutSec $timeout
|
||||||
if ($Query) {
|
if ($Query) {
|
||||||
|
|
|
||||||
|
|
@ -193,8 +193,18 @@ $Headers = @{
|
||||||
try { $name = $snmp.Get('.1.3.6.1.4.1.10642.1.4.0').toupper() } catch { $name = $null }
|
try { $name = $snmp.Get('.1.3.6.1.4.1.10642.1.4.0').toupper() } catch { $name = $null }
|
||||||
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for model' -PercentComplete 30 -ParentId 2
|
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for model' -PercentComplete 30 -ParentId 2
|
||||||
try { $model = $snmp.Get('.1.3.6.1.4.1.10642.200.19.7.0').toupper() } catch { $model = $null }
|
try { $model = $snmp.Get('.1.3.6.1.4.1.10642.200.19.7.0').toupper() } catch { $model = $null }
|
||||||
|
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for adapter type' -PercentComplete 40 -ParentId 2
|
||||||
|
try { $adapter = $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.5.2.1.5.3') } catch { $adapter = $null }
|
||||||
|
$adapterType = switch ($adapter) {
|
||||||
|
1 { '(Ethernet)' }
|
||||||
|
2 { '(WiFi)' }
|
||||||
|
default { $null }
|
||||||
|
}
|
||||||
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for MAC address' -PercentComplete 50 -ParentId 2
|
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for MAC address' -PercentComplete 50 -ParentId 2
|
||||||
try { $MAC = $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.10.2.1.5.2').toupper() } catch { $MAC = $null }
|
$MAC = switch ($adapter) {
|
||||||
|
2 { try { $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.5.2.1.2.3') } catch { $null } }
|
||||||
|
default { try { $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.5.2.1.2.2') } catch { $null } }
|
||||||
|
}
|
||||||
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for serial number' -PercentComplete 70 -ParentId 2
|
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for serial number' -PercentComplete 70 -ParentId 2
|
||||||
try { $serial = $snmp.Get('.1.3.6.1.4.1.10642.1.9.0') } catch { $serial = $null }
|
try { $serial = $snmp.Get('.1.3.6.1.4.1.10642.1.9.0') } catch { $serial = $null }
|
||||||
if (!$serial) { try { $serial = $snmp.Get('.1.3.6.1.4.1.10642.200.19.5.0') } catch { $serial = $null } }
|
if (!$serial) { try { $serial = $snmp.Get('.1.3.6.1.4.1.10642.200.19.5.0') } catch { $serial = $null } }
|
||||||
|
|
@ -211,6 +221,20 @@ $Headers = @{
|
||||||
7 {'(PERMANENT)'}
|
7 {'(PERMANENT)'}
|
||||||
default {'(UNKNOWN)'}
|
default {'(UNKNOWN)'}
|
||||||
}
|
}
|
||||||
|
<# These settings seem to vary wildly in OID between models
|
||||||
|
$sensorType = try { $snmp.Get('.1.3.6.1.4.1.10642.2.851.1.4.3.0') } catch { 0 }
|
||||||
|
$sensorType = switch ($sensorType) {
|
||||||
|
0 {'WEB'}
|
||||||
|
1 {'MARK'}
|
||||||
|
default {'UNKNOWN'}
|
||||||
|
}
|
||||||
|
$mediaType = try { $snmp.Get('.1.3.6.1.4.1.10642.2.851.1.4.4.0') } catch { 1 }
|
||||||
|
$mediaType = switch ($mediaType) {
|
||||||
|
0 {'CONTINUOUS'}
|
||||||
|
1 {'NON-CONTINUOUS'}
|
||||||
|
default {'UNKNOWN'}
|
||||||
|
}
|
||||||
|
#>
|
||||||
$model = "Zebra $model"
|
$model = "Zebra $model"
|
||||||
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for status' -PercentComplete 90 -ParentId 2
|
Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for status' -PercentComplete 90 -ParentId 2
|
||||||
#STATUS
|
#STATUS
|
||||||
|
|
@ -218,8 +242,6 @@ $Headers = @{
|
||||||
$html = Invoke-WebRequest -uri $uri
|
$html = Invoke-WebRequest -uri $uri
|
||||||
$raw = $html.rawcontent
|
$raw = $html.rawcontent
|
||||||
$raw -match '([A-Z])\w+<.F' | Out-Null
|
$raw -match '([A-Z])\w+<.F' | Out-Null
|
||||||
# Captures the first text between a > and < after "Status:"
|
|
||||||
#$raw -match 'Status:.*>(\w+)<.*>(\w+)<' | Out-Null
|
|
||||||
$status = ($Matches[0] -split '<')[0]
|
$status = ($Matches[0] -split '<')[0]
|
||||||
#split off error condition
|
#split off error condition
|
||||||
$raw -match 'RED>.+' | Out-Null
|
$raw -match 'RED>.+' | Out-Null
|
||||||
|
|
@ -388,7 +410,7 @@ $Headers = @{
|
||||||
Status = $status
|
Status = $status
|
||||||
IP = "$printerip $ipconfig"
|
IP = "$printerip $ipconfig"
|
||||||
DomainName = $domainName
|
DomainName = $domainName
|
||||||
MAC = $MAC
|
MAC = "$MAC $adapterType"
|
||||||
Model = $model
|
Model = $model
|
||||||
Serial = $serial
|
Serial = $serial
|
||||||
#Comment = $comment
|
#Comment = $comment
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ function Invoke-UninstallProgram ($Computer) {
|
||||||
Write-Host "Uninstalling $($apps[$item].Name)"
|
Write-Host "Uninstalling $($apps[$item].Name)"
|
||||||
$res = $apps[$item].Uninstall()
|
$res = $apps[$item].Uninstall()
|
||||||
switch ($res.ReturnValue) {
|
switch ($res.ReturnValue) {
|
||||||
0 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $Computer" }
|
0 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $env:ComputerName" }
|
||||||
1641 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $Computer"; Write-Warning "Restarting $Computer" }
|
1641 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $env:ComputerName"; Write-Warning "Restarting $env:ComputerName" }
|
||||||
3010 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $Computer"; Write-Warning "Please restart $Computer to finish uninstall" }
|
3010 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $env:ComputerName"; Write-Warning "Please restart $env:ComputerName to finish uninstall" }
|
||||||
3011 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $Computer"; Write-Warning "Please restart $Computer to finish uninstall" }
|
3011 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $env:ComputerName"; Write-Warning "Please restart $env:ComputerName to finish uninstall" }
|
||||||
default { Write-Warning "$appname failed to uninstall from $Computer with ReturnValue $($res.ReturnValue). See an MsiExec return value table for more information." }
|
default { Write-Warning "$appname failed to uninstall from $env:ComputerName with ReturnValue $($res.ReturnValue). See an MsiExec return value table for more information." }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
Patch
|
Patch
|
||||||
-Fix Zebra printer statuses report correctly now
|
-Fix Zebra printer statuses report correctly now
|
||||||
-Fix ZD421 printers report Serial numbers correctly
|
-Fix ZD421 printers report Serial numbers correctly
|
||||||
|
-Update Enable now defualts workstations to the Samaritan Workstations OU rather than GSRMC
|
||||||
|
-Update Enable detects L12345 and PACS12345 and places them in the default rather than NLH and PCH OUs
|
||||||
|
-Fix UninstallProgram reports the hostname in the done message rather than blank
|
||||||
|
-Update Zebra printers report Ethernet or wifi. Detection method isn't officially documented by Zebra so could be faulty
|
||||||
|
-Fix PCLocal searches CMDB with the first non-null value in Asset Tag, Serial Number, and Name
|
||||||
|
|
||||||
Patch 2025-5-28
|
Patch 2025-5-28
|
||||||
-Update SCCMQueryBlock uses asset tag to query Spark!
|
-Update SCCMQueryBlock uses asset tag to query Spark!
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue