Need some assistance formatting output

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
notarat
Posts: 24
Last visit: Mon Feb 12, 2018 6:56 am

Re: Need some assistance formatting output

Post by notarat »

jvierra wrote: Thu Feb 08, 2018 1:34 pm The code you posted lists only group membership and has nothing to do with applications.

This is the code you posted:

foreach ($computer in $computers) {
$strCMP=GET-ADComputer $computer –Properties cn,MemberOf
$strGRP=($strCMP.MemberOf | Sort Name | foreach {($_.Split(','))[0].Substring(3)}) -Join ","
$strCMP=($strCMP.cn | foreach {($_.Split('='))[0]}) -Join ","
$strDone=$strCMP+","+$strGRP
Add-Content c:\outputfiles\$dt"ComputersandGroupsList.txt" -value $strdone
}


Note that there is no mention of any products - only computers ad "MemberOf". Did you post the wrong script?
Jvierra,

My company uses AD in some very non-standard ways. Don't ask me why because no one who was here when this was created and implemented is still around.

The "member of" field in our AD is for groups, as you say, but the group(s) your computer is assigned to determine(s) which application(s) are installed on the computer the first time it connects to the domain. Hence, my referral to "member of" as an "application instance package group"

Example

Our admins assign a brand new computer (just the basic OS load) to the "AdobeAcrobatPro_WNX" group, join it to the domain, and deploy it to the user. The user logs in and the update scripts automatically start, which installs Adobe Acrobat Pro for Windows 10 9and all the other applications that user is supposed to have on their computer.)

In essence, because the computer is a "member of" that particular "group", it automatically receives the install for AcorbatPro for Windows 10 (and any security/compatibility updates are automatically applied as they are released over the life span of that application and/or computer)

Those "application instance package" groups are, in turn, assigned to other groups (nested group membership) and the script I posted evidently pulls some, but not all the groups...and I'm not sure why it's grabbing some but not all groups.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need some assistance formatting output

Post by jvierra »

Code: Select all

$outfile = 'c:\outputfiles\' + [datetime]::Today.ToString('yyyyMMdd') + 'ComputersandGroupsList.txt'
Get-Content c:\inputfiles\ngmclist.txt |
    ForEach-Object{
        $computer = $_
        (Get-ADComputer $computer –Properties MemberOf).MemberOf |
        ForEach-Object{
            Get-AdGroup |
            Select-Object @{ n = 'ComputerName'; e = { $computer } }, Name
        }
    } |
    Out-File $outfile
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked