简体   繁体   English

如何在 powershell 中为团队执行嵌套循环

[英]How can I do nested loops in powershell for teams

I'm new to PowerShell and I want to use it to automate different FOR loops in teams.我是 PowerShell 的新手,我想用它来自动化团队中的不同 FOR 循环。

I made a script that reads information from a file and performs the actions based on this file我制作了一个脚本,它从文件中读取信息并根据该文件执行操作

Import-Csv -Path "C:\\Users\\Arik\\Desktop\\names.csv" | foreach{Add-TeamChannelUser -GroupId 7a0d2b07-3e4d-45c5-b455-5622fa5b0b24 -DisplayName "4  -  Execution" -user $\_.email}

This script adds user to a certain team and a certain channel.此脚本将用户添加到某个团队和某个频道。 What I want to do is automate the GroupID and the DisplayName process.我想要做的是自动化 GroupID 和 DisplayName 过程。 Is there anyway I can do this?无论如何我可以做到这一点吗? I figured I'd have to use a for loop but I'm not sure how to implement this on PowerShell.我想我必须使用 for 循环,但我不确定如何在 PowerShell 上实现它。 I want it to first choose the Team by using the group ID then for each team I want it to look for certain channels and for each channel I want it to add the list of emails.我希望它首先使用组 ID 选择团队,然后对于每个团队,我希望它查找某些频道,对于每个频道,我希望它添加电子邮件列表。 Any help would be appreciate, I'm trying to avoid stack overflow as much as possible.任何帮助将不胜感激,我试图尽可能避免堆栈溢出。

I've not used powershell for teams, but perhaps try:我没有为团队使用过 powershell,但也许可以尝试:

$users = Import-Csv -Path "C:\\Users\\Arik\\Desktop\\names.csv"
foreach($user in $users){
    Add-TeamChannelUser -GroupId '7a0d2b07-3e4d-45c5-b455-5622fa5b0b24' -DisplayName "4  -  Execution" -user $user.email
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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