Problem to rename android script on intune with azure automation

raorla 5 Reputation points
2023-05-17T08:33:14.8566667+00:00

I have a script to rename android devices on powershell and I would like to run it on azure automation to automate every week and I can't connect to intune and graph microsoft even by installing all the module on azure automation:

connect-MSGraph
$androidDevices = Get-DeviceManagement_ManagedDevices -Filter "operatingSystem eq 'Android'"
foreach ($device in $androidDevices) {
	$newName = "Android-"+$device.serialNumber 
	$deviceId = $device.managedDeviceId
	Write-Host "Renaming Android device with ID:" $deviceId "to" $newName
	$device = Get-DeviceManagement_ManagedDevice -ManagedDeviceId $deviceId
	$device.deviceName = $newName
	$device | Set-DeviceManagement_ManagedDevice
}

#foreach ($device in $androidDevices) {
 #   $newName = "Android-"+$device.serialNumber 
 #   $deviceId = $device.managedDeviceId
  #  Write-Host "Renaming Android device with ID:" $deviceId "to" $newName
   # $device = Get-DeviceManagement_ManagedDevice -ManagedDeviceId $deviceId
   # $device.deviceName = $newName
   ## $device | Set-DeviceManagement_ManagedDevice
#}
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,192 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,246 Reputation points
    2023-05-18T06:55:16.0666667+00:00

    @raorla , thank you for posting this question.

    I see that you are using connect-MSGraph which requires interactive authentication. Interactive authentication is not supported in Azure Automation. For more details of how the execution and authentication works in Azure Automation, please see Runbook execution environment

    For using connect-MSGraph in Runbooks, you would have to use one of the non-interactive methods for authentication as mentioned here - App-only access via client credential with a certificate. Use the third method (using certificate in this doc).

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it, and we will help you out. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.