I created a python program that collects information from active directory. To gather the info, the program runs certain PowerShell scripts to connect to the server.
After debugging seemed to be done, I converted the file into a .exe using pyinstaller -onefile -w. When I run the .exe the gui opens up without issue, but when I try to execute the commands that connect to the active directory server, the program crashes. There is no error code in the console when this happens. After troubleshooting on my own for a minute, I realized that if I create the .exe without the "-w" making the console run in the background, the program works fine. The problem is that I really don't want the console running in the background as this is supposed to be a user-friendly application.
Is there anyway that I can run the program without the console window or at least keep it hidden when the gui is running? Also, apologies if this is a dumb quesion. I am new to programming and even newer to powershell.
p.s. here's a snippet of the python code that runs the PowerShell script:
pscommandUsers = '$users = ' + userNameList + ';'
pscommandHeader = 'foreach ($u in $users) {'
pscommandGroups = '$Group = Get-ADPrincipalGroupMembership -Identity $u | ' \
'Select-Object -ExpandProperty Name | Sort-Object | ft -hidetableheaders;'
pscommandTitles = '$ADProp = Get-ADUser -Identity $u -Properties Department, ' \
'Title | ForEach-Object {$_.Department, $_.Title};'
pscommandFooter = '$Array = $ADProp, $Group; Write-Output "*****" $Array}'
...process = subprocess.Popen(["powershell.exe", pscommand],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, error_description = process.communicate()