Powershell在AD中按Employee Name单元格搜索,直到,(逗号)



我想知道PowerShell是否可以进入excel文档,在特定的工作表、特定的列、特定的单元格和该单元格中搜索,只选择文本BEFORE(逗号(分隔符。在这种情况下,前面的文本(逗号(分隔符是用户的姓氏。最后,我希望PowerShell只按姓氏搜索用户,搜索1000多个条目。https://i.stack.imgur.com/4DJHt.png

关于您希望如何处理脚本,或者您希望从Active Directory查询哪些属性,没有太多细节,但您可以从以下内容开始:

# If ImportExcel is not installed:
Install-Module ImportExcel -Scope CurrentUser
$xlsx=Import-Excel 'path/to/excel.xlsx' -WorksheetName 'SheetNameHERE'
if('Employee Name' -notin $xlsx[0].PSObject.Properties.Name)
{
Write-Warning "Expectected Column Name 'Employee Name' not found."
break
}
$result=[System.Collections.Generic.List[pscustomobject]]::new()
foreach($usr in $xlsx)
{
if($usr.'Employee Name'.Contains(','))
{
$filter="Surname -eq '{0}'" -f $usr.'Employee Name'.Split(',')[0]
$adUsr=Get-ADUser -Filter $filter

$result.Add(
[pscustomobject]@{
'Employee#'=$usr.'Employee#'
# Remaining properties you need to query of $adUsr here
})
}
}

最新更新