简体   繁体   中英

Powershell script with a CSV to get objectID from DisplayName

I want to make a new CSV file containing only ObjectID from a CSV file with a list of Computer name (DisplayName)

connect-azuread
$csv = Import-Csv C:\Tools\PCname.csv
foreach ($DisplayName in $csv){
    $ObejctID = get-AzureADDevice -Filter "DisplayName eq '$._DisplayName'" | Select ObjectID 
}
$ObejctID
$Content.objectID | Out-File 'C:\Tools\BulkObjectID.csv'

I have the following error from the ISE:

***get-AzureADDevice : Le terme «get-AzureADDevice» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou 
programme exécutable. Vérifiez l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès est correct et 
réessayez.
Au caractère Ligne:11 : 17
+     $ObejctID = get-AzureADDevice -Filter "DisplayName eq '$._Display ...
+                 ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-AzureADDevice:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException***

Can Anyone help me please?

aside from getting your Get-AzureADDevice working. doesn't look like you're adding anything to the list. I would do something like this. Create an empty array ObjectID. Then in for Foreach you add your elements to the array. After your foreach you call the array and pipe it out to export-csv.

$csv = Import-Csv C:\Tools\PCname.csv
$ObjectID=@()
foreach ($DisplayName in $csv){
    $ObejctID += get-AzureADDevice -Filter "DisplayName eq '$._DisplayName'" | Select ObjectID 
}
$ObejctID
$ObjectID | export-csv 'C:\Tools\BulkObjectID.csv'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM