From 29e6749316cabd44939a79f50aa70b418f221bf9 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Fri, 26 Jul 2024 14:13:08 -0700 Subject: [PATCH 1/3] Starting Spark integration --- Private/Spark.ps1 | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Private/Spark.ps1 diff --git a/Private/Spark.ps1 b/Private/Spark.ps1 new file mode 100644 index 0000000..d99bdd0 --- /dev/null +++ b/Private/Spark.ps1 @@ -0,0 +1,45 @@ +$SparkHeaders = @{ + "Content-Type" = "application/json" + "Authorization" = "" + "Accept" = "*/*" + "Accept-Encoding" = "gzip, deflate, br" +} + +$SparkTenantPrefix = "samaritanhealth-amc" +$SparkURL = "https://$SparkTenantPrefix.ivanticloud.com" + +Function Connect-ISM { + try { + #Try a fast route to check if authorization headers are set properly + Invoke-RestMethod -Method Get -URI "$SparkURL/api/odata" -Headers $SparkHeaders + } catch { + $errobject = ConvertFrom-Json $_ + #A 404 means we were authorized and didn't find anything, as intended! + if ($errobject.code -eq "ISM_4004") { return } + #Anything other than a 401 Unauthorized is unexpected, attempt to handle gracefully + if ($errobject.code -ne "ISM_4001") { + Write-Host -ForegroundColor Red "Unexpected error connecting to Spark!" + Write-Host -ForegroundColor Red "$errobject" + $SparkHeaders["Authorization"] = "" + return + } + #Unuathorized response, so let's update our authorization! + if ( $SparkHeaders["Authorization"] ) { + Write-Host "Spark Authorization key expired, please update key" + } + $authKey = Read-Host "Login to Spark, open browser dev tools, and paste SID cookie here, or an API key if you have one" + if ($authKey -match "[0-9A-F](32)") { + $SparkHeaders["Authorization"] = "rest_api_key=$authKey" + } elseif ($authKey -match "$($SparkURL.split('/')[-1])#.*#") { + $SparkHeaders["Authorization"] = $authKey + } else { + Write-Host -ForegroundColor Yellow "Authorization key not a recognized key format" + $SparkHeaders["Authorization"] = "" + } + } +} + +Function Check-SparkEnabled { + return -not -not $SparkHeaders["Authorization"] +} + From 5508b8fadc34d0ef57ef1ebd814f54e37deae602 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Tue, 30 Jul 2024 13:25:32 -0700 Subject: [PATCH 2/3] Spark now utilized for CMDB Fallback --- Private/Get-CMDBDELInfo.ps1 | 6 ++-- Private/Get-CMDBFallback.ps1 | 68 ++++++++++++++---------------------- Private/Spark.ps1 | 10 ++++++ Public/Get-PC.ps1 | 4 ++- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/Private/Get-CMDBDELInfo.ps1 b/Private/Get-CMDBDELInfo.ps1 index 9de7307..ffe65df 100644 --- a/Private/Get-CMDBDELInfo.ps1 +++ b/Private/Get-CMDBDELInfo.ps1 @@ -7,7 +7,7 @@ function Get-CMDBDELInfo { if($null -eq $cmdb){ return } - if($cmdb.values.ConfigurationItem._SHSVendorPC -eq 'True'){ + if($cmdb.SHS_IsVendorPC -eq 'True'){ $vendor = "Yes | Non-standard SHS Image/Hardware" } else{ @@ -15,9 +15,9 @@ function Get-CMDBDELInfo { } $delInfo = [PSCustomObject]@{ - Owner = $cmdb.values.ConfigurationItem._SHSAssetOwner + Contact = $cmdb.SHS_ExceptionContact Vendor = $vendor - Description = $cmdb.values.ConfigurationItem._Description + Description = $cmdb.AssignedDescription } return $delInfo diff --git a/Private/Get-CMDBFallback.ps1 b/Private/Get-CMDBFallback.ps1 index 59e9b72..e66f3d4 100644 --- a/Private/Get-CMDBFallback.ps1 +++ b/Private/Get-CMDBFallback.ps1 @@ -3,48 +3,34 @@ function Get-CMDBFallback { $comp ) - $cmdbData = Get-LANDeskCMDBItem -name $comp + #$cmdbData = Get-LANDeskCMDBItem -name $comp + $cmdbData = Search-SparkCIs $comp - if(!$cmdbData){ - if($comp.Length -gt 5){ - $asset = $comp[-5..-1] -join "" - $cmdbData = Get-LANDeskCMDBItem -AssetTag $asset - if($cmdbData){ - $comp = $cmdbData.values.Title - if(Test-Connection $comp){ - $getpcData = get-pc $comp - return $getpcData - } - } - } - } - $status = $cmdbData.values.Status + $status = $cmdbData.Status if(!$status){ $status = 'No CMDB/SCCM Record Located' } else{ - $status = $cmdbData.values.Status + ' (CMDB Data)' + $status = $cmdbData.Status + ' (CMDB Data)' } - if($cmdbData.values._SHSLocation3.Length -gt $cmdbData.values._SHSCalcLocationString.Length){ - $locationData = $cmdbData.values._SHSLocation3 - } - else{ - $locationData = $cmdbData.values._SHSCalcLocationString - } - if($cmdbData.values._ConfigTypesCategory -eq 'Mobile Device'){ + $locationData = $cmdbData.SHS_Floor + ' - ' + $cmdbData.SHS_Department + ' - ' + $cmdbData.LocationDetails + + $phoneNumber = $cmdbData.LoginName + + if($cmdbData.CIType -eq 'MobileDevice'){ $props = [Ordered]@{ - Hostname = $cmdbData.values.Title - 'MAC' = $cmdbData.values._SHSMACAddress - Model = $cmdbData.values._Model + ' (' + $cmdbData.Values._SHSChasisRef + ')' - 'OS' = $cmdbData.Values._SHSOperatingSystem - 'Asset Tag' = $cmdbData.values._SHSAssetTag - 'Service Tag' = $cmdbData.values._SerialNumber - 'MDM Platform' = $cmdbData.values._SHSMDMPlatform - 'Phone Number' = $cmdbData.values._SHSPhoneNumber - 'Cellular Carrier' = $cmdbData.values._SHSCellularCarrier - 'Cellular Voice' = $cmdbData.values._SHSCellularVoice - 'Cellular Data' = $cmdbData.values._SHSCellularData + Hostname = $cmdbData.Name + 'MAC' = $cmdbData.MACAddress + Model = $cmdbData.Model + ' (' + $cmdbData.ChassisType + ')' + 'OS' = $cmdbData.OperatingSystem + 'Asset Tag' = $cmdbData.AssetTag + 'Service Tag' = $cmdbData.SerialNumber + 'MDM Platform' = $cmdbData.SHS_MdmPlatform + 'Phone Number' = $cmdbData.PhoneNumber #TODO fix this, idk why Spark! doesn't return this + 'Cellular Carrier' = $cmdbData.SHS_Carrier + 'Cellular Voice' = $cmdbData.SHS_IsCellularVoice + 'Cellular Data' = $cmdbData.SHS_IsCellularData 'CMDB Location' = $locationData } @@ -56,9 +42,9 @@ function Get-CMDBFallback { Status = $status 'Current User' = "Not Available" 'Last User(s)' = $null - 'IP | MAC' = $cmdbData.values._IPAddress + " | " + $cmdbData.values._SHSMACAddress - Model = $cmdbData.values._Model + ' (' + $cmdbData.Values._SHSChasisRef + ')' - 'OS' = $cmdbData.Values._SHSOperatingSystem + 'IP | MAC' = $cmdbData.IPAddress + " | " + $cmdbData.MACAddress + Model = $cmdbData.Model + ' (' + $cmdbData.ChassisType + ')' + 'OS' = $cmdbData.OperatingSystem 'OS Build' = $null 'BIOS Ver' = $null Encryption = $null @@ -66,8 +52,8 @@ function Get-CMDBFallback { RAM = $cmdbData.Values._RAM + " GB " 'SSO Client' = "Not Available" 'Kiosk Role' = "Not Available" - 'Asset Tag' = $cmdbData.values._SHSAssetTag - 'Service Tag' = $cmdbData.values._SerialNumber + 'Asset Tag' = $cmdbData.AssetTag + 'Service Tag' = $cmdbData.SerialNumber 'Last Reboot' = $null Printers = $null 'CMDB Location' = $locationData @@ -78,9 +64,9 @@ function Get-CMDBFallback { Write-Host "`n`nPulling cached CMDB data for $comp." -ForegroundColor Yellow Write-Host "Last CMDB Update: ",$cmdbData.values.LastUpdate -ForegroundColor Yellow - if($cmdbData.values.ConfigurationItem._SHSDELAsset -eq 'True'){ + if($cmdbData.SHS_IsException -eq 'True'){ $delInfo = Get-CMDBDELInfo $cmdbData - $obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $delInfo.Owner + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $delInfo.Contact $obj | Add-Member -MemberType NoteProperty -Name 'DEL Vendor PC' -Value $delInfo.Vendor $obj | Add-Member -MemberType NoteProperty -Name 'DEL Description' -Value $delInfo.Description } diff --git a/Private/Spark.ps1 b/Private/Spark.ps1 index d99bdd0..c3fa75d 100644 --- a/Private/Spark.ps1 +++ b/Private/Spark.ps1 @@ -43,3 +43,13 @@ Function Check-SparkEnabled { return -not -not $SparkHeaders["Authorization"] } +Function Search-SparkCIs($CIName) { + Connect-ISM + $uri = "$SparkURL/api/odata/businessobject/CIs`?`$filter=Name+eq+%27$CIName%27&`$top=100&`$skip=0" + try{ + $Query = Invoke-RestMethod -Method GET -uri $uri -headers $SparkHeaders + } catch { + $ExceptionErrors += $_.Exception.Message + } + return $Query.Value +} diff --git a/Public/Get-PC.ps1 b/Public/Get-PC.ps1 index c817143..d4893aa 100644 --- a/Public/Get-PC.ps1 +++ b/Public/Get-PC.ps1 @@ -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 @@ -27,6 +27,8 @@ if ($Version -ne $deployedVersion) { Write-Host 'New version of Get-PC is available. Please run Get-PC -Update' -ForegroundColor Yellow } Write-Host "Enter 'Help Get-PC' for available commands.`n" -ForegroundColor Green + +if ($(Read-Host "Enable Spark features? (y/N)") -match "^y") { Connect-ISM } #endregion Function Get-PC { From f3e8186b1c23247c3ff48916dc187fadc4309c7b Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Fri, 2 Aug 2024 12:03:04 -0700 Subject: [PATCH 3/3] Spark, yay! --- Private/BatchInvokes.ps1 | 38 ++++ Private/Connect-LANDesk.ps1 | 37 ---- Private/Get-CMDBFallback.ps1 | 4 +- Private/Get-LANDeskCMDBItem.ps1 | 103 --------- Private/PCLocal.ps1 | 16 ++ Private/Search-CMDB.ps1 | 124 ----------- Private/Set-CMDBLocation.ps1 | 368 -------------------------------- Private/Spark.ps1 | 8 +- Public/Get-PC.ps1 | 7 +- patchnotes.txt | 6 + 10 files changed, 71 insertions(+), 640 deletions(-) delete mode 100644 Private/Connect-LANDesk.ps1 delete mode 100644 Private/Get-LANDeskCMDBItem.ps1 delete mode 100644 Private/Search-CMDB.ps1 delete mode 100644 Private/Set-CMDBLocation.ps1 diff --git a/Private/BatchInvokes.ps1 b/Private/BatchInvokes.ps1 index 5f90c83..2b1d24e 100644 --- a/Private/BatchInvokes.ps1 +++ b/Private/BatchInvokes.ps1 @@ -5,6 +5,8 @@ function Get-PCBatchInvoke { [string[]] $Computers ) + $SparkEnabled = Get-SparkEnabled + if ($SparkEnabled) { Connect-ISM } #Region Script Block $sblock = { Write-Progress -Activity "Retrieving data from online computers" -Status $Env:COMPUTERNAME -PercentComplete 10 @@ -300,6 +302,34 @@ function Get-PCBatchInvoke { Default {$chassisType = "Unknown Model/Chassis"} } + if (${using:SparkEnabled}) { + $uri = "${using:SparkURL}/api/odata/businessobject/CIs`?`$filter=Name+eq+%27$($Env:COMPUTERNAME)%27" + try{ + $Query = Invoke-RestMethod -Method GET -uri $uri -headers ${using:SparkHeaders} + } catch { + $ExceptionErrors += $_.Exception.Message + } + $cmdbData = $Query.Value + + if ($cmdbData.SHS_IsException -eq 'True') { + Write-host "***NOTICE: $($Env:COMPUTERNAME) is a Device Exception computer. Please check CMDB/Asset Mgmt prior to supporting this workstation. ***" -BackgroundColor Black -ForegroundColor Yellow + if($cmdb.SHS_IsVendorPC -eq 'True'){ + $vendor = "Yes | Non-standard SHS Image/Hardware" + } + else{ + $vendor = "No | Standard SHS Hardware" + } + + $delInfo = [PSCustomObject]@{ + Contact = $cmdbData.SHS_ExceptionContact + Vendor = $vendor + Description = $cmdbData.AssignedDescription + } + } + + $locationData = $cmdbData.SHS_Floor + ' - ' + $cmdbData.SHS_Department + ' - ' + $cmdbData.SHS_LocationDetails + } + Write-Progress -Activity "Retrieving data from online computers" -Status $Env:COMPUTERNAME -PercentComplete 90 #Output @@ -328,6 +358,14 @@ function Get-PCBatchInvoke { $obj | Add-Member -MemberType NoteProperty -Name 'TPM Status' -Value "$tpmStatus" $obj | Add-Member -MemberType NoteProperty -Name 'MBAM GPO' -Value "$gpostatus" $obj | Add-Member -MemberType NoteProperty -Name 'Printers' -Value "$printers" + if (${using:SparkEnabled}) { + $obj | Add-Member -MemberType NoteProperty -Name 'CMDB Location' -Value "$locationData" + } + if ($delInfo) { + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $delInfo.Contact + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Vendor PC' -Value $delInfo.Vendor + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Description' -Value $delInfo.Description + } return $obj } diff --git a/Private/Connect-LANDesk.ps1 b/Private/Connect-LANDesk.ps1 deleted file mode 100644 index 9d3f38c..0000000 --- a/Private/Connect-LANDesk.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -function Connect-LANDesk { - [CmdletBinding()] - param ( - [Parameter(HelpMessage = 'The Server of landesk', - Mandatory = $false)] - [string]$server = "shsldapp1", - [Parameter(HelpMessage = 'The Framework', - Mandatory = $false)] - [string]$framework = "ServiceDeskAPI", - [Parameter(HelpMessage = 'The Framework', - Mandatory = $false)] - [string]$username = $env:username, - [Parameter(HelpMessage = 'The password used to connect', - Mandatory = $false)] - [String]$Pass = '' - ) - if($env:username -like "jrodriguez.adm"){ - $username = "jorodriguez" - } - elseif($env:username -like "*.adm"){ - $username = $env:USERNAME.Split('.')[0] - } - else{ - $username = "$env:username" - } - $pair = "$($username):$($Pass)" - $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) - $basicAuthValue = "Basic $encodedCreds" - $headers = @{} - $headers["Authorization"] = $basicAuthValue - $headers["Accept"] = "application/landesk.ldms.base+json,application/json" - $headers["Accept-Language"] = "en-US,en;q=0.8" - - Return $headers, $server, $framework -} - - diff --git a/Private/Get-CMDBFallback.ps1 b/Private/Get-CMDBFallback.ps1 index e66f3d4..c3229c3 100644 --- a/Private/Get-CMDBFallback.ps1 +++ b/Private/Get-CMDBFallback.ps1 @@ -4,7 +4,7 @@ function Get-CMDBFallback { ) #$cmdbData = Get-LANDeskCMDBItem -name $comp - $cmdbData = Search-SparkCIs $comp + $cmdbData = Get-SparkCI $comp $status = $cmdbData.Status if(!$status){ @@ -14,7 +14,7 @@ function Get-CMDBFallback { $status = $cmdbData.Status + ' (CMDB Data)' } - $locationData = $cmdbData.SHS_Floor + ' - ' + $cmdbData.SHS_Department + ' - ' + $cmdbData.LocationDetails + $locationData = $cmdbData.SHS_Floor + ' - ' + $cmdbData.SHS_Department + ' - ' + $cmdbData.SHS_LocationDetails $phoneNumber = $cmdbData.LoginName diff --git a/Private/Get-LANDeskCMDBItem.ps1 b/Private/Get-LANDeskCMDBItem.ps1 deleted file mode 100644 index c03d4e4..0000000 --- a/Private/Get-LANDeskCMDBItem.ps1 +++ /dev/null @@ -1,103 +0,0 @@ -function Get-LANDeskCMDBItem { - [CmdletBinding(DefaultParameterSetName="Default")] - param ( - [Parameter(HelpMessage = 'Search LANDesk CMDB by the Name of the CMDM Item', - ParameterSetName = 'Title', - Mandatory = $true - )] - [string]$Name, - [Parameter(HelpMessage = 'Search LANDesk CMDB by the Configuration Item Type', - ParameterSetName = '_ConfigTypesCategory', - Mandatory = $true - )] - [string]$CIType, - [Parameter(HelpMessage = 'Search for the CMDB Item by Asset Tag Number', - ParameterSetName = '_SHSAssetTag', - Mandatory = $true - )] - [string]$AssetTag, - [Parameter(HelpMessage = 'Search for the Request by Current Assigned Group in LANDesk', - ParameterSetName = 'Default', - Mandatory = $false, - DontShow = $true - )] - [switch]$All, - [Parameter(HelpMessage = 'Specifying Server', - Mandatory = $false, - DontShow = $true)] - [string] $server = $(Connect-LANDesk)[1], - [Parameter(HelpMessage = 'Specifying LanDesk Framework for api', - Mandatory = $false, - DontShow = $true)] - [string] $framework = $(Connect-LANDesk)[2], - [Parameter(HelpMessage = 'Specifying LanDesk Headers for api', - Mandatory = $false, - DontShow = $true)] - [hashtable] $Headers = $(Connect-LANDesk)[0] - ) - - begin { - } - - process { - $uri = 'http://' + $server + '/' + $framework + '/api/' - #$SearchURI = $uri + 'query/?class_name=_CMDBManagement.Call&page_size=20000000&attributes=Title,_ConfigTypesCategory,Status,_SHSDeleted,_SHSDeployedTo,_SHSCIPrimaryOwner,_PO,_SHSAssetTag,_CILocation,_RequestID,_IPAddress,_SerialNumber,_Department,_Model,_Manufacture,_SHSTier,_SHSAssetOwner,_SHSLocation3,_SHSWarrantyExpires,_SHSPOANumber,_SHSEpicPrinterWorkflow,_SHSLastAuditDate,_SHSEnvironment,Description,_IncidentQueue,_RequestQueue,_SHSCINotes,CreationDate,CreationUser,LastUpdate,LastUpdateUser,_SHSOperatingSystem,_SHSChassisType,_HardDiskSize,_RAM,_AvailableDiskSpace,_Model,_SHSKioskRoleName,_SerialNumber,_IPAddress,_SHSOSPatching,_SHSPatchSchedule,_SHSPatchNotes,_SHSDeviceExceptionContact,_SHSDeviceExceptionContact,_DisplayName&V=*' - $SearchURI = $uri + 'query/?class_name=_CMDBManagement.Call&page_size=20000000&attributes=Title,_ConfigTypesCategory,ConfigurationItem._Description,_SHSCalcLocationString,_SHSPhoneNumber,_SHSMDMPlatform,_SHSCellularCarrier,_SHSCellularVoice,_SHSCellularData,ConfigurationItem._SHSDELAsset,ConfigurationItem._SHSVendorPC,ConfigurationItem._SHSAssetOwner,Status,_SHSDeleted,_SHSDeployedTo,_SHSCIPrimaryOwner,_PO,_SHSAssetTag,_CILocation,_RequestID,_IPAddress,_SerialNumber,_Department,_Model,_Manufacture,_SHSTier,_SHSAssetOwner,_SHSLocation3,_SHSWarrantyExpires,_SHSPOANumber,_SHSEpicPrinterWorkflow,_SHSLastAuditDate,_SHSEnvironment,Description,_IncidentQueue,_RequestQueue,_SHSCINotes,CreationDate,CreationUser,LastUpdate,LastUpdateUser,_SHSOperatingSystem,_SHSChassisType,_SHSChasisRef,_HardDiskSize,_RAM,_AvailableDiskSpace,_Model,_SHSKioskRoleName,_SerialNumber,_IPAddress,_SHSMACAddress,_LocationDetails,_DisplayName&V=*' - - if (($PSCmdlet.ParameterSetName -ne "Default") -and ($PSCmdlet.ParameterSetName -ne "_ConfigTypesCategory") ) { - $FinalUri = $SearchURI + '&cns=' + $PSCmdlet.ParameterSetName + '-e-0-_a__SHSDeleted-e-1&c0=' + $PSBoundParameters.Values + '&c1=False' - } - elseif ($PSCmdlet.ParameterSetName -eq "_ConfigTypesCategory") { - if ($PSBoundParameters.Values -eq 'Workstation') { - $FinalUri = $SearchURI + '&cns=' + $PSCmdlet.ParameterSetName + '-e-0-_a__SHSDeleted-e-1&c0=' + '9dadd9f9-ca5d-4be6-93cc-6c8745fff615' + '&c1=False' - } - else { - # Printer - $FinalUri = $SearchURI + '&cns=' + $PSCmdlet.ParameterSetName + '-e-0-_a__SHSDeleted-e-1&c0=' + 'd1e6d576-a18f-4703-b431-c859f1c222ee' + '&c1=False' - } - - } - else { - Write-Verbose "DEfault" - $FinalUri = $SearchURI - } - - $SearchResults = (Invoke-RestMethod -Uri $FinalUri -Headers $headers -Method get).DataRows - - - - - return $SearchResults - } - - end { - } -} - - -function Get-CMDBData { - [CmdletBinding()] - param ( - [Parameter()] - [string] - $comp, - - [string] - $asset - ) - - if($asset -match "\w \w"){ - $asset = $asset -split ' ' - $asset = $asset[0] - } - - $cmdb = Get-LANDeskCMDBItem -Name $comp - if ($null -eq $cmdb){ - try { $cmdb = Get-LANDeskCMDBItem -AssetTag $asset} catch{ $cmdb = $null } - - } - - - return $cmdb - -} diff --git a/Private/PCLocal.ps1 b/Private/PCLocal.ps1 index 8f1fd58..68295a7 100644 --- a/Private/PCLocal.ps1 +++ b/Private/PCLocal.ps1 @@ -124,6 +124,14 @@ $compFreeSpaceMB = "$compFreeSpaceMB" + ' MB' $compFreeSpaceGB = "$compFreeSpaceGB" + ' GB' $compMemory = "$compMemory" + ' GB' + + if (Get-SparkEnabled) { + $cmdbData = Get-SparkCI $ENV:ComputerName + $locationData = $cmdbData.SHS_Floor + ' - ' + $cmdbData.SHS_Department + ' - ' + $cmdbData.SHS_LocationDetails + if($cmdbData.SHS_IsException -eq 'True'){ + $delInfo = Get-CMDBDELInfo $cmdbData + } + } $i++ | ProgressBar $i $comp "Generating Output" $NumberofComputers $PCID @@ -153,6 +161,14 @@ } $obj = New-Object -TypeName PSObject -Property $props + if ($locationData) { + $obj | Add-Member -MemberType NoteProperty -Name 'CMDB Location' -Value $locationData + } + if ($delInfo) { + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $delInfo.Contact + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Vendor PC' -Value $delInfo.Vendor + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Description' -Value $delInfo.Description + } return $obj } diff --git a/Private/Search-CMDB.ps1 b/Private/Search-CMDB.ps1 deleted file mode 100644 index e8ba2bc..0000000 --- a/Private/Search-CMDB.ps1 +++ /dev/null @@ -1,124 +0,0 @@ -function Search-CMDB{ - - [CmdletBinding()] - param ( - - [Parameter(HelpMessage = 'Search LANDesk CMDB by the Name of the CMDM Item' - )] - [string]$Hostname, - - [Parameter(HelpMessage = 'Search for the CMDB Item by Asset Tag Number' - )] - [string]$AssetTag, - - [Parameter(HelpMessage = 'Search for the CMDB Item by Location' - )] - [string]$Location, - - [Parameter(HelpMessage = 'Search for the CMDB Item by Guid/Key' - )] - [string]$key, - - [Parameter(HelpMessage = 'Specifying Server', - Mandatory = $false, - DontShow = $true)] - [string] $server = $(Connect-LANDesk)[1], - [Parameter(HelpMessage = 'Specifying LanDesk Framework for api', - Mandatory = $false, - DontShow = $true)] - [string] $framework = $(Connect-LANDesk)[2], - [Parameter(HelpMessage = 'Specifying LanDesk Headers for api', - Mandatory = $false, - DontShow = $true)] - [hashtable] $Headers = $(Connect-LANDesk)[0] - ) - - if(($Hostname + $AssetTag + $Location + $key) -eq ''){ - Write-Warning 'Input cannot be null' - return - } - - - $attributes = @( - 'Guid', - 'Title', - '_ConfigTypesCategory', - 'Status', - '_SHSAssetTag', - '_SerialNumber', - '_Model', - 'ConfigurationItem', - 'ConfigurationItem.Guid', - 'ConfigurationItem._SHSDELAsset', - 'ConfigurationItem._SHSVendorPC', - 'CreationDate', - 'CreationUser', - 'LastUpdate', - 'LastUpdateUser', - 'Lifecycle', - '_LocationDetails', - '_SHSLocation3', - '_SHSCINotes', - '_SHSCIPrimaryOwner', - '_SHSSCCMScanDate', - '_SHSChassisType', - '_SHSPOANumber' - ) - - $attributesString = $attributes -join ',' - - $uri = 'http://' + $server + '/' + $framework + '/api/' - $searchUri = $uri + 'query/?class_name=_CMDBManagement.Call&page_size=20000000&attributes=' + $attributesString + '&v=*' + '&cns=' + '_SHSDeleted-e-0_a_' + 'Title' + '-c-1_a_' + '_SHSLocation3' +'-c-2-&c0=False&c1=' + $Hostname + '&c2=' + $Location - $SearchResults = (Invoke-RestMethod -Uri $searchUri -Headers $headers -Method get).DataRows - - $output = @() - if($SearchResults -is [array]){ - foreach($result in $SearchResults){ - $cmdbRecord = [PSCustomObject]@{ - Hostname = $result.values.Title - AssetTag = $result.values._SHSAssetTag - Status = $result.values.Status - Type = $result.values._ConfigTypesCategory - Model = $result.values._Model - Chassis = $result.values._SHSChassisType - SerialNumber = $result.values._SerialNumber - POA = $result.values._SHSPOANumber - Location = $result.values._SHSLocation3 - CreationDate = $result.values.CreationDate - CreationUser = $result.values.CreationUser - LastUpdate = $result.values.LastUpdate - LastUpdateUser = $result.values.LastUpdateUser - Lifecycle = $result.values.Lifecycle - Guid = $result.Key - CI = $result.values.ConfigurationItem - } - $output += $cmdbRecord - } - } - else{ - $output = [PSCustomObject]@{ - Hostname = $SearchResults.values.Title - AssetTag = $SearchResults.values._SHSAssetTag - Status = $SearchResults.values.Status - Type = $SearchResults.values._ConfigTypesCategory - Model = $SearchResults.values._Model - Chassis = $SearchResults.values._SHSChassisType - SerialNumber = $SearchResults.values._SerialNumber - POA = $SearchResults.values._SHSPOANumber - Location = $SearchResults.values._SHSLocation3 - CreationDate = $SearchResults.values.CreationDate - CreationUser = $SearchResults.values.CreationUser - LastUpdate = $SearchResults.values.LastUpdate - LastUpdateUser = $SearchResults.values.LastUpdateUser - Lifecycle = $SearchResults.values.Lifecycle - Guid = $SearchResults.Key - CI = $SearchResults.values.ConfigurationItem - - } - - - } - - return $output | Select-Object -Property Hostname, Type, Location - -} \ No newline at end of file diff --git a/Private/Set-CMDBLocation.ps1 b/Private/Set-CMDBLocation.ps1 deleted file mode 100644 index c106c67..0000000 --- a/Private/Set-CMDBLocation.ps1 +++ /dev/null @@ -1,368 +0,0 @@ -function Set-CMDBLocation { - [CmdletBinding()] - param ( - [Parameter()] - [string] - $Hostname - ) - - process { - - - - - try { $cmdbData = Get-LANDeskCMDBItem -Name $Hostname } catch { $cmdbData = $null} - if($null -eq $cmdbData){ - $getpcData = Get-PCBatchInvoke $Hostname - $asset = $getpcData.'Asset Tag' - $asset = $asset -split ' ' - $asset = $asset[0] - try { $cmdbData = Get-LANDeskCMDBItem -AssetTag $asset} catch{ $cmdbData = $null } - if($null -eq $cmdbData){ - Write-Warning "Unable to find record with that hostname or assset tag in CMDB" - return - } - } - $oldLocation = $cmdbData.Values._SHSLocation3 - $key = $cmdbData.key - Write-Host "Hostname: $hostname" - Write-Host "Current Location: $oldLocation" - $newLocation = Read-Host "New Location" - - try {Set-LANDeskCMDBWorkstation -LocationDetails $newLocation -Key $key | Out-Null } - catch { - Write-Warning "Unable to change location data" - return - } - try { $cmdbData = Get-LANDeskCMDBItem -Name $Hostname } catch { $cmdbData = $null} - if($null -eq $cmdbData){ - try { $cmdbData = Get-LANDeskCMDBItem -AssetTag $asset} catch{ $cmdbData = $null } - if($null -eq $cmdbData){ - Write-Warning "Unable to find record with that hostname or assset tag in CMDB" - return - } - } - - $newLocation = $cmdbData.values._SHSLocation3 - Write-Host "Location now set to: $newLocation" -ForegroundColor Green - } -} - -function Set-LANDeskCMDBLocation { - [CmdletBinding(DefaultParameterSetName="Default")] - param ( - [Parameter(HelpMessage = 'The Name of the new CMDB item', - Mandatory = $true - )] - [string]$Name, - [Parameter(HelpMessage = 'Enter the Location Details for the CMDB Item')] - [string]$LocationDetails, - - [Parameter(HelpMessage = 'Enter the GUID for the CMDB Item')] - [string]$Key, - - [Parameter(HelpMessage = 'Specifying Server', - Mandatory = $false, - DontShow = $true)] - [string] $server = $(Connect-LANDesk)[1], - [Parameter(HelpMessage = 'Specifying LanDesk Framework for api', - Mandatory = $false, - DontShow = $true)] - [string] $framework = $(Connect-LANDesk)[2], - [Parameter(HelpMessage = 'Specifying LanDesk Headers for api', - Mandatory = $false, - DontShow = $true)] - [hashtable] $Headers = $(Connect-LANDesk)[0] - ) - - begin { - } - - process { - [object[]]$Values = $null - - $Title = @{} - $Title.Name = "Title" - $Title.Value = $Name - [object[]]$Values += $Title - - <# - $_ConfigTypesCategory = @{} - $_ConfigTypesCategory.Name = "_ConfigTypesCategory" - $_ConfigTypesCategory.Value = '9dadd9f9-ca5d-4be6-93cc-6c8745fff615' - $Values += $_ConfigTypesCategory - #> - $LocationDetails - $_SHSLocation3 = @{} - $_SHSLocation3.Name = "_SHSLocation3" - $_SHSLocation3.Value = $LocationDetails - $Values += $_SHSLocation3 - - $body = [ordered]@{} - $body.class_name = '_CMDBManagement.Call' - $Body.originalValues = $Values - $body.formValues = $Values - $body = $body | ConvertTo-Json - - $uri = 'http://' + $server + '/' + $framework + '/api/form?class_name=_CMDBManagement.Call&key=' + $Key + '&function_name=Edit&v=*' - Invoke-RestMethod -Uri $uri -Headers $headers -Body $Body -Method Patch - - } - - end { - } -} - -function Set-LANDeskCMDBWorkstation { - [CmdletBinding(DefaultParameterSetName="Default")] - param ( - [Parameter(HelpMessage = 'The Name of the new CMDB item')] - [string]$Name, - - [Parameter(HelpMessage = 'Enter the PO for the CMDB Item')] - [string]$PO, - - [Parameter(HelpMessage = 'Enter the Physical Location for the CMDB Item')] - [string]$PhysicalLocation, - - [Parameter(HelpMessage = 'Enter the Asset Tag for the CMDB Item')] - [string]$AssetTag, - - [Parameter(HelpMessage = 'Enter the RequestID for the CMDB Item')] - [string]$RequestID, - - [Parameter(HelpMessage = 'Enter the OperatingSystem for the CMDB Item')] - [string]$OperatingSystem, - - [Parameter(HelpMessage = 'Enter the ChassisType for the CMDB Item')] - [string]$ChassisType, - - [Parameter(HelpMessage = 'Enter the Total Hard Drive Size for the CMDB Item')] - [string]$HDD, - - [Parameter(HelpMessage = 'Enter the RAM for the CMDB Item')] - [string]$RAM, - - [Parameter(HelpMessage = 'Enter the Hard drive space Avalible for the CMDB Item')] - [string]$HDDAvail, - - [Parameter(HelpMessage = 'Enter the IPAddress for the CMDB Item')] - [string]$IPAddress, - - [Parameter(HelpMessage = 'Enter the KioskRole for the CMDB Item')] - [string]$KioskRole, - - [Parameter(HelpMessage = 'Enter the Model for the CMDB Item')] - [string]$Model, - - [Parameter(HelpMessage = 'Enter the SerialNumber for the CMDB Item')] - [string]$SerialNumber, - - [Parameter(HelpMessage = 'Enter the Notes for the CMDB Item')] - [string]$Notes, - - [Parameter(HelpMessage = 'Enter the OSPatching for the CMDB Item')] - [string]$OSPatching, - - [Parameter(HelpMessage = 'Enter the Patch Schedule for the CMDB Item')] - [string]$PatchSchedule, - - [Parameter(HelpMessage = 'Enter the Patch Notes for the CMDB Item')] - [string]$PatchNotes, - - [Parameter(HelpMessage = 'Enter the Location Details for the CMDB Item')] - [string]$LocationDetails, - - [Parameter(HelpMessage = 'Enter the GUID for the CMDB Item', - Mandatory = $true)] - [string]$Key, - - [Parameter(HelpMessage = 'Specifying Server', - Mandatory = $false, - DontShow = $true)] - [string] $server = $(Connect-LANDesk)[1], - [Parameter(HelpMessage = 'Specifying LanDesk Framework for api', - Mandatory = $false, - DontShow = $true)] - [string] $framework = $(Connect-LANDesk)[2], - [Parameter(HelpMessage = 'Specifying LanDesk Headers for api', - Mandatory = $false, - DontShow = $true)] - [hashtable] $Headers = $(Connect-LANDesk)[0] - ) - - begin { - } - - process { - [object[]]$Values = $null - - if($Name){ - $Title = @{} - $Title.Name = "Title" - $Title.Value = $Name - [object[]]$Values += $Title - } - - <# $_ConfigTypesCategory = @{} - $_ConfigTypesCategory.Name = "_ConfigTypesCategory" - $_ConfigTypesCategory.Value = '9dadd9f9-ca5d-4be6-93cc-6c8745fff615' - $Values += $_ConfigTypesCategory #> - - if ($PO) { - $_PO = @{} - $_PO.Name = "_PO" - $_PO.Value = $PO - $Values += $_PO - } - - # Look up table - if ($PhysicalLocation) { - $Location = Search-LANDeskIssueLocation -Location $PhysicalLocation - $_CILocation = @{} - $_CILocation.Name = "_CILocation" - $_CILocation.Value = $Location.Key - $Values += $_CILocation - } - if ($AssetTag) { - $_SHSAssetTag = @{} - $_SHSAssetTag.Name = "_SHSAssetTag" - $_SHSAssetTag.Value = $AssetTag - $Values += $_SHSAssetTag - } - - if ($RequestID) { - $_RequestID = @{} - $_RequestID.Name = "_RequestID" - $_RequestID.Value = $RequestID - $Values += $_RequestID - } - # Look up table - if ($OperatingSystem) { - if($OperatingSystem -match 'Windows 10'){ - $OS = '2ad72fd5-8d4e-4510-b5ea-f94b3a2cda08' - } - elseif ($OperatingSystem -match 'Windows 7') { - $OS = 'f127ceee-074b-4cc1-8a71-f8c02a9a9bd1' - } - else { - $OS = '00000000-0000-0000-0000-000000000000' - } - $_SHSOperatingSystem = @{} - $_SHSOperatingSystem.Name = "_SHSOperatingSystem" - $_SHSOperatingSystem.Value = $OS - $Values += $_SHSOperatingSystem - } - - if ($ChassisType) { - if($ChassisType -match "Desktop" -or $ChassisType -match "SFF"){ - $ChassisGuid = 'c7f3c5ba-a8b3-40be-963f-7e1d75fb7fda' - } - elseif ($ChassisType -match "Micro") { - $ChassisGuid = '8d71a4c3-ae9d-4e55-98ea-2f8a75987cac' - } - elseif($ChassisType -match "Laptop"){ - $ChassisGuid = 'a8460b18-bab9-4c07-8fb1-a4cca4e63fa1' - } - elseif($ChassisType -match "Tablet"){ - $ChassisGuid = 'e6ae9cd4-9936-496d-8e5d-efce8417a3d0' - } - else{ - $ChassisGuid = '00000000-0000-0000-0000-000000000000' - } - $_SHSChassisType = @{} - $_SHSChassisType.Name = "_SHSChasisRef" - $_SHSChassisType.Value = $ChassisGuid - $Values += $_SHSChassisType - } - - if ($HDD) { - $_HardDiskSize = @{} - $_HardDiskSize.Name = "_HardDiskSize" - $_HardDiskSize.Value = $HDD - $Values += $_HardDiskSize - } - - if ($RAM) { - $_RAM = @{} - $_RAM.Name = "_RAM" - $_RAM.Value = $RAM - $Values += $_RAM - } - - if ($HDDAvail) { - $_AvailableDiskSpace = @{} - $_AvailableDiskSpace.Name = "_AvailableDiskSpace" - $_AvailableDiskSpace.Value = $HDDAvail - $Values += $_AvailableDiskSpace - } - - if ($IPAddress) { - $_IPAddress = @{} - $_IPAddress.Name = "_IPAddress" - $_IPAddress.Value = $IPAddress - $Values += $_IPAddress - } - - if ($Model) { - $_Model = @{} - $_Model.Name = "_Model" - $_Model.Value = $Model - $Values += $_Model - } - if ($SerialNumber) { - $_SerialNumber = @{} - $_SerialNumber.Name = "_SerialNumber" - $_SerialNumber.Value = $SerialNumber - $Values += $_SerialNumber - } - if ($Notes) { - $_SHSCINotes = @{} - $_SHSCINotes.Name = "_SHSCINotes" - $_SHSCINotes.Value = $Notes - $Values += $_SHSCINotes - } - # Look up table - if ($OSPatching) { - $Patch = Search-LANDeskOSPatchType -PatchType $OSPatching - $_SHSOSPatching = @{} - $_SHSOSPatching.Name = "_SHSOSPatching" - $_SHSOSPatching.Value = $Patch.Key - $Values += $_SHSOSPatching - } - #look up table - if ($PatchSchedule) { - $Schedule = Get-LANDeskPatchSchedule -PatchSchedule $PatchSchedule - $_SHSPatchSchedule = @{} - $_SHSPatchSchedule.Name = "_SHSPatchSchedule" - $_SHSPatchSchedule.Value = $Schedule - $Values += $_SHSPatchSchedule - } - if ($PatchNotes) { - $_SHSPatchNotes = @{} - $_SHSPatchNotes.Name = "_SHSPatchNotes" - $_SHSPatchNotes.Value = $PatchNotes - $Values += $_SHSPatchNotes - } - if ($LocationDetails){ - $LocationDetails - $_SHSLocation3 = @{} - $_SHSLocation3.Name = "_SHSLocation3" - $_SHSLocation3.Value = $LocationDetails - $Values += $_SHSLocation3 - } - - $body = [ordered]@{} - $body.class_name = '_CMDBManagement.Call' - $Body.originalValues = $Values - $body.formValues = $Values - $body = $body | ConvertTo-Json - - $uri = 'http://' + $server + '/' + $framework + '/api/form?class_name=_CMDBManagement.Call&key=' + $Key + '&function_name=Edit&v=*' - Invoke-RestMethod -Uri $uri -Headers $headers -Body $Body -Method Patch - - } - - end { - } -} \ No newline at end of file diff --git a/Private/Spark.ps1 b/Private/Spark.ps1 index c3fa75d..541d7d4 100644 --- a/Private/Spark.ps1 +++ b/Private/Spark.ps1 @@ -39,13 +39,15 @@ Function Connect-ISM { } } -Function Check-SparkEnabled { +if ($(Read-Host "Enable Spark features? (y/N)") -match "^y") { Connect-ISM } + +Function Get-SparkEnabled { return -not -not $SparkHeaders["Authorization"] } -Function Search-SparkCIs($CIName) { +Function Get-SparkCI($CIName) { Connect-ISM - $uri = "$SparkURL/api/odata/businessobject/CIs`?`$filter=Name+eq+%27$CIName%27&`$top=100&`$skip=0" + $uri = "$SparkURL/api/odata/businessobject/CIs`?`$filter=Name+eq+%27$CIName%27" try{ $Query = Invoke-RestMethod -Method GET -uri $uri -headers $SparkHeaders } catch { diff --git a/Public/Get-PC.ps1 b/Public/Get-PC.ps1 index d4893aa..884ba3c 100644 --- a/Public/Get-PC.ps1 +++ b/Public/Get-PC.ps1 @@ -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 @@ -27,8 +27,6 @@ if ($Version -ne $deployedVersion) { Write-Host 'New version of Get-PC is available. Please run Get-PC -Update' -ForegroundColor Yellow } Write-Host "Enter 'Help Get-PC' for available commands.`n" -ForegroundColor Green - -if ($(Read-Host "Enable Spark features? (y/N)") -match "^y") { Connect-ISM } #endregion Function Get-PC { @@ -92,6 +90,7 @@ Function Get-PC { [Switch]$Bypass, [Switch]$ClearCCMCache, [switch]$Devices, + [switch]$EnableSpark, [Switch]$EventLog, [switch]$Excel, [Switch]$FileSystem, @@ -137,6 +136,8 @@ Function Get-PC { Update-GetPC return } + + if ($EnableSpark) { Connect-ISM } if ($PatchNotes) { $scriptparent = (get-item $PSScriptRoot ).parent.FullName diff --git a/patchnotes.txt b/patchnotes.txt index 5764aeb..52d8368 100644 --- a/patchnotes.txt +++ b/patchnotes.txt @@ -1,3 +1,9 @@ +Patch: 2024-08-02 +-Remove references to LANDesk +-Add interface to CMDB via Spark! +-Add CMDB data to output +-Add DEL warning and info + Patch: 2024-07-26 -Refactors -Update BatchInvokes to utilize jobs for up to 4x speedup