Get-Hostname queries CMDB for asset tags correctly and SCCMQueryBlock now gets CMDB data
This commit is contained in:
parent
8661d20d07
commit
e9435d15d3
|
|
@ -6,7 +6,7 @@ function Get-Hostname ([string]$name) {
|
|||
try {
|
||||
$cmdbData = Search-ISMBO -bo cis -filter "AssetTag eq '$name'" -RawFilter
|
||||
} catch { $cmdbData = $null }
|
||||
if ( $cmdbData ) { return $cmdbData.values.title, '' }
|
||||
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
||||
else { $errMsg += "$name Asset Tag not in SMBIOS or CMDB. " }
|
||||
}
|
||||
# Regex to match IP Address brought to you by https://stackoverflow.com/a/36760050
|
||||
|
|
@ -21,6 +21,10 @@ function Get-Hostname ([string]$name) {
|
|||
if ($name.Length -eq 7) {
|
||||
$res = Get-ServiceTagConversion $name
|
||||
if ($res) { return $res,'' }
|
||||
try {
|
||||
$cmdbData = Search-ISMBO -bo cis -filter "SerialNumber eq '$name'" -RawFilter
|
||||
} catch { $cmdbData = $null }
|
||||
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
||||
else { $errMsg += "$name Service Tag not found in SCCM"}
|
||||
}
|
||||
# Regex to match MAC Address brought to you by https://stackoverflow.com/a/4260512
|
||||
|
|
|
|||
|
|
@ -271,6 +271,33 @@ $SCCMNAMESPACE="root\sms\site_100"
|
|||
Write-Host "Last Hardware Scan Time: $FindLastHardwareScanSCCM" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
$uri = "${using:Tenant}/api/odata/businessobject/cis`?`$filter=Name eq '$comp'&`$top=1&`$skip=0"
|
||||
Write-Host $uri
|
||||
try {
|
||||
$Query = Invoke-RestMethod -Method GET -uri $uri -headers ${using:Headers}
|
||||
} catch {
|
||||
Write-Host $_.Exception.Message
|
||||
}
|
||||
$cmdbData = $Query.Value
|
||||
|
||||
$LocationConstructors = @(
|
||||
"SHS_AssetLocality",
|
||||
"ivnt_Location",
|
||||
"SHS_Floor",
|
||||
"SHS_Department",
|
||||
"SHS_LocationDetails"
|
||||
)
|
||||
|
||||
$LocationData = Foreach($Loc in $LocationConstructors){
|
||||
|
||||
if ($Loc -eq 'SHS_Floor'){
|
||||
$(if ($cmdbData.$Loc -match '-'){$cmdbData.$Loc.split('-')[-1] + " Floor"} else{$cmdbData.$Loc})
|
||||
} elseif (![string]::IsNullOrEmpty($cmdbData.$Loc)){
|
||||
$cmdbData.$Loc
|
||||
}
|
||||
}
|
||||
|
||||
$LocationData = $LocationData -join ' | '
|
||||
|
||||
$props = [Ordered]@{
|
||||
Hostname = "$comp"
|
||||
|
|
@ -291,14 +318,15 @@ $SCCMNAMESPACE="root\sms\site_100"
|
|||
'Service Tag' = "$FindServiceTagSCCM"
|
||||
'Last Reboot' = "$FindLastBootUpTimeSCCM"
|
||||
Printers = "$FindPCPrinterSCCM"
|
||||
'CMDB Location' = "$LocationData"
|
||||
}
|
||||
|
||||
$obj = New-Object -TypeName PSObject -Property $props
|
||||
<#if($cmdbData.values.ConfigurationItem._SHSDELAsset -eq 'True'){
|
||||
$delInfo = Get-CMDBDELInfo $cmdbData
|
||||
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $delInfo.Owner
|
||||
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Vendor PC' -Value $delInfo.Vendor
|
||||
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Description' -Value $delInfo.Description
|
||||
} #>
|
||||
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
|
||||
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $cmdbData.SHS_ExceptionContact
|
||||
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Vendor PC' -Value $cmdbData.SHS_IsVendorPC
|
||||
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Description' -Value $cmdbData.SHS_ExceptionNotes
|
||||
}
|
||||
return $obj
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@
|
|||
New-Item -Path $Destination\backuplog.txt -Force | Write-Verbose
|
||||
$log = Join-Path -Path $Destination -ChildPath backuplog.txt
|
||||
|
||||
Invoke-UserProfileTransfer $SourceRoot $Destination
|
||||
Invoke-UserProfileTransfer $SourceRoot $Destination -ErrorAction 'Continue'
|
||||
|
||||
if(($site -ge 0 ) -and ($site -lt $numSites)){
|
||||
#Manually backup sticky notes since we don't always want them to transfer
|
||||
|
|
@ -236,6 +236,6 @@
|
|||
Write-Warning "The backup you have chosen does not exist"
|
||||
break
|
||||
}
|
||||
Invoke-UserProfileTransfer $FullRestorationSource $SourceRoot
|
||||
Invoke-UserProfileTransfer $FullRestorationSource $SourceRoot -ErrorAction 'Continue'
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
function Invoke-UserProfileTransfer {
|
||||
[CmdletBinding()]
|
||||
param($srcPath, $dstPath)
|
||||
<#
|
||||
.SYNOPSIS
|
||||
|
|
@ -30,7 +31,7 @@
|
|||
for ($i = 0; $i -lt $FoldersToCopy.Length; $i++) {
|
||||
$Folder = $FoldersToCopy[$i]
|
||||
|
||||
Write-Progress -Activity "User Profile Transfer from $srcPath to $dstPath" -Status $Folder -PercentComplete ($i / $FoldersToCopy.Length)*100
|
||||
Write-Progress -Activity "User Profile Transfer from $srcPath to $dstPath" -Status $Folder -PercentComplete (($i / $FoldersToCopy.Length)*100)
|
||||
|
||||
$Source = Join-Path -Path $srcPath -ChildPath $Folder
|
||||
$Destination = $dstPath
|
||||
|
|
|
|||
Loading…
Reference in a new issue