【发布时间】:2020-05-14 21:44:37
【问题描述】:
我正在尝试获取连接到 Windows RAS 服务器的用户列表(基本上是连接 VPN 的用户列表)并获取他们的 AD 帐户属性,
以下命令返回数据如下(它返回 100 多个用户,但为了简洁我只展示了一个)
Get-RemoteAccessConnectionStatistics | fl
ClientIPAddress : 1.2.3.4
UserName : {Bob.Jones@company.com}
ConnectionDuration(s) : 696055
ConnectionType : Vpn
所以我写了以下脚本:
$users = Get-RemoteAccessConnectionStatistics
foreach ($user in $users) {
$UPN = $user.username
Get-ADUser -Filter {UserPrincipalName -eq $UPN }
}
但是在运行脚本时出现以下错误:
Get-ADUser : Invalid type 'System.String[]'.
Parameter name: userPrincipalName
At line:7 char:1
+ Get-ADUser -Filter {UserPrincipalName -eq $UPN }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
有人可以帮忙吗?我不知道我做错了什么
【问题讨论】:
-
错误提示
$UPN包含一个字符串数组。仔细检查其内容。
标签: powershell