AD 用户脚本更正 [英] AD Users Script correction
问题描述
谁能更正一下?
用户 1 和用户 2 的单独运行运行良好并附加结果
Individual runs of user1 and user 2 running good and appending results
(get-aduser -Identity user1 -Properties memberof | select -expand memberof | get-adgroup) |
select Name, groupscope | Out-File -Append c:\scripts\resultsusersad.txt
(get-aduser -Identity user2 -Properties memberof | select -expand memberof | get-adgroup) |
select Name, groupscope | Out-File -Append c:\scripts\resultsusersad.txt
当我尝试将两个用户保存在一个文本文件中并用于循环时,出现错误.这就是我所做的,如下(更新):
When I tried to save both users in a text file and used for loop I am getting error. This is what I did, given below (Update):
$file = Get-Content -path "c:\scripts\usersad.txt"
$file = Get-Content -path "c:\scripts\usersad.txt"
foreach ($i 在 $file 中){(get-aduser -Identity $($i) -Properties memberof | select -expand memberof | get-adgroup) |选择名称,组范围 |添加内容 -Path c:\scripts\resultsusersad.txt}
foreach ($i in $file) { (get-aduser -Identity $($i) -Properties memberof | select -expand memberof | get-adgroup) | select Name, groupscope | Add-Content -Path c:\scripts\resultsusersad.txt }
请纠正我做错的地方.
推荐答案
我总是遇到输出文件的问题.
I always have trouble with out-file.
我会做的是:
要么在脚本中创建一个新文件,要么已经创建并等待.
Either create a new file in the script, or have one already created and waiting.
可变输出.类似的东西
$Var1 = @(user1 -Properties memberof | select -expand memberof | get-adgroup) |选择名称,组范围)
$Var1 = @(user1 -Properties memberof | select -expand memberof | get-adgroup) | select Name, groupscope)
使用添加内容"写入文件
Use 'Add-Content' to write to the file
Add-Content -Path .\myfile.txt -Value $Var1
Add-Content -Path .\myfile.txt -Value $Var1
我会将字符串作为新行追加到前一行的正下方.我曾经使用类似的方法从 AD 中抓取数据来构建 CSV.
I it will append the string as a new line right under the previous one. I use to use a similar method to build CSVs from grabbing data from AD.
这篇关于AD 用户脚本更正的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!