EXE not working with Import-Module

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
4100260298
Posts: 5
Last visit: Fri Aug 03, 2018 9:37 am

EXE not working with Import-Module

Post by 4100260298 »

Pwoershell Studio 5.4.134 in Sapien Studio
64 bit
64 bit OS
PowerShell Version: v5, v3 same result

I've got a script that loads the active directory module. It then uses it to make changes to AD objects. This works fine when I run it in PS Studio, in an Powershell window, and at the DOS prompt. BUT, when I then compile the code into an EXE, it acts as though the module wasn't loaded.

The code basically boils down to this:

import-module activedirectory
$TargetGroup = "AzureUsers"
$UsersToCheck = Get-ADGroupMember -Identity $TargetGroup

Note the import-module, which doesn't seem to be working in the .EXE. I've tried both Powershell v3 and v5.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: EXE not working with Import-Module

Post by davidc »

Please make sure you have the correct platform / bitness selected, because some modules are 64 bit only.

If the script requires admin rights, you might want to use an elevation manifest:
Elevation Manifest.png
Elevation Manifest.png (33.24 KiB) Viewed 1981 times
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: EXE not working with Import-Module

Post by davidc »

Are you getting an error message?
David
SAPIEN Technologies, Inc.
User avatar
4100260298
Posts: 5
Last visit: Fri Aug 03, 2018 9:37 am

Re: EXE not working with Import-Module

Post by 4100260298 »

Thank you both!

I followed the instructions provided, and they partially resolved the problem. I can run the EXE from explorer, and it works correctly. However, it would not run in the scheduled task. After more troubleshooting, I decided to delete the scheduled task and recreate it. Doing this then resolve the final issue and the EXE is running in the scheduled task as expected.

Thank you both!
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.