Когда я Write-Host
из моего файла .ps1, я вижу:
Parentfolder >> ChildFolder
При выводе в файл я вижу:
ParentFolder
>>
ChildFolder
Я использую простой write-host ($childgroup.name), ">>", ($object.samaccountname)
Когда я пытаюсь вывести ту же информацию с помощью Return
, Out-File
, Export to CSV
и т. Д., Я получаю 3 строки для того, что Write-Host
печатает как одну строку.
Я просто хочу, чтобы выходной файл был в том же формате, что и выходной файл Write-Host
.
как просили:
function getchildgroups($groupname) {
# Get initial group details and members
$childgroup = get-adgroup $groupname -properties member
# Only continue if this group has members
if (($childgroup.member).count -gt 0) {
# Loop through each member of the group
foreach ($memberobject in $childgroup.member) {
try {
$object = get-adobject $memberobject -properties *;
# If the member of the group is another group
if ($object.objectclass -eq "group") {
# Print it to the screen
write-host ($childgroup.name),">>", ($object.samaccountname)
#$cgname = $childgroup.name
#$objname =$object.samaccountname
#Return (($cgname, ">>", $objname)) >>
c:\Temp\NestedGroups.txt
# Recursive lookup the members of the sub-group (if
not self-nested)
if ($memberobject -ne $object.distinguishedname) {
getchildgroups($object.distinguishedname);
}
}
} catch {}
}
}
}
# Run the function with your group name
$Groups = Get-Content C:\temp\ListOfFolders.txt
Foreach ($Group in $Groups){
getchildgroups("$group")
}