1

I'm working on a script in VBScript (inside Sparx EA) to validate the users and groups of an Azure Entra ID (aka Azure AD)

Now since it seems to be much easier to use Powershell to get that information from Azure, I wrote a powershell script and execute that from VBScript like this:

dim shell
set shell = CreateObject("Wscript.shell")
shell.run "powershell -file " & script.FullPath

My powershell script creates a number of CSV files containing the info I need. When the powershell script is finished, I read those files in VBScript.

dim groups
set groups = getGroupsFromFile(script.FullPathWithoutExtension & "_AzureADGroups.csv")
dim users
set users = getUsersFromFile(script.FullPathWithoutExtension & "_AzureADUsers.csv")
'link users with groups
readMembershipsFromFile script.FullPathWithoutExtension & "_AzureADUserGroups.csv", users, groups

Then I cleanup by deleting the CSV files created by my Powershell script.

Instead of this workaround with the CSV files, I would much rather get a list of user objects in VBScript, but I haven't found a way to do that.

I know it's possible to return an integer using the exit command, or a string using the StdOut from this question: How to return PowerShell variable to VBScript

But I haven't found a way to return objects or lists of objects from Powershell to VBScript.

5
  • 1
    Change the PowerShell script to use ConvertTo-Csv instead of Export-Csv - then read the CSV contents directly from standard output Commented Jan 18, 2024 at 11:44
  • 2
    Short answer - you can't pass PowerShell / dotnet object references across process boundaries. Even powershell remoting uses an interim serialization format and the "received" objects are sometimes just synthetic propertybags rather than "real" objects - see devblogs.microsoft.com/powershell/…. The best you could do is maybe serialize (e.g. ConvertTo-Csv or json / xml) the output in PowerShell, send it to StdOut with write-host and receive / reconstruct it again from StdIn inside the VBScript code per your linked answer. Commented Jan 18, 2024 at 11:45
  • 1
    Thanks @MathiasR.Jessen and @ mclayton for the suggestion. Since I need several differents sets of data the current workaround using CSV files seems OK. BTW "This is not possible because..." is also an answer, so if you post it as an answer I can accept it. Commented Jan 18, 2024 at 12:10
  • Why not rewrite the vbs in powershell ? Commented Jan 18, 2024 at 12:40
  • @Civette because Sparx EA's scripting environment doesn't support powershell. And even then; rewriting thousands of lines of scripts isn't a job I would look forward too. Commented Jan 18, 2024 at 12:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.