- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含一堆电子邮件地址的 .txt 文件,我需要获取相应的登录名并将它们导出到另一个文件中。
我写了一个看起来像这样的脚本:
Import-Module ActiveDirectory
$users = get-content C:\users-input.txt
foreach($users in $users){
Get-ADUser -Filter {EmailAddress -eq "$_"} -properties SamAccountName | Select-Object SamAccountName | Export-CSV -Path "c:\users.csv"
}
由于某种原因,结果我只得到一个空文件。谁能告诉我我做错了什么?
最佳答案
这里有几个问题,
您在 Get-ADUser
命令中使用变量 $_
作为电子邮件地址,但这并未定义,因为它仅在使用 ForEach 的循环中使用-对象
。
您在 foreach
中使用相同的变量名称,因此第一个循环会覆盖正在循环的数组。
您正在为每个用户编写 CSV 文件。
试试这个:
Get-Content -Path "c:\users-input.txt" | %{ Get-ADUser -Filter {EmailAddress -eq $_} } | Select-Object SamAccountName | Export-CSV -Path "c:\users.csv"
关于powershell - 如何使用 Powershell 从电子邮件中获取 samaccountname?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47035953/
我想在 Active Directory 中使用 sAMaccountName 搜索用户,其中 sAMaccountName 是 firstName.substring(0,1)+lastName+以
我有一个用户全名列表,我想获取他们的 SAMaccount 名称,但是当我运行我的代码时,我没有得到任何结果。谁有想法? $users = Get-Content C:\users\admin\Des
使用在线 javascript 正则表达式工具,我正在尝试转换它: john doe (vp of ops) [cupertino,CA,USA] Expand/Contract Sally Jone
我可以通过以下 vbs 代码获取特定 ADS 用户的用户详细信息。 Set objConnection = CreateObject("ADODB.Connection") objConnection
我可以通过以下 vbs 代码获取特定 ADS 用户的用户详细信息。 Set objConnection = CreateObject("ADODB.Connection") objConnection
我有这个脚本来提取以字母“m”开头的用户以及他们所属的组。脚本的结果没问题,但我需要 SamAccountName并且组在同一行上并用逗号分隔,以便我可以在 Excel 文件中更好地安排它。有什么建议
我们使用大量 Active Directory 来集成到我们的内部应用程序中。我们通常有一个像“提交者”这样的字段,我们最终会在其中放置用户的 samAccountName。 这看起来不错,但在某些奇
我有这个代码: public static DataTable ExecutesAMAccountNameQuery(string sAMAccountName) {
我有一个属性samaccountname,我可以为用户检索该属性。 但是,samaccount 名称是 AD 特定的,需要 LDAP 标准属性。例如,在查询中,如果我使用 (&(objectCateg
我正在尝试通过针对 CSV 文件中名为“OwnerEmail”(这是用户主体名称)的另一列查询 Active Directory 来填充 CSV 文件中的员工 ID 列。问题是owneremail 列
我有一个包含一堆电子邮件地址的 .txt 文件,我需要获取相应的登录名并将它们导出到另一个文件中。 我写了一个看起来像这样的脚本: Import-Module ActiveDirectory $use
我正在尝试使用 C# 和 .NET 更改组的名称。它适用于以下代码: public void selectADSObject(string LDAP) { Direct
uid 之间有什么区别?和 sAMAccountName Microsoft Active Directory 的属性。 编辑:我知道 sAMAccountName 是必填字段而 uid 不是。有人可
当用户传递 sAMAccountName 和 password 时,我无法进行身份验证。 如果我执行以下操作: env.put(Context.SECURITY_PRINCIPAL, "CN="+us
我需要添加自定义声明“samAccountName”以显示在 token 中(使用 jwt) 首先,我创建了 powershell 脚本 New-AzureADPolicy -Definition @
我的机器有原始版本的 PowerShell v2.0,所以 Get-ADUser不管用。我正在尝试转换 manager来自 distinguishedname 的属性(property)给它SamAc
我需要将几百个 AD 发行组移动到一个新的 OU。我只得到了他们的电子邮件地址,并想制作一个脚本来根据 samaccountname 移动它们。我想知道为什么以下内容不返回任何内容,如果我对电子邮件地
我有以下代码可以更改 LDAP 中的用户密码。如果我使用用户的 CN,它就可以工作,但我不知道我应该做什么才能使其与 sAMA 一起工作。 public static void main(St
目前,我有以下内容,来自 LDAP。 // Get context, based on currently logged on user PrincipalContext domainContext
我实现了一个返回 Active Directory 用户列表的方法,我想像这样检索 SAMAccountName Domain\Administrator。 这是我使用的方法: public Coll
我是一名优秀的程序员,十分优秀!