Avatar of HudRah
 asked on

Modify Distribution Group Members (Scripting)

Hi, I am attempting to script the code presented in article  RE: 3669 "Modify Distribution Group Members" to read in a file with DL names and then upgrade them populating the managed by field. I attempted to do this but get an error on the following line, if ran as part of script:
foreach($g in $groups) { $user = $g.user.tostring().substring($g.user.tostring().indexof("\") + 1);

ERROR: You cannot call a method on a null-valued expression.
At C:\scripts\NEW\DL\NEW\DLmodification-FORLIST-u_test.ps1:32 char:50
+ foreach($g in $groups) { $user = $g.user.tostring <<<< ().substring($g.user.tostring().indexof("\") + 1);
    + CategoryInfo          : InvalidOperation: (tostring:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

When I run it manually, it runs fine. Am I missing something? Any Advice would be greatly appreciated.

Attached is my attempted script.

ExchangePowershellWindows Batch

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes