【问题标题】:office 365 Powershell办公室 365 Powershell
【发布时间】:2016-11-21 05:08:05
【问题描述】:

人力资源部门有 5000 名未经许可的用户。我想将它们全部删除。 我对两个 powershell 命令感到困惑,想使用最快的一个:

## 1
Get-MsolUser -UnlicensedUsersOnly | Remove-MsolUser -force
## 2
Get-MsolUser -All | where {$_.department -eq "HR"} | Remove-MsolUser -force

【问题讨论】:

    标签: powershell office365


    【解决方案1】:

    虽然我认为处理时间不会有很大差异,因为您只是使用两种不同的方式来检索数据列表,但似乎只拉取未经许可的用户会更快一些,而不是拉出所有用户,然后根据部门过滤它们。但是,您确定其他部门中没有您不想删除的未授权用户吗?

    关于哪个命令更快,您是否尝试过使用Measure-Object 命令查看每个命令需要多长时间?您可以只测量Get-MsolUser 命令来确认差异。

    Measure-Object {Get-MsolUser -UnlicensedUsersOnly}
    Measure-Object {Get-MsolUser -All | where {$_.department -eq "HR"}}
    

    Remove-MsolUser -force 对于这两个选项应该花费相同的时间。另外,我认为您需要将 Remove-MsolUser 命令放入 foreach 循环中:

    foreach($user in Get-MsolUser -UnlicensedUsersOnly | where {$_.department -eq "HR"})
    {Remove-MsolUser -ObjectId $user.ObjectId.guid -force}
    

    https://technet.microsoft.com/en-us/library/ee176899.aspx

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      • 2010-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多