powershell add objects via -outvariable +variable in a function -


I'm not sure if the imported session window is running in case

I have a function in one Trying to add some variable values ​​to the array

  $ session = new-PSSession - ConfigurationName Microsoft.Exchange -ConnectionUri "http: // emailserver / powershell /" -Authentication Kerberos Import-PSSession $ session -allowclobber Add-PsSnapin Microsoft.SharePoint.PowerShell $ GROUP1 = "Accounting" $ Group2 = "Human Resources" function AddUsersToGroups {Write Output $ Group1 -outvariable + Ad Group Rights Group $ 2 -outvariable + Ad Group}  

When I highlighted and run lines from a Powershell ISE they work properly For more variables you can create $ AdGroups and the combined data exists there.

But when I run the function, I see there is output and no variables are created.

  psc: \ windows \ system32 & gt; AddUserToGroups Group 1 Group 2  

A little stumped I tried to create a variable $ AdGroups = @ () as the first line, but also Fails

Not sure what you are trying to achieve, but AdGroups variable will only be available in the scope of the AddUsersToGroups function.

A way to do this solving adding script: scope, like the following:

  function AddUsersToGroups {write-output $ Group1 -outvariable + Script: ad group, right-out $ group 2 -outvariable + script: ad group}  

Now you're calling out to access the $ Ad Group Goes should be enabled.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -