Get-PC/Get-PC/Private/Set-CMDBLocation.ps1

383 lines
13 KiB
PowerShell

function Set-CMDBLocation {
[CmdletBinding()]
param (
[Parameter()]
[string]
$Hostname
)
process {
try {
## $cmdbData = Get-LANDeskCMDBItem -Name $Hostname
$cmdbRecord = Search-ISMBO -BO cis -filter "Name eq '$Hostname'" -RawFilter
} 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
$cmdbData = Search-ISMBO -BO cis -filter "AssetTag eq '$asset'" -RawFilter
} 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
$cmdbData = Search-ISMBO -BO cis -filter "Hostname eq '$Hostname'" -RawFilter
} catch { $cmdbData = $null}
if($null -eq $cmdbData){
try {
##$cmdbData = Get-LANDeskCMDBItem -AssetTag $asset
$cmdbData = Search-ISMBO -BO cis -filter "AssetTag eq '$asset'" -RawFilter
} 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 {
}
}