我试图写一个脚本来看看用户和他们是什么广告组的一部分,寻找一个特定的组,有多个“子组”.例如VPN-GRP-ONE,VPN-GRP-TWO,VPN-GRP-THREE.
我试着使用一些东西,我发现在一些演示,但它不工作的权利,因为它希望ActiveDirectory模块导入使用get-aduser,我们不允许安装新的模块,我们还没有。(我没有ActiveDirectory在我的可用模块)
我想用用途:
$list1 = C:\Users\MrAoxx\Documents\List1.txt
foreach ($_ in $list1) {
net user $_ /domain}
字符串
我希望输出,然后我可以采取下一步管道,以一个新的文本文件,并开始剥离我需要它得到的只是广告组的名称,我正在寻找即:一,二,三。但它所做的一切就是打开txt文件,没有别的。
3条答案
按热度按时间qhhrdooz1#
我看到你已经接受了一个答案,然而,这里有其他的方法来减轻你的这种努力。所以,至于这个......
--- '(我的可用模块中没有ActiveDirectory)' ---
.你甚至需要在你的系统上实际安装/启用它们才能使用它们。这就是隐式PSRemoting的用途,和/或使用内置的.Net命名空间或adsiphon。
Use PowerShell Active Directory Cmdlets Without Installing Any Software
字符串
Powershell Remote Use of Module Commandlets (Remoting Import-Module)的
型
Working with Active Directory using PowerShell ADSI adapter的
型
g52tjvyc2#
这并不有趣,但在这里你去-注意,这是绝对可能的,足够长的组名称将被截断:
字符串
我将逐步介绍这是如何工作的:
1.获取从文件读取的当前用户的
net user
输出1.选择所有包含 * 的行,并将输出转换为字符串,删除前导和尾随空格。
1.为了便于处理,将输出重新拆分为每行一个数组。
1.对于输出的每一行,删除前29个字符,并通过
*
字符分割文本的其余部分。1.从最终数组输出中删除所有空字符串
这就是为什么你应该选择installing RSAT tools的原因。下面是你如何使用
Get-ADUser
:型
kwvwclae3#
字符串
这是我需要的方式,感谢@LotPings的答案。