Script doesn't work when compiled to .exe

Ask your Windows 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.
jvierra
Posts: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Fri Jan 05, 2018 1:29 pm

Sapien PowerShell V5 Host (Windows Forms)

User avatar
Chris.Ediger
Posts: 26
Joined: Tue Oct 24, 2017 9:33 am

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

Post by Chris.Ediger » Fri Jan 05, 2018 2:51 pm

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: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Fri Jan 05, 2018 3:09 pm

Please run the script I posted to see if AD actually works on your system.

User avatar
Chris.Ediger
Posts: 26
Joined: Tue Oct 24, 2017 9:33 am

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

Post by Chris.Ediger » Fri Jan 05, 2018 3:15 pm

jvierra wrote:
Fri Jan 05, 2018 3:09 pm
Please run the script I posted to see if AD actually works on your system.
It works.

jvierra
Posts: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Fri Jan 05, 2018 3: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.

User avatar
Chris.Ediger
Posts: 26
Joined: Tue Oct 24, 2017 9:33 am

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

Post by Chris.Ediger » Mon Jan 08, 2018 7:49 am

jvierra wrote:
Fri Jan 05, 2018 3: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: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Jan 08, 2018 9: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.

User avatar
Chris.Ediger
Posts: 26
Joined: Tue Oct 24, 2017 9:33 am

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

Post by Chris.Ediger » Mon Jan 08, 2018 12:01 pm

jvierra wrote:
Mon Jan 08, 2018 9: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: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Jan 08, 2018 12:08 pm

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: 14015
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Jan 08, 2018 12:09 pm

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.

Locked