ugurkocde / IntuneOffboarding

https://ugurkoc.de/
MIT License
92 stars 23 forks source link

Error in offboarding operation: Please ensure device names are valid #12

Open amagre opened 1 month ago

amagre commented 1 month ago

I keep getting this error when checking the log file on a number of devices when offboarding even though I have checked those devices exist in Entra ID and Intune: "Error in offboarding operation. Exception: Cannot process argument transformation on parameter 'DeviceId'. Cannot convert value to type System.String."

Screenshot 2024-07-25 110356

I have also checked the device name and there is nothing unusual in the name. Any ideas or has anyone else seen this issue?

Thanks

amagre commented 1 month ago

Also noticed this script cannot handle duplicate entries found in Entra ID, which isn't great if you have to then go in manually to delete from Entra ID. Screenshot 2024-07-25 111933

blinkblinktwo commented 2 weeks ago

Nifty project, thanks.

I tried some cases where there were only some "objects" available between AP, Intune, and AAD, and not all three. This also seemed to cause some problems for searching devices and serials.

I was also looking at adding individual "offboard" buttons for each area to test finding/removing individual objects.


$OffboardButton2.Add_Click({

    if ($AuthenticateButton.IsEnabled) {
        Write-Log "User is not connected to MS Graph. Attempted offboarding operation."
        [System.Windows.MessageBox]::Show("You are not connected to MS Graph. Please connect first.")
        return
    }

    $confirmationResult = [System.Windows.MessageBox]::Show("Are you sure you want to proceed with INTUNE offboarding? This action cannot be undone.", "Confirm Offboarding", [System.Windows.MessageBoxButton]::YesNo)
    if ($confirmationResult -eq 'No') {
        Write-Log "User canceled offboarding operation."
        return
    }

    try {
        $SearchTexts = $SearchInputText.Text -split ', '

        foreach ($SearchText in $SearchTexts) {
            if (![string]::IsNullOrEmpty($SearchText)) {
                $IntuneDevice = Get-MgDeviceManagementManagedDevice -Filter "deviceName eq '$SearchText'" -ErrorAction Stop

                if ($IntuneDevice) {
                    Remove-MgDeviceManagementManagedDevice -ManagedDeviceId $IntuneDevice.Id -PassThru -ErrorAction Stop
                    [System.Windows.MessageBox]::Show("Successfully removed device $SearchText from INTUNE.")
                    $Window.FindName('intune_status').Text = "Intune: Unavailable"
                    Write-Log "Successfully removed device $SearchText from INTUNE."
                }
                else {
                    [System.Windows.MessageBox]::Show("Device $SearchText not found in INTUNE.")
                }

            }
            else {
                [System.Windows.MessageBox]::Show("Please provide a valid INTUNE device name.")
            }
        }
    }
    catch {
        Write-Log "Error in INTUNE offboarding operation. Exception: $_"
        [System.Windows.MessageBox]::Show("Error in INTUNE offboarding operation. Please ensure device names are valid.")
    }
})