Hi

I have a list of device names exported to an csv file.

I need to import this csv to then query the data and export the objectid of these computers from azure.

I am using the below and the error I am receiving is beneath

Can anyone point me in the right direction?

#create a variable for import-csv

$test3 = import-csv -path “C:\temp\test3.xml”

#output objectid

Get-MsolDevice -Name $test3.Name | Select-Object -Property ObjectID | Export-CSV -Path “C:\temp\test9.xml”

Get-MsolDevice : Cannot convert ‘System.Object’ to the type ‘System.String’ required by

parameter ‘Name’. Specified method is not supported.

At line:1 char:22

  • Get-MsolDevice -Name $test3.Name | Select-Object -Property ObjectID | …

  • 
    
  • CategoryInfo : InvalidArgument: (:slight_smile: [Get-MsolDevice], ParameterBindingExceptio

n

  • FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Online.Administration.Automatio

n.GetDevice

6 Spice ups

If $test3 contains more than one object, you will need to send them to Get-MsolDevice one at a time.

$test3 = import-csv -path "C:\temp\test3.xml"

#output objectid
$Results = ForEach ($device in $test3) {
    Get-MsolDevice -Name $device.Name | Select-Object -Property ObjectID 
}
$Results | Export-CSV -Path "C:\temp\test9.xml" -NoTypeInformation

Also, your filename extensions are wonky. You should use .csv instead of .xml in this case.

Just to keep things clean.

1 Spice up

Hi

Thanks I tried this but received the below error

This just loops round for each device it searches for

Get-MsolDevice : Device Not Found
At line:2 char:5

  • Get-MsolDevice -Name $device.Name | Select-Object -Property Objec …
  • CategoryInfo : OperationStopped: (:slight_smile: [Get-MsolDevice], MicrosoftOnlineExceptio
    n
  • FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.MicrosoftOnlineExcep
    tion,Microsoft.Online.Administration.Automation.GetDevice

I took everything out of the csv and left in one machine name that I know for sure is in azure.

The script produces a csv but it’s blank with no column headings

can you give us the first two lines your CSV please

e.g.

HEADER1,HEADER2

SERVER1,Info

1 Spice up