You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用PowerShell批量查询AD用户中登录脚本为SLOGIC的账号?

批量查询AD用户中使用“SLOGIC”登录脚本的PowerShell方案

方案1:直接输出符合条件的用户列表

# 获取所有AD用户,筛选登录脚本为"SLOGIC"的用户,返回用户名和脚本路径
Get-ADUser -Filter {ScriptPath -eq "SLOGIC"} -Properties ScriptPath | Select-Object SamAccountName, ScriptPath

方案2:导出结果到CSV文件(适合大量用户排查)

针对500+用户的排查需求,导出到CSV文件更方便后续统计分析:

# 查询并导出到指定路径的CSV文件
Get-ADUser -Filter {ScriptPath -eq "SLOGIC"} -Properties ScriptPath | 
    Select-Object SamAccountName, ScriptPath | 
    Export-Csv -Path "C:\AD_LogonScript_SLOGIC.csv" -NoTypeInformation -Encoding UTF8

脚本说明

  1. Get-ADUser -Filter {ScriptPath -eq "SLOGIC"}:通过AD内置筛选器直接过滤目标用户,比先获取所有用户再本地筛选效率更高,适配大规模AD环境。
  2. -Properties ScriptPath:必须指定该参数,因为ScriptPath不属于Get-ADUser的默认返回属性。
  3. Select-Object SamAccountName, ScriptPath:返回清晰的用户名和脚本路径,避免原单用户脚本中出现的@{ScriptPath=SLOGIC}这类对象格式输出。
  4. 导出CSV:通过Export-Csv将结果保存为表格文件,可直接用Excel等工具打开,方便批量用户的排查统计。

补充:优化原单用户查询脚本(可选)

如果仍需保留单用户查询功能,可优化输出格式让结果更直观:

Write-Host "Checking for logon scripts."
$User = Read-Host -Prompt "Input the username"
Write-Host "Checking for logon script."

# 获取脚本路径的纯文本值,而非对象
$ScriptPath = Get-ADUser -Identity $User -Properties Scriptpath | Select-Object -ExpandProperty ScriptPath

If ($ScriptPath) {
    Write-Host "$User has a logon script: $ScriptPath"
} Else {
    Write-Host "$User does not have a logon script"
}

内容的提问来源于stack exchange,提问作者Lukas Riesen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 13:31:05