Since I switch a lot between languages, I tend to forget what indentation, spacing and termination to use.
So from the Indentation/Length/Spacing/Termination sections in [WayBack] Code Layout and Formatting · PowerShell Practice and Style:
Posted by jpluimers on 2021/09/22
Since I switch a lot between languages, I tend to forget what indentation, spacing and termination to use.
So from the Indentation/Length/Spacing/Termination sections in [WayBack] Code Layout and Formatting · PowerShell Practice and Style:
Posted in .NET, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/09/14
A while ago, I bumped into problems updating UltraVNC through Chocolatey.
It is similar to issues with other packages I have seen in the past: sha256 hash mismatches of which the reported mismatch changes over time, though the version stays the same.
This was tracked down to the actual file download site now needing a correct HTTP referer header. Likely this is to stop automated downloads, which kind of back-fires as ultimately you want to automate download and installation of things as much as possible.
Anyway: this is the [Archive.is] thread (which cannot be archived as Disqus hates archiving in the WayBack machine, and archive.is often fails with it too):
The recent update to 1.2300 fails for me with a file hash error. The install script has
fe3d1135ae0e7b72394a6f3cc137282cb5e6382a55b5ceee72140d28f5ffe961, but the installer as downloaded, and verified via a separate download and hash check has5A42A24BED5A39ACA44443916E5B2C4C259CE8E843E90FD07F7AB3D26CB237C8
Related: Chocolatey got more strict on various URLs being correct; see [WayBack] (UltraVNC) Why has the X64 been removed? · Issue #42 · mkevenaar/chocolatey-packages · GitHub.
–jeroen
Posted in Chocolatey, CommandLine, Communications Development, Development, HTTP, Internet protocol suite, Power User, PowerShell, Software Development, TCP, Windows | Leave a Comment »
Posted by jpluimers on 2021/09/09
When you do a choco upgrade all --yes on a system that – during upgrade – becomes low on disk space, you can end up with a lot of empty .nupkg files.
For those package, Chocolatey will not recognise they are installed any more.
The fix is this:
--force parameter before the --yes parameter like in
choco install --force --yes chocolatey
choco upgrade --all --yesI wrote a few PowerShell scripts assisting me in cleaning up the mess.
choco-list-installed.bat:: https://superuser.com/questions/890251/how-to-list-chocolatey-packages-already-installed-and-newer-version-available-fr choco list --localonly %*
choco-show-installed-package-names.bat:: `--limit-output` does not show Chocolatey version header and count footer. :: `--id-oonly` omits the version number, so you only get the package name choco list --local-only --limit-output --id-only
choco-show-installed-package-names-and-versions.bat:: `--limit-output` does not show Chocolatey version header and count footer. choco list --local-only --limit-output %*
choco-reinstall-empty-nupkg-by-names.ps1There is an environment variable set on installation,
ChocolateyInstall, which is set toC:\Chocolateyby default in versions of Chocolatey less than 0.9.8.27. After that, this defaults toC:\ProgramData\Chocolatey.NOTE: By default, the
C:\ProgramDatafolder on Windows is hidden. You will either need to enable hidden files and folders throughFolder Options | Viewor you can navigate directly to the path shown above by copy/pasting directly into the Windows Explorer address bar.In version 0.9.9 of Chocolatey, it actively moves from the old folder location to the new one.
A convenient way to obtain the string value rather than the dictionary entry (which is technically what
Get-ChildItemis accessing) is to just use the variable syntax:$Env:USERPROFILErather thanGet-ChildItem Env:USERPROFILE.$localpath = "$env:USERPROFILE\some\path"…
Also, the
Join-Pathcmdlet is a good way to combine two parts of a path.$localpath = Join-Path $env:USERPROFILE 'some\path'
<# https://learningpcs.blogspot.com/2009/12/powershell-finding-0-byte-files.html Zero length .nupkg files sorted by oldest first. These are packages that choco will not show and likekly need a forced reinstall. Choco does remember the version that was installed (so not all the choco config is hosed). - https://stackoverflow.com/questions/28235388/where-is-the-chocolatey-installation-path/28239451#28239451 - https://stackoverflow.com/questions/41047123/powershell-concatenate-an-environment-variable-with-path/41047343#41047343 /#> $LibPath = Join-Path $env:ChocolateyInstall 'lib' $NuPkgExtension = 'nupkg' $NupkgFilter = "*.$NuPkgExtension" ## Remove the empty .nupkg files for each argument $args | ForEach-Object { $PackageName = $_ Write-Output "Deleting any empty $PackageName.$NuPkgExtension under $LibPath :" Get-ChildItem -Path $LibPath -Recurse -Filter $NupkgFilter | Where-Object { ($_.Length -eq 0) -and ($_.BaseName -eq $PackageName) } | Sort-Object LastWriteTime | ForEach-Object { $PackageFullName = $_.FullName Write-Output "Deleting $PackageFullName" Remove-Item $PackageFullName } } ## Force install the chocolatey package for each argument $args | ForEach-Object { $PackageName = $_ Write-Output "Installing $PackageName with Chocolatey:" choco install --force --yes $PackageName }
Some more links that helped me solve this:
Some links on errors I encountered while recovering from this:
--ignorechecksum to choco --install (see [WayBack] CommandsInstall · chocolatey/choco Wiki · GitHub)--force parameterSysinternals Suite is going to be installed in ‘C:\ProgramData\chocolatey\lib\sysinternals\tools’
File appears to be downloaded already. Verifying with package checksum to determine if it needs to be redownloaded.
Error – hashes do not match. Actual value was ‘A510C31C2CC591A16F342E7CBA5DC8409EAF08C9B56729CF132C95C69E196787’.
Downloading sysinternals
from ‘https://download.sysinternals.com/files/SysinternalsSuite.zip’
Progress: 100% – Completed download of C:\Users\devCrPhoneDebug\AppData\Local\Temp\2\chocolatey\sysinternals\2018.12.27\SysinternalsSuite.zip (23.51 MB).
Download of SysinternalsSuite.zip (23.51 MB) completed.
Error – hashes do not match. Actual value was ‘A510C31C2CC591A16F342E7CBA5DC8409EAF08C9B56729CF132C95C69E196787’.
ERROR: Checksum for ‘C:\Users\devCrPhoneDebug\AppData\Local\Temp\2\chocolatey\sysinternals\2018.12.27\SysinternalsSuite.zip’ did not meet ‘b14466c6bf3be216ea71610a3f455030e791cd5ad1b42a283886194205d176b0’ for checksum type ‘sha256’. Consider passing the actual checksums through with –checksum –checksum64 once you validate the checksums are appropriate. A less secure option is to pass –ignore-checksums if necessary.
The install of sysinternals was NOT successful.
Error while running ‘C:\ProgramData\chocolatey\lib\sysinternals\tools\chocolateyInstall.ps1’.
See log for details.Chocolatey installed 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
.nupkg files first, which will give you an idea on the potential missing dependencies. Retry by forcing reinstall each dependency..nupkg files. Example: [WayBack] Unable to resolve dependency · Issue #206 · chocolatey/choco · GitHub
choco-reinstall-empty-nupkg-by-names.ps1command, then retry.–jeroen
Posted in Chocolatey, COBOL, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows, Windows 10 | Leave a Comment »
Posted by jpluimers on 2021/09/08
By now, probably newer versions have come out, but this should give a rough indication of the 2019 state of [WayBack] PowerShell OS Support Matrix – mohitgoyal.co:
For 5.1 and lower, you can find the prerequisites in [WayBack] Windows PowerShell System Requirements – PowerShell | Microsoft Docs.
–jeroen
Posted in .NET, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/09/07
If you get [WayBack] “A parameter cannot be found that matches parameter name ‘PassThru'” as PowerShell error, then likely the PowerShell version is too old to support -PassThru, which likely means you have are running pre-Windows 10 version.
PowerShell 3 (introduced in 2012) added the -PassThru parameter that allowed to chain multiple commands from one list pipe.
Another reason for the error might be that the command you use does not support the -PassThru parameter.
To check which commandlets support -PassThru, use the below command (the output is from a Windows 8.1 machine running PowerShell 4.0).
Posted in .NET, CommandLine, Development, PowerShell, PowerShell, Software Development | Leave a Comment »
Posted by jpluimers on 2021/07/19
[WayBack] windows – Is there any sed like utility for cmd.exe? – Stack Overflow
TL;DR: many people suggest to use PowerShell, but there is GNU sed in Chocolatey
The chocolatey part:
Instructions for building [WayBack] Gnu Sed as a native windows application
All patches under the same license as sources of [WayBack] Gnu Sed: [WayBack] GPLv3 or later
sed.exe was exactly the binary [WayBack] sed-windows/sed-4.5-x64.exe at cafe68124fb8f01db3fb1d9ea586f8f6a72d6917 · mbuilov/sed-windows · GitHubThe PowerShell part: read the other answers from the above question.
–jeroen
Posted in *nix, *nix-tools, CommandLine, Power User, PowerShell, RegEx, sed, Windows | Leave a Comment »
Posted by jpluimers on 2021/05/19
From my batch file library; note this PowerShell wrapper does not support stdin, but that is OK for me.
For Windows 10 and up, sort /unique works too and supports stdin.
:: note: does not work on stdin, unliqke sort which does support standard input :: http://secretgeek.net/ps_duplicates PowerShell Get-Content %1 ^| Sort-Object ^| Get-Unique :: note that for Windoww 10 and up, there is a sort /unique switch, but Windows versions below it do not. :: https://superuser.com/questions/1316317/is-there-a-windows-equivalent-to-the-unix-uniq
Related:
–jeroen
Posted in Batch-Files, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/05/13
Sometimes an install is not just as simple as C:\>choco install --yes oracle-sql-developer.
Edit 20210514:
Note that most of the below pain will be moot in the future as per [Archive.is] Jeff Smith 🍻 on Twitter: “we’re working on removing the SSO requirement, it’s already done for @oraclesqlcl – see here … “ referring to [Wayback] SQLcl now under the Oracle Free Use Terms and Conditions license | Oracle Database Insider Blog
SQLcl, the modern command-line interface for the Oracle Database, can now be downloaded directly from the web without any click-through license agreement.It means the Oracle acount restriction will be lifted, and downloads will be a lot simpler.
I started with the below failing command, tried a lot of things, then finally almost gave up: Oracle stuff does not want to be automated, which means I should try to less of their stuff.
First of all you need an Oracle account (I dislike companies doing that for free product installs; I’m looking at Embarcadero too) by going to profile.oracle.com:
[WayBack] Chocolatey Gallery | Oracle SQL Developer 18.4.0 (also: gist.github.com/search?l=XML&q=oracle-sql-developer)
Notes
- This version supports both 32bit and 64bit and subsequently does not have a JDK bundled with it. It has a
dependency on thejdk8package to meet the application’s JDK requirement.- An Oracle account is required to download this package. See the “Package Parameters” section below for
details on how to provide your Oracle credentials to the installer. If you don’t have an existing account, you can
create one for free here: https://profile.oracle.com/myprofile/account/create-account.jspxPackage Parameters
The following package parameters are required:
*
/Username:– Oracle username
*/Password:– Oracle password(e.g.
choco install oracle-sql-developer --params "'/Username:MyUsername /Password:MyPassword'")To have choco remember parameters on upgrade, be sure to set
choco feature enable -n=useRememberedArgumentsForUpgrades.
Then the installation failed fail again: ERROR: The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
The trick is to RUN IEXPLORE.EXE AS ADMINISTRATOR ONCE BEFORE INSTALLING FROM CHOCOLATEY. Who would believe that.
The reason is that the package uses Invoke-WebRequest which requires Internet Explorer and PowerShell 3. Chocolatey packages however need to be able to run on just PowerShell 2 without Invoke-WebRequest.
Maybe using cURL can remedy that; adding a dependency to is is possible, as cURL can be installed via chocolatey: [WayBack] How to Install cURL on Windows – I Don’t Know, Read The Manual. Another alternative might be [WayBack] Replace Invoke-RestMethod in PowerShell 2.0 to use [WayBack] WebRequest Class (System.Net) | Microsoft Docs.
Posted in CertUtil, Chocolatey, CommandLine, Database Development, Development, DVCS - Distributed Version Control, git, Hashing, OracleDB, Power User, PowerShell, Security, SHA, SHA-1, Software Development, Source Code Management, Windows, XML, XML/XSD | Leave a Comment »
Posted by jpluimers on 2021/05/04
On my list to experiment with are [Wayback] about_Preference_Variables – PowerShell | Microsoft Docs, especially
$ConfirmPreference
Determines whether PowerShell automatically prompts you for confirmation before running a cmdlet or function.
The
$ConfirmPreferencevariable’s valid values are High, Medium, or Low. Cmdlets and functions are assigned a risk of High, Medium, or Low. When the value of the$ConfirmPreferencevariable is less than or equal to the risk assigned to a cmdlet or function, PowerShell automatically prompts you for confirmation before running the cmdlet or function.If the value of the
$ConfirmPreferencevariable is None, PowerShell never automatically prompts you before running a cmdlet or function.To change the confirming behavior for all cmdlets and functions in the session, change
$ConfirmPreferencevariable’s value.To override the
$ConfirmPreferencefor a single command, use a cmdlet’s or function’s Confirm parameter. To request confirmation, use-Confirm. To suppress confirmation, use-Confirm:$false.Valid values of
$ConfirmPreference:
- None: PowerShell doesn’t prompt automatically. To request confirmation of a particular command, use the Confirm parameter of the cmdlet or function.
- Low: PowerShell prompts for confirmation before running cmdlets or functions with a low, medium, or high risk.
- Medium: PowerShell prompts for confirmation before running cmdlets or functions with a medium, or high risk.
- High: PowerShell prompts for confirmation before running cmdlets or functions with a high risk.
–jeroen
Posted in .NET, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/02/18
Recently, I bumped into [WayBack] Write-Output confusion for the upteenth time.
Luckily I had the below links archived, basically invalidating the use of Write-Output, and invalidating the answer at [WayBack] powershell – What’s the difference between “Write-Host”, “Write-Output”, or “[console]::WriteLine”? – Stack Overflow.
Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »