chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.05k stars 890 forks source link

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

Closed JuhaszBalint2 closed 1 month ago

JuhaszBalint2 commented 3 months ago

Checklist

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

Installed Packages

None because chocolatey fails unexpectedly

Output Log

None because chocolatey fails unexpectedly

Additional Context

Idk I'm very angry and frustrated

pauby commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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.

github-actions[bot] commented 1 month ago

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[bot] commented 1 month ago

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.