Powershell - Variable scope behaves strangely -
I have a small script that reads the members of the AD group and then I have them with an array of users Comparison
To accomplish this, I use some nested loops and if the situation and my big problems are facing, then my $ member
changer suddenly Lose scope and empty
.
I tried to set the radius to $ globals: members
or $ script: members
, which had no effect.
The following is the source code I have. Any suggestion, pushing in the right direction, how it works and how it helps is highly appreciated.
Thanks in advance!
Edit : I have to go ahead with my work, from $ member
variable to out string
Even I am very curious about what happened, so if someone knows what happened, please highlight me.
foreach ($ group in group) {# members $ member = $ group | Get ADGroupMember | Out String # Out String fixes this issue This small print shows $ $ to the members that everything is fine # if a necessary part of each group is needed to match ($ group.Name -Match "Group-AX_User {$ Man = $ match [1]} Foreign exchange ($ $ $ entry result) {# EET entry is a CSV string, drag the first value if ($ Entry-match ". *, `` (. *) `'") {$ TblMan = $ match [1] If ($ tblMan -q $ man) {# Correct the matches of our group together with one in the CRD Rena # Everything is fine, if the members are not zero ($ entry -match "` '(. *) `',` '") {# !!! Suddenly, $ members are zero which has happened to hell? $ M = $ Matches [1] if ($ member. Resource ($ M)) {# also existing entry member # group already has $ Entry}}}}}}
You do not have a scope problem The issue is that you have a group that is not present in the domain. Reach the Line:
$ member = $ group | Get-ADGroupMember
You are assigning $ null
to $ member
.
Because of this, the piping out string works for you because members were assigned empty string. You just do not want to strangle it at all.
Even your discrimination investigation was lying to you.
$ member # With this small print I find that everything is fine
Print members on the last loop, just fine. In the present pass, zero shows nothing. You can then get an error on the $ members. Depending on your script ($ m)
you will see the previous output and give an impression that the scope is lost.
Comments
Post a Comment