Powershell:ForEach +获取Msol循环
我曾尝试查看视频,浏览了我的两本书中的文章,但仍然无法确定它:-/我的脚本目标:根据用户帐户的 DisplayName 获取 UPN 。
我的 CSV 示例:
- DisplayName
- user1
- user2
- user3
当我刚刚运行时,我成功了:
Get-MsolUser -SearchString 'user1' | Select-Object UserPrincipalName
将所有显示名称导入数组:
$userlist = Import-Csv .\ul.csv
检查我是否正确导入:
$userlist
遗憾的是我在这里失败了:通过导入的 CSV 运行循环“对象”:-/
我尝试过 1:
$userlist.foreach(
{
Get-MsolUser -SearchString 'DisplayName' | Select-Object UserPrincipalName
})
我尝试过 2:
foreach ($user in $userlist)
{
Get-MsolUser -Searchstring DiplayName | Select-Object UserPrincipalName
}
我尝试过 3:
$userlist | ForEach-Object {Get-MsolUser -Searchstring DisplayName | Select-Object UserPrincipalName}
它们都不起作用:-(
I had tried to take a look on videos, went thru articles in my 2 books but still cannot nail it :-/ Goal of my script: to get the UPN's based on DisplayName of user's accounts.
My CSV example:
- DisplayName
- user1
- user2
- user3
I am successfull when I just run:
Get-MsolUser -SearchString 'user1' | Select-Object UserPrincipalName
Importing all displaynames to array:
$userlist = Import-Csv .\ul.csv
Check I did import correctly:
$userlist
Sadly I'm failing here: to run the loop thru the imported CSV "objects" :-/
I tried 1:
$userlist.foreach(
{
Get-MsolUser -SearchString 'DisplayName' | Select-Object UserPrincipalName
})
I tried 2:
foreach ($user in $userlist)
{
Get-MsolUser -Searchstring DiplayName | Select-Object UserPrincipalName
}
I tried 3:
$userlist | ForEach-Object {Get-MsolUser -Searchstring DisplayName | Select-Object UserPrincipalName}
None of them worked :-(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论