Chocolatey Installation Process Logging



  • I have a PowerShell script set up to install some software, one of which is Chocolatey.

    To install Chocolatey, I have:

    Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
    Set-Variable "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin\"
    

    This works great on a lot of things, no issues there.

    However, on a few systems, Chocolatey fails to install.

    I would like to output (append) everything the first line does to a specified log file, but I am a bit unsure how to do this due to the install happening to a downloaded "install.ps1" file the first line grabs.

    Does anyone have any ideas?

    I'm trying to get ANY info as to why it's failing, so even outputting the results of the line itself to the log file would help.



  • Doesn't work on Windows 7, no Invoke-Expression 😞



  • @scottalanmiller said in Chocolatey Installation Process Logging:

    Doesn't work on Windows 7, no Invoke-Expression 😞

    You will have install the latest Windows Management Framework.
    https://docs.microsoft.com/en-us/powershell/wmf/readme



  • @scottalanmiller said in Chocolatey Installation Process Logging:

    Doesn't work on Windows 7, no Invoke-Expression 😞

    Specifically Windows 7 limitation, or it doesn't work on certain versions of PowerShell?

    We have a bunch of Windows 7 machines running PS 5.1.



  • Verified that Chocolatey has in fact installed on Windows 7 using that PowerShell script (using Invoke-Expression).

    So it's something else stopping the install.

    On one particular Win7 machine, it is running PowerShell 5.1 (which that itself requires the updated WMF).

    So back to the question, how do I get the output of the Chocolatey install to append to a log file?



  • @tim_g Chocolatey normally logs itself. Is something wrong with that log?



  • @tim_g said in Chocolatey Installation Process Logging:

    @scottalanmiller said in Chocolatey Installation Process Logging:

    Doesn't work on Windows 7, no Invoke-Expression 😞

    Specifically Windows 7 limitation, or it doesn't work on certain versions of PowerShell?

    We have a bunch of Windows 7 machines running PS 5.1.

    The version of PS on Windows 7 by default lacks that command.



  • @scottalanmiller said in Chocolatey Installation Process Logging:

    @tim_g said in Chocolatey Installation Process Logging:

    @scottalanmiller said in Chocolatey Installation Process Logging:

    Doesn't work on Windows 7, no Invoke-Expression 😞

    Specifically Windows 7 limitation, or it doesn't work on certain versions of PowerShell?

    We have a bunch of Windows 7 machines running PS 5.1.

    The version of PS on Windows 7 by default lacks that command.

    Yes a lot of great stuff is lacking in old PS versions. That's why it's good to keep systems up to date with things like PowerShell. It helps with so much.



  • @jaredbusch said in Chocolatey Installation Process Logging:

    @tim_g Chocolatey normally logs itself. Is something wrong with that log?

    It's not getting that far. No c:\programdata\chocolatey which is where the log would be.



  • @tim_g said in Chocolatey Installation Process Logging:

    @jaredbusch said in Chocolatey Installation Process Logging:

    @tim_g Chocolatey normally logs itself. Is something wrong with that log?

    It's not getting that far. No c:\programdata\chocolatey which is where the log would be.

    Why are you using your own made up command to run the install?

    Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))



  • @jaredbusch said in Chocolatey Installation Process Logging:

    iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

    iex is an alias to Invoke-Expression

    @jaredbusch said in Chocolatey Installation Process Logging:

    Set-ExecutionPolicy Bypass -Scope Process -Force;

    I don't need this part, because it's running as a computer startup script via Group Policy.

    @jaredbusch said in Chocolatey Installation Process Logging:

    Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

    So, it's the same thing... nothing made up, you just give me the exact same thing I'm already doing.



  • Wait.. I thought Invoke-Expression has existed for a long time..

    It is Invoke-WebRequest that was in Powershell3+



  • Does the Chocolatey installer grab anything from anywhere other than *.chocolatey.org?



  • @tim_g said in Chocolatey Installation Process Logging:

    Does the Chocolatey installer grab anything from anywhere other than *.chocolatey.org?

    No. You can look in the script to see that.



  • [[email protected] ~]$ grep http install.ps1 
    # at https://github.com/chocolatey/chocolatey.org
    #   http://www.apache.org/licenses/LICENSE-2.0
      $url = "https://chocolatey.org/api/v2/package/chocolatey/$chocolateyVersion"
          # http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-expected/ plus comments
      Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to do one or more of the following: (1) upgrade to .NET Framework 4.5+ and PowerShell v3, (2) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally), (3) use the Download + PowerShell method of install. See https://chocolatey.org/install for all install options.'
      $url = 'https://chocolatey.org/api/v2/Packages()?$filter=((Id%20eq%20%27chocolatey%27)%20and%20(not%20IsPrerelease))%20and%20IsLatestVersion'
      Download-File 'https://chocolatey.org/7za.exe' "$7zaExe"
    [[email protected] ~]$ 
    


  • Well I figured out the issue preventing the install of Chocolatey.

    It was because these specific machines are on an off-internet network, and were also NOT connecting through a proxy server.

    After applying a .reg file to set the computer to use the proxy server, Chocolatey installed, and therefore salt-minion installed, too, (after whitelisting .saltstack.com on the proxy servers). I entered a pssession on the machine and seen that Chocolatey installs salt-minion from the saltstack.com repo. All is well now, so long as off-internet computers are using a proxy server.

    Script log file:

    2018-03-23 11:18:52 Checking for Salt Minion process.
    2018-03-23 11:18:52 Salt Minion is NOT running. Attempting to start.
    2018-03-23 11:18:52 Salt Minion executable is missing. Can't start.
    2018-03-23 11:18:52 Salt Minion is still NOT running. Attempting to reinstall Salt Minion and Chocolatey.
    2018-03-23 11:18:52 Checking for Salt Minion process after reinstall attempt.
    2018-03-23 11:18:52 Salt Minion is still NOT running. Reinstall FAILED.
    2018-03-23 11:18:52 Email sent to ****@****.com - Salt Minion reinstall FAILED on ****03
    2018-03-23 11:18:52 Checking if Chocolatey is functional.
    2018-03-23 11:18:52 Chocolatey is functional.
    2018-03-23 11:23:50 Checking for Salt Minion process.
    2018-03-23 11:23:50 Salt Minion is NOT running. Attempting to start.
    2018-03-23 11:23:50 Salt Minion executable is missing. Can't start.
    2018-03-23 11:23:50 Salt Minion is still NOT running. Attempting to reinstall Salt Minion and Chocolatey.
    2018-03-23 11:23:50 Checking for Salt Minion process after reinstall attempt.
    2018-03-23 11:23:50 Salt Minion is running. Reinstall successful.
    2018-03-23 11:23:50 Email sent to ****@****.com - Salt Minion reinstall successful on ****03
    2018-03-23 11:23:50 Checking if Chocolatey is functional.
    2018-03-23 11:23:50 Chocolatey is functional.
    

    However, I still would like to know how to have the Chocolatey installer append it's install status to a log file from my script.


Log in to reply