Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTLite fails to run PowerShell script with Chocolatey CLI commands #3411

Closed
6 tasks done
JuhaszBalint2 opened this issue Apr 2, 2024 · 11 comments
Closed
6 tasks done

Comments

@JuhaszBalint2
Copy link

JuhaszBalint2 commented Apr 2, 2024

Checklist

  • I confirm there are no unresolved issues reported on the Chocolatey Status page.
  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my problem.
  • I have verified this is not an issue for a specific package.
  • I have verified this issue is not security related.
  • I confirm I am using official, and not unofficial, or modified, Chocolatey products.

What You Are Seeing?

Choco install fails when I run my script. It's supposed to work but it's not. I have to manually restart the powershell terminal for the script to work, this is unacceptable and used to NOT be the case at all.

I use the freeware called NTLIte to call scripts as admin, I used to use this exact same script with the exact same type of logging with great success, this is no more. Something must've changed on chocolatey's backend and I'd like some help.

What is Expected?

When NTLite calls this script:

# Set the log directory path
$logDirectory = "C:\ChocolateyClient_Install_Logs"
$logFile = Join-Path -Path $logDirectory -ChildPath "InstallLog_$(Get-Date -Format 'yyyy-MM-dd_HH;mm;ss').txt"

# Ensure the log directory exists
if (-not (Test-Path -Path $logDirectory)) {
    New-Item -Path $logDirectory -ItemType Directory | Out-Null
}

# Combine setting execution policy, configuring security protocol, and Chocolatey install script
$scriptBlock = {
    Set-ExecutionPolicy Bypass -Scope Process -Force
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
    try {
        iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    } catch {
        Write-Error $_.Exception.Message
    }
}

# Execute the script block and capture all output directly to the log file, excluding PowerShell transcript metadata
& $scriptBlock *>&1 | Out-File -FilePath $logFile

Write-Host "Installation and logs have been directed to $logFile"'

This calls the installation script block as admin and it successfully installs the chocolatey client as ADMIN.

Immediately afterwards, as the second "script call" (SEPARATE powershell window), NTLite calls this script, as admin:

`Set-ExecutionPolicy Bypass -Scope Process -Force

# Define the directory where logs will be stored
$logDirectory = "C:\ChocolateySoftwareInstallLogs"

# Create the directory if it doesn't exist
if (-not (Test-Path -Path $logDirectory)) {
    New-Item -Path $logDirectory -ItemType Directory | Out-Null
}

# Define the log file name based on the current date and time
$logFileName = "Software_Installation_Log_$(Get-Date -Format 'yyyy-MM-dd_HH;mm;ss').txt"
$logFilePath = Join-Path -Path $logDirectory -ChildPath $logFileName

# Initialize the answer variable
$answer = $null

# Loop until a valid answer is given
while ($answer -ine "Yes" -and $answer -ine "No") {
    $answer = Read-Host "Is this a gaming PC? (Yes/No)"
    # Normalize the case for comparison
    $answer = $answer.Trim().ToLower()
    
    # If the answer is still invalid, inform the user and loop will repeat
    if ($answer -ne "yes" -and $answer -ne "no") {
        Write-Host "Invalid input. Please enter 'Yes' or 'No'."
    }
}

$commands = @("choco install qbittorrent -y")

# Check the user's input and append gaming-related software commands if 'Yes'
if ($answer -eq "yes") {
    $commands += @(
        "choco install ea-app -y",
        "choco install origin -y",
        "choco install nvidia-geforce-now -y",
        "choco install geforce-experience -y",
        "choco install steam -y",
        "choco install bethesdanet -y",
        "choco install epicgameslauncher -y",
        "choco install goggalaxy -y",
        "choco install playnite -y",
        "choco install firefox -y",
        "choco install rockstar-launcher -y"
    )
}

# Execute each command, displaying output in the terminal and logging it
foreach ($command in $commands) {
    Invoke-Expression $command 2>&1 | Tee-Object -FilePath $logFilePath -Append
}

Write-Host "Installation complete. Logs have been saved to $logFilePath"`

Which will install the necessary packages as admin.

The problem is as follows: The second script, directly above, does NOT install the packages. It displays the prompt no problem (Gaming PC? Yes or no?) but then immediately after I type in the answer (yes or no - case insensitive), it does not install anything, and it does not create a log file (only a log directory). So the "chocolatey" part of it is NOT working.

IF, however, I manually open a second powershell terminal and put in the exact same script (above), everything works perfectly.

How Did You Get This To Happen?

See explanation ABOVE

The problem is as follows: The second script, directly above, does NOT install the packages. It displays the prompt no problem (Gaming PC? Yes or no?) but then immediately after I type in the answer (yes or no - case insensitive), it does not install anything, and it does not create a log file (only a log directory). So the "chocolatey" part of it is NOT working.

IF, however, I manually open a second powershell terminal and put in the exact same script (above), everything works perfectly.

System Details

  • Operating System: Windows 11 23H2 latest
  • Windows PowerShell version: Powershell 5.1
  • Chocolatey CLI Version: Latest idk the version
  • Chocolatey Licensed Extension version: No, this is the free version
  • Chocolatey License type: free version
  • Terminal/Emulator: Powershell?

Installed Packages

None because chocolatey fails unexpectedly

Output Log

None because chocolatey fails unexpectedly

Additional Context

Idk I'm very angry and frustrated

@pauby
Copy link
Member

pauby commented Apr 2, 2024

Something must've changed on chocolatey's backend and I require explanation and help. And a fix.

Are you a Chocolatey for Business customer? If so, can you run choco support to find out what your support options are?

If not, then we provide support on a best efforts basis for the free Chocolatey CLI.

@JuhaszBalint2
Copy link
Author

Something must've changed on chocolatey's backend and I require explanation and help. And a fix.

Are you a Chocolatey for Business customer? If so, can you run choco support to find out what your support options are?

If not, then we provide support on a best efforts basis for the free Chocolatey CLI.

Of course not, I specified the free version in the OP. I'm not a paying customer, so to speak.

@pauby
Copy link
Member

pauby commented Apr 2, 2024

The reason I ask is that you have used language such as:

require explanation and help. And a fix.

There is no expectation of support, or a fix for the free Chocolatey CLI version. It is on a best efforts basis as I said. I want to set that expectation with you just now. I also want to draw your attention to the Code of conduct when communicating.

We don't support running Chocolatey CLI within NTLite. Does the script work outside of NTLite?

UPDATE: I've fixed the formatting above and can now read it.

You said this:

IF, however, I manually open a second powershell terminal and put in the exact same script (above), everything works perfectly.

So the script works when run from PowerShell directly but doesn't work when NTLite runs it? That would suggest this is an NTLite issue. Have you raised an issue with them?

@JuhaszBalint2
Copy link
Author

The reason I ask is that you have used language such as:

require explanation and help. And a fix.

There is no expectation of support, or a fix for the free Chocolatey CLI version. It is on a best efforts basis as I said. I want to set that expectation with you just now. I also want to draw your attention to the Code of conduct when communicating.

We don't support running Chocolatey CLI within NTLite. Does the script work outside of NTLite?

Okay I'll re-word my OP then.

Yes it does but this isn't NTLite's fault since I used this exact same script in the past in the exact same manner, nothing has changed regarding NTLite. Or my script. So the logical explanation is that Chocolatey must've been changed on the back-end.

@pauby
Copy link
Member

pauby commented Apr 2, 2024

So the logical explanation is that Chocolatey must've been changed on the back-end.

If the script works outside of NTLite, then that would confirm nothing has changed on the 'back-end'. It would also confirm that Chocolatey CLI is behaving as expected.

If the same script doesn't work inside of NTLite, then that would suggest the problem lies with NTLite.

My suggestion would be to raise an issue with NTLite in the first instance.

Thinking out loud, perhaps the version of PowerShell has been updated and NTLite doesn't work with it.

@JuhaszBalint2
Copy link
Author

So the logical explanation is that Chocolatey must've been changed on the back-end.

If the script works outside of NTLite, then that would confirm nothing has changed on the 'back-end'. It would also confirm that Chocolatey CLI is behaving as expected.

If the same script doesn't work inside of NTLite, then that would suggest the problem lies with NTLite.

My suggestion would be to raise an issue with NTLite in the first instance.

Thinking out loud, perhaps the version of PowerShell has been updated and NTLite doesn't work with it.

All the other powershell and batch scripts work fine with NTLite tho. And I cannot see anything wrong with my scripts in the OP. I made sure there was gonna be extensive logging for this reason

Are you talking about Powershell 7.4 btw? Supposedly the latest version. I checked and my machines run on 5.1

@pauby
Copy link
Member

pauby commented Apr 2, 2024

Are you talking about Powershell 7.4 btw? Supposedly the latest version. I checked and my machines run on 5.1

Not specifically that version. But yes, a version.

Unfortunately, as the script works directly, there isn't anything we can do. I know I'm repeating myself, but we don't provide support running Chocolatey CLI through NTLite.

@JuhaszBalint2
Copy link
Author

JuhaszBalint2 commented Apr 2, 2024

Are you talking about Powershell 7.4 btw? Supposedly the latest version. I checked and my machines run on 5.1

Not specifically that version. But yes, a version.

Unfortunately, as the script works directly, there isn't anything we can do. I know I'm repeating myself, but we don't provide support running Chocolatey CLI through NTLite.

But didn't you say you provide support on a best-efforts basis? So if I put enough effort into the logging and details, surely you would be willing to? You or the dev team. I suppose you're on it. (on the dev team)

@pauby
Copy link
Member

pauby commented Apr 2, 2024

But didn't you say you provide support on a best-efforts basis?

Yes. For open-source Chocolatey CLI, in areas we support.

So if I put enough effort into the logging and details, surely you would be willing to? You or the dev team. I suppose you're on it.

If you can point to the issue being in Chocolatey CLI, then absolutely. But nothing that you have provided so far indicates that.

@pauby pauby changed the title Choco install runs for 2 seconds then disappears and fails to install anything NTLite fails to run PowerShell script with Chocolatey CLI commands Apr 3, 2024
Copy link

github-actions bot commented May 8, 2024

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue will be closed in 14 days if it continues to be inactive.

@github-actions github-actions bot added the Pending Closure This issue has been marked as having no response or is stale and will soon be closed. label May 8, 2024
Copy link

Dear contributor,

As this issue seems to have been inactive for quite some time now, it has been automatically closed.
If you feel this is a valid issue, please feel free to re-open the issue if / when a pull request
has been added.
Thank you for your contribution.

@pauby pauby removed 0 - Waiting on User No Response / Stale Pending Closure This issue has been marked as having no response or is stale and will soon be closed. labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants