function - PowerShell 函数。Foreach + If 查询、正确顺序或更多
问题描述
我正在寻找一种在 powershell 中查询每个 AD 用户在 Windows Server 2019 中活动的进程的方法,创建一个包含 Enabled 为“True”的用户的数组,并迭代搜索进程的多个因素(名称、ID、 cpu等)分成两个查询,这样太大的表就不会出来,更显眼。我的问题是,让数组和 Foreach 工作,我无法找到一种方法来根据循环的每个步骤中的用户名来调整进程的搜索。我已经用下面的 if 进行了尝试,其中每个查询的管道是 where,......但我无法解决它。我将不胜感激任何帮助。
function procUsers {
$usuariosTrue = Get-ADUser -Filter * | select Name, Enabled | where Enabled -Match True
ForEach ($usuario in $usuariosTrue) {
if (**********) {
Get-Process -IncludeUserName | Select-Object UserName, Id, cpu, StartTime, TotalProcessorTime | where $usuario.name -ieq UserName | sort UserName| Format-Table * | Where $usuario.name match UserName
Get-WmiObject win32_process | select CommandLine, Status | sort Username | Format-Custom *
}
}
}
解决方案
推荐阅读
- javascript - 另一个窗口的Javascript关闭模式
- javascript - 在 Google Analytics 可跟踪点击后显示 mailto 链接
- r - 在 R 中创建一个带有 X 试验、Y 代表和 Z 图的 data.table
- html - 如何将输入表单结果集成到 R 块中?
- node.js - 每次创建文章并将其保存在数据库中时,如何生成 slug?
- firebase - 在 Heroku 上部署 Spring Boot 应用程序不工作
- sql - 使用 GROUP BY 在 SQL Server 中计算总数的百分比
- angular - Angular 在动态模块中使用 Fontawesome 指令
- php - 如何使用 mysql 将带有文本数据的图像插入 php 中的数据库。?
- php - 如何使用 php 从 JSON 中获取特定值