【发布时间】:2018-10-15 12:30:38
【问题描述】:
我正忙着编写一个脚本,其中声明了一个变量,其中包含您可以在提示中输入的用户信息。 当我看到无法使用电子邮件地址(2000年之后的登录名)解锁帐户时,我想到了这个方法。 但我不知道我做错了什么。
这是我现在正在运行的代码。
Import-Module ActiveDirectory
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your name", "Name", "$env:username")
$Test = Get-ADUser -Filter { EmailAddress -eq $name } | Select SamAccountName
Unlock-ADAccount -Identity $Test
我得到的错误是
Unlock-ADAccount : Object reference not set to an instance of an object.
At C:\Users\Admcbl\Documents\Powershell.ps1:5 char:1
+ Unlock-ADAccount -Identity $Test
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Activ...ement.ADAccount:ADAccount) [Unlock-ADAccount], NullReferenceException
+ FullyQualifiedErrorId : Object reference not set to an instance of an object.,Microsoft.ActiveDirectory.Management.Commands.UnlockADAccount
【问题讨论】:
-
您遇到什么错误?到目前为止,您尝试过什么来解决此问题?快速浏览一下,这可能是因为您在
$Test和Get-ADUser之间缺少一个=符号 -
同样
SamAccountNam应该是SamAccountName。 -
我是草率复制并粘贴到这里,但我收到的错误消息是我在帖子中更新的内容
标签: powershell variables account