r/scripting • • Jun 26 '18

Copying information between Active Directory tabs with Powershell

Hey guys. What I'm looking for may or may not be simple, but I can't seem to find exactly what I'm looking for with Google searches.

Basically I'm looking to copy every group from the 'Member of' tab and paste it into the Notes section of the Telephone tab. We do this when disabling our users in case we need to find the info again. Currently it's a manual process and it would save us a lot of time with a script.

Let me know if any more information is needed, as I'm a total rookie here and may have missed some details. Any help would be big time appreciated!

1 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/JimmyRecard51 Jun 27 '18

I removed the $ before memberof and got "memberof : The term 'memberof' is not recognized as the name of a cmdlet, function, script file, or operable program."

I may need this explained like I'm 5. Still unsure what I'm doing wrong.

2

u/Ta11ow Jun 27 '18

Once it's run just call the variable again:

$memberof

Or you can just take off the variable assignment to get it to drop all data to output:

(Get-ADUser -Identity $Username -Properties MemberOf).MemberOf |
    ForEach-Object {
        if ($_ -match '(?<=OU\=).*(?=,.+)') {
            $matches[0]
        }
    }

2

u/JimmyRecard51 Jun 28 '18

You're saying I can run it and then alter it after the fact? I've got no experience with Powershell and just assumed it worked similar to the command prompt. Thank you for your continued help by the way. It'll save my team a lot of time if we can figure this out.

2

u/Ta11ow Jun 28 '18

Yep. The way I put it originally has PS store it in a variable you can use later.

There're definitely some similarities between cmd and PS, but PS is a lot more flexible because it deals in objects and data types -- command prompt is all strings.

1

u/JimmyRecard51 Jun 29 '18

So, I ran:

$memberof = (Get-ADUser -Identity dhopper -Properties MemberOf).MemberOf | ForEach-Object { if ($_ -match '(?<=OU=).*(?=,.+)') { $matches[0] } }

It quickly said something like Loading Active Directory Module and then went back to just showing the script. I tried to retroactively edit the $memberof part but it seemed like I couldn't make any changes. Plus, I'm not sure what exactly to even change. Haha hopefully this will be my last message.

1

u/Ta11ow Jun 29 '18

Yep, that stores the data in the variable $memberof. If you then call the variable by itself on a line, it will output the data it contains.