Page 2 of 3

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

Posted: Fri Jan 05, 2018 1:29 pm
by jvierra
Sapien PowerShell V5 Host (Windows Forms)

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

Posted: Fri Jan 05, 2018 2:51 pm
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?

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

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

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

Posted: Fri Jan 05, 2018 3:15 pm
by Chris.Ediger
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.

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

Posted: Fri Jan 05, 2018 3:27 pm
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.

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

Posted: Mon Jan 08, 2018 7:49 am
by Chris.Ediger
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?

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

Posted: Mon Jan 08, 2018 9:38 am
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.

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

Posted: Mon Jan 08, 2018 12:01 pm
by Chris.Ediger
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?

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

Posted: Mon Jan 08, 2018 12:08 pm
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?

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

Posted: Mon Jan 08, 2018 12:09 pm
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.