WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: bettman on June 16, 2020, 02:38:30 PM

Title: Multiple instances of StrReplace
Post by: bettman on June 16, 2020, 02:38:30 PM
Hi,

I am attempting to write a script which retrieves a list of anyone in the local administrators group. Once I have that, I want to remove certain members/groups from that list and use what is left over. I have the following code which works fine, but I am wondering if there is a cleaner way to do this? Is it possible to nest Strreplace (or a similar function) in a single line of code?

Admins = wntMemberList('','Administrators', @LOCALGROUP,1,0)
Admins = StrReplace(Admins,'.\Administrator','')
Admins = StrReplace(Admins,'XYZ.com\PC Admins','')
Admins = StrReplace(Admins,'XYZ.com\Domain Admins','')

Thank you
Title: Re: Multiple instances of StrReplace
Post by: td on June 16, 2020, 02:52:37 PM
A WIL function is an expression so you can use it anywhere in a statement the makes sense for the function's return type.  So yes, you can nest away to your heart's content; provided you don't exceed maximum line length.  However, code is easier to debug if you don't nest function calls so it is better to get the kinks out of a section of script before entering nesting nirvana.
Title: Re: Multiple instances of StrReplace
Post by: bettman on June 16, 2020, 06:29:18 PM
What is the syntax to be used if I were to nest those strreplace commands into one statement?
Title: Re: Multiple instances of StrReplace
Post by: JTaylor on June 16, 2020, 08:06:32 PM
Admins = wntMemberList('','Administrators', @LOCALGROUP,1,0),'.\Administrator','')
Admins = StrReplace(StrReplace(StrReplace(Admins,'XYZ.com\PC Admins',''),'.\Administrator',''),'XYZ.com\Domain Admins','')
Title: Re: Multiple instances of StrReplace
Post by: bettman on June 17, 2020, 05:31:41 AM
Thank you for the example. That's exactly what I was looking for.
Title: Re: Multiple instances of StrReplace
Post by: JTaylor on June 17, 2020, 05:46:25 PM
Probably obvious but most of the functions can be used in such a way, even with each other.

Jim