【发布时间】:2022-10-14 22:14:00
【问题描述】:
我正在尝试设置一个 powershell 脚本以自动运行命令以获取所有具有“Remotepowershellenabled”$True 的用户帐户的列表,然后将该列表与 2 个管理员组进行比较。之后,我希望它设置不属于 2 个管理员帐户的所有用户帐户,然后将该选项设置为 $false。 当我到达脚本的这一部分时,新变量没有填充任何内容。我知道变量 $UserswithRemotePS 中列出的用户不在 $DomainAdmin 变量中。
$UsersNotDA = $UserswithRemotePS | where {$_.samaccountname -inotin $DomainAdmin}
我通过查看其他几个类似的脚本将这个脚本放在一起,所以我显然错过了一些东西。 任何帮助将不胜感激。
$DomainAdmins = (Get-ADGroupMember -Identity "Domain Admins").samaccountname|out-string
$Exchangeadmins = (Get-ADGroupMember -Identity "ExchangeAdmins").samaccountname|out-string
Get-PSSession|Remove-PSSession
$ExchangePSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ExchangeServer/PowerShell/ -Authentication Kerberos
$UserswithRemotePS = (Invoke-Command -Session (Get-PSSession) {Get-User -ResultSize Unlimited -Filter 'RemotePowerShellEnabled -eq $true'}).samaccountname|out-string
$UsersNotDA = $UserswithRemotePS | where {$_.samaccountname -notin $DomainAdmin}
【问题讨论】:
-
目前你有一个错字:
-inotin应该是:-notin。不知道这些变量中有什么很难帮助... -
我从其他地方拉了它,并假设它应该代表“不在”,但我也尝试将它作为 -notin 以及仍然没有运气。一旦我摆脱了公司的具体细节,我会添加代码
标签: powershell automation