azure - 带有 CSV 的 Powershell 脚本从 DisplayName 获取 objectID
问题描述
我想制作一个新的 CSV 文件,该文件仅包含来自 CSV 文件的 ObjectID,其中包含计算机名称 (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'
我从 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***
任何人都可以帮助我吗?
解决方案
除了让您的 Get-AzureADDevice 正常工作。看起来您没有在列表中添加任何内容。我会做这样的事情。创建一个空数组 ObjectID。然后在 foreach 中将元素添加到数组中。在您的 foreach 之后,您调用数组并将其输出到 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'
推荐阅读
- c# - 获取数组内数组的最大计数?
- flutter - 未为“DocumentSnapshot”类型定义运算符“[]”
- tensorflow - 对 TensorFlow 和 PyTorch 的 GPU 支持
- javascript - 通过js自动选择最高质量?
- postgresql - 如何强制前缀“pg_”在 postgres 中创建新用户?
- macos - 每次我在我的 Mac 上打开终端时,我都会得到 /Users/shubh01/.zshrc:source:73: no such file or directory
- apparmor - AppArmor:没有任何附加参数的单个“文件”子句是什么意思?
- mysql - Mysql联合二区列合二为一
- r - 如何使用 R 中 gplots 包中的 plotmeans() 函数绘制平均值和置信区间条形图
- c - 如何用始终写入 `uint8_t*` 的函数替换 `fwrite`