Script doesn't work when compiled to .exe

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

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 6 years and 2 months 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.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script doesn't work when compiled to .exe

Post by jvierra »

Sapien PowerShell V5 Host (Windows Forms)
User avatar
Chris_Ediger
Posts: 45
Last visit: Tue May 09, 2023 8:35 pm

Re: Script doesn't work when compiled to .exe

Post by Chris_Ediger »

Still doesn't work. I get a built in error that I put into my script but I'm guessing it is because of the same problem as before.

This is the full first part of the script. When I compile as a Windows form I get as far as prompting for credentials then I get my username/password not correct error. This works just fine before I compile it.

$CreateNewUser_Load={
#TODO: Initialize Form Controls here
$Global:ADUsers = Get-ADUser -Filter * -Properties DisplayName,DistinguishedName,HomeDirectory,Department,MemberOf,SAMAccountName,CN,EmailAddress -SearchBase "<mysearchbase>" | Where-Object { $_.DisplayName -notlike "zz*" }
$ADUserDisplayNames = $ADUsers | Select-Object -ExpandProperty DisplayName

do {

$Global:DomainAdminCredentials = Get-Credential -message "Enter Domain Admin credentials" #Read credentials
$username = $DomainAdminCredentials.username
$password = $DomainAdminCredentials.GetNetworkCredential().password

# Get current domain using logged-on user's credentials
$CurrentDomain = "LDAP://" + ([adsi]"").DistinguishedName
$domain = New-Object System.DirectoryServices.DirectoryEntry ($CurrentDomain, $UserName, $Password)

if ($domain.Name -eq $null) {
[void][System.Windows.Forms.MessageBox]::Show("Username or Password Incorrect", "Warning")
$Authenticated = $false
}
else {
$Authenticated = $true
}
}
while ($Authenticated -eq $false)

Is there any way to log what is going on when the script executes?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script doesn't work when compiled to .exe

Post by jvierra »

Please run the script I posted to see if AD actually works on your system.
User avatar
Chris_Ediger
Posts: 45
Last visit: Tue May 09, 2023 8:35 pm

Re: Script doesn't work when compiled to .exe

Post by Chris_Ediger »

jvierra wrote: Fri Jan 05, 2018 2:09 pm Please run the script I posted to see if AD actually works on your system.
It works.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script doesn't work when compiled to .exe

Post by jvierra »

Then your code has a problem and the script needs to be rebuilt a bit at a time until you find the issue. There is likely a typo somewhere.
User avatar
Chris_Ediger
Posts: 45
Last visit: Tue May 09, 2023 8:35 pm

Re: Script doesn't work when compiled to .exe

Post by Chris_Ediger »

jvierra wrote: Fri Jan 05, 2018 2:27 pm Then your code has a problem and the script needs to be rebuilt a bit at a time until you find the issue. There is likely a typo somewhere.
Why does it work when I run it from within PSS? It only fails when I compile it. And why do scripts that previously compiled properly now fail?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script doesn't work when compiled to .exe

Post by jvierra »

Unfortunately there is not enough information to answer your question. Somewhere you have changed something that is causing your packager to work differently. Be sure you are using all of the correct settings for STA/host type and architecture.
User avatar
Chris_Ediger
Posts: 45
Last visit: Tue May 09, 2023 8:35 pm

Re: Script doesn't work when compiled to .exe

Post by Chris_Ediger »

jvierra wrote: Mon Jan 08, 2018 8:38 am Unfortunately there is not enough information to answer your question. Somewhere you have changed something that is causing your packager to work differently. Be sure you are using all of the correct settings for STA/host type and architecture.
What settings might I have changed? Are there others besides those in the packager settings?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script doesn't work when compiled to .exe

Post by jvierra »

What settings are you using? What is your script trying to do? What are the problems?

Without accurate information no one can be of much help.

Have you tried running from a new account? Have you tried repairing your system?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script doesn't work when compiled to .exe

Post by jvierra »

Also if these are all AD scripts with the same error perhaps you have issues with the AD servers or the network.

Without an accurate error message it would be very hard to analyze this.
This topic is 6 years and 2 months 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.
Locked