如何解决向函数添加计数过程
所以我需要计算函数中使用的变量的值。我不能运行简单的 $count++
,因为该变量的值很少等于 1。
Function Set-bhRTGmembers_logonly {
[CmdletBinding(SupportsShouldProcess)]
$DirectReports = Get-Directreport $manager -norecurse | Select-Object -expand samAccountName
# Get manager's 'report to <manager>' group again to update members
$managerReportToGroup = Get-ADGroup -SearchBase $OU -Filter "Name -like 'Report to $Manager'"
if ($managerReportToGroup) {
$script:logonlyAddUserCount++
$LogLine = "Report to $Manager would be updated with $DirectReports"
Log-Write -LogPath $slogonlyFile -LineValue $LogLine
}
else {
$LogLine = "Group for $Manager not found,would be updated with $DirectReports"
Log-Write -LogPath $slogonlyFile -LineValue $LogLine
}
}
第 7 行试图计算 $DirectReports 中 SamAccountNames 的数量,我该怎么做?
解决方法
如果您需要 $DirectReports
中包含的项目数,您可以简单地使用其别名属性 Count
(如果它是一个集合)或 Measure-Object。无论 Measure-Object
中包含多少项,$DirectReports
都有效。
($DirectReports | Measure-Object).Count
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。