Jump to content

Recommended Posts

Posted

We have some machines that do not have the correct settings and I have identified a lot of systems and I have found a handful I can see they are not part of the correct groups. I am trying to cut this down by running a Powershell script to check the computer groups on the list I have created.

 

I am using the following

Import-csv input.csv | ForEach-Object {Get-ADComputer $_.name -Properties memberOf} | Select-Object -Property @{N= "Name";E= {$_.samaccountname}},@{N= "Groups";E={$_.Memberof}} |export-csv -path results.csv -append

 

Now it outputs what I want, but where the comptuer is a member of multiple groups it just pipes this into 1 string. I want the output to be Name, Group but what I am getting is Name, Group,Group,Group

 

I need it to be on each line as I want to then use it to compare against other sources.

 

Can anyone help what I am doing wrong?

Posted

@Steve21 - Thanks for the input, I don't care how it is done to be honest, I just want the output to include the ComputerName, Group membership. I am now using the code below and it outputs the group membership on each line which is good. However it is missing the computerName. I just want to e able to put this into a spreadsheet later to use as comparison.

 

Import-csv input.csv | ForEach-Object { Get-ADComputer $_.name | get-adprincipalgroupmembership | select-object samaccountname} |Export-Csv results.csv -NoTypeInformation #-append

 

I'm basically re-learning PS as I haven't used it properly for years :(

 

The original Script I was using I found on the web, but I've lost the link now.

Posted

In the end I did this...

$path = "results.csv"$Name= Import-csv input.csv | ForEach-Object {Get-ADComputer $_.Name | ForEach-Object { $computer= $_ Get-ADPrincipalGroupMembership -Identity $_| Select-Object @{Name = 'Computer Name'; Expression ={$computer.SamAccountName}},@{Name = 'GroupName'; Expression ={$_.SamAccountName}}}}| Export-Csv -Path $Path -NoTypeInformation

 

I'm sure there was probably a neater way to do it, but it works for what I need at the moment.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...