Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel Powershell按员工姓名单元格在AD中搜索,直到(逗号)_Excel_Powershell_Search_Cell - Fatal编程技术网

Excel Powershell按员工姓名单元格在AD中搜索,直到(逗号)

Excel Powershell按员工姓名单元格在AD中搜索,直到(逗号),excel,powershell,search,cell,Excel,Powershell,Search,Cell,我想知道PowerShell是否可以进入excel文档,在特定工作表、特定列、特定单元格和该单元格中搜索,以仅在逗号分隔符之前选择文本。 在本例中,前面的文本逗号分隔符是用户的姓氏。 最后,我希望PowerShell只按姓氏搜索用户,搜索1000多个条目。 关于如何处理脚本,或者要从Active Directory查询哪些属性,没有太多详细信息,但您可以从以下内容开始: # If ImportExcel is not installed: Install-Module ImportExcel -

我想知道PowerShell是否可以进入excel文档,在特定工作表、特定列、特定单元格和该单元格中搜索,以仅在逗号分隔符之前选择文本。 在本例中,前面的文本逗号分隔符是用户的姓氏。 最后,我希望PowerShell只按姓氏搜索用户,搜索1000多个条目。

关于如何处理脚本,或者要从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
        })
    }
}

当然可以。强烈建议您从GitHub安装用于PS的Excel模块。一旦您这样做了,并尝试使用您的代码,我们将帮助您解决您遇到的问题,解决您的困境。当然,Powershell可以做到这一点。我将使用Powershell Gallery中的ImportExcel模块从电子表格中获取数据,在逗号上拆分名称并删除任何空格,然后使用get-ADUser-Filter-LastName-eq$LastName获取结果。您不需要-ResultSetSize参数,因为默认情况下,cmdlet将返回所有结果。:是的,拆分。。。。trim真让我受不了。简单:$cellText-split','[0]。TrimImport excel在尝试使用[-StartRow][-EndRow]检查原始数据时会产生错误的结果。它给出了第3行的开始和第4行的结束结果。绝对糟糕。试了10次。为了循环查看每个原始数据,我使用了:1..458 | ForEach对象{$a=$ws.Cells.Item$|,1.Value2$b=$ws.Cells.Item$|,2.Value2,其中$|是原始数据的编号。它比导入Excel更好地循环查看它们。获取ADUser-Filter EmployeeID-eq$a |设置ADUser-title$b-Verbose-ErrorAction Stop | Out File test100.txt-Append