@@ -393,7 +393,7 @@ function Invoke-HuduExtensionSync {
393393 $CompanyResult.Logs.Add (' Starting User Processing' )
394394 $OutputUsers = foreach ($user in $licensedUsers ) {
395395 try {
396-
396+ $HuduUser = $null
397397 $UserGroups = foreach ($Group in $Groups ) {
398398 if ($User.id -in $Group.Members.id ) {
399399 $FoundGroup = $AllGroups | Where-Object { $_.id -eq $Group.id }
@@ -685,13 +685,13 @@ function Invoke-HuduExtensionSync {
685685 } elseif ($HuduUserCount -eq 0 ) {
686686 if ($CreateUsers -eq $True ) {
687687 $CompanyResult.Logs.Add (" Creating $ ( $User.displayName ) in Hudu" )
688- $HuduUser = (New-HuduAsset - Name $User.displayName - company_id $company_id - asset_layout_id $PeopleLayout.id - Fields $UserAssetFields ).asset
689- if (! $HuduUser ) {
688+ $CreateHuduUser = (New-HuduAsset - Name $User.displayName - company_id $company_id - asset_layout_id $PeopleLayout.id - Fields $UserAssetFields ).asset
689+ if (! $CreateHuduUser ) {
690690 $CompanyResult.Errors.add (" User $ ( $User.userPrincipalName ) : Unable to create user in Hudu. Check the User asset fields for 'Email Address'" )
691691 } else {
692692 $AssetCache = [PSCustomObject ]@ {
693693 PartitionKey = ' HuduUser'
694- RowKey = [string ]$HuduUser .id
694+ RowKey = [string ]$CreateHuduUser .id
695695 CompanyId = [string ]$company_id
696696 Hash = [string ]$NewHash
697697 }
@@ -851,13 +851,13 @@ function Invoke-HuduExtensionSync {
851851 }
852852 Add-CIPPAzDataTableEntity @HuduAssetCache - Entity $AssetCache - Force
853853
854- $HuduUser = $People | Where-Object { $_.primary_mail -eq $Device.userPrincipalName -or ($_.cards.integrator_name -eq ' cw_manage' -and $_.cards.data.communicationItems.communicationType -eq ' Email' -and $_.cards.data.communicationItems.value -eq $Device.userPrincipalName ) }
854+ $RelHuduUser = $People | Where-Object { $_.primary_mail -eq $Device.userPrincipalName -or ($_.cards.integrator_name -eq ' cw_manage' -and $_.cards.data.communicationItems.communicationType -eq ' Email' -and $_.cards.data.communicationItems.value -eq $Device.userPrincipalName ) }
855855
856- if ($HuduUser ) {
857- $Relation = $HuduRelations | Where-Object { $_.fromable_type -eq ' Asset' -and $_.fromable_id -eq $HuduUser .id -and $_.toable_type -eq ' Asset' -and $_toable_id -eq $HuduDevice.id }
856+ if ($RelHuduUser ) {
857+ $Relation = $HuduRelations | Where-Object { $_.fromable_type -eq ' Asset' -and $_.fromable_id -eq $RelHuduUser .id -and $_.toable_type -eq ' Asset' -and $_toable_id -eq $HuduDevice.id }
858858 if (-not $Relation ) {
859859 try {
860- $null = New-HuduRelation - FromableType ' Asset' - FromableID $HuduUser .id - ToableType ' Asset' - ToableID $HuduDevice.id - ea stop
860+ $null = New-HuduRelation - FromableType ' Asset' - FromableID $RelHuduUser .id - ToableType ' Asset' - ToableID $HuduDevice.id - ea stop
861861 } catch {}
862862 }
863863 }
@@ -875,23 +875,23 @@ function Invoke-HuduExtensionSync {
875875 }
876876 if ($DeviceCreation -eq $true ) {
877877 $CompanyResult.Logs.Add (" Creating $ ( $device.deviceName ) in Hudu" )
878- $HuduDevice = (New-HuduAsset - Name $device.deviceName - company_id $company_id - asset_layout_id $DeviceLayoutID - Fields $DeviceAssetFields - PrimarySerial $Device.serialNumber ).asset
878+ $CreateHuduDevice = (New-HuduAsset - Name $device.deviceName - company_id $company_id - asset_layout_id $DeviceLayoutID - Fields $DeviceAssetFields - PrimarySerial $Device.serialNumber ).asset
879879
880- if (! $HuduDevice ) {
880+ if (! $CreateHuduDevice ) {
881881 $CompanyResult.Errors.add (" Device $ ( $device.deviceName ) : Failed to create device in Hudu, check your device asset fields for 'Primary Serial'." )
882882 } else {
883883 $AssetCache = [PSCustomObject ]@ {
884884 PartitionKey = ' HuduDevice'
885- RowKey = [string ]$HuduDevice .id
885+ RowKey = [string ]$CreateHuduDevice .id
886886 CompanyId = [string ]$company_id
887887 Hash = [string ]$NewHash
888888 }
889889 Add-CIPPAzDataTableEntity @HuduAssetCache - Entity $AssetCache - Force
890890
891- $HuduUser = $People | Where-Object { $_.primary_mail -eq $Device.userPrincipalName -or ($_.cards.integrator_name -eq ' cw_manage' -and $_.cards.data.communicationItems.communicationType -eq ' Email' -and $_.cards.data.communicationItems.value -eq $Device.userPrincipalName ) }
892- if ($HuduUser ) {
891+ $RelHuduUser = $People | Where-Object { $_.primary_mail -eq $Device.userPrincipalName -or ($_.cards.integrator_name -eq ' cw_manage' -and $_.cards.data.communicationItems.communicationType -eq ' Email' -and $_.cards.data.communicationItems.value -eq $Device.userPrincipalName ) }
892+ if ($RelHuduUser ) {
893893 try {
894- $null = New-HuduRelation - FromableType ' Asset' - FromableID $HuduUser .id - ToableType ' Asset' - ToableID $HuduDevice .id - ea stop
894+ $null = New-HuduRelation - FromableType ' Asset' - FromableID $RelHuduUser .id - ToableType ' Asset' - ToableID $CreateHuduDevice .id - ea stop
895895 } catch {
896896 # No need to do anything here as its will be when relations already exist.
897897 }
0 commit comments