One of the places explaining a more and more frequent error on Windows 7 installations is [Wayback/Archive.is] “You must provide a value expression on the right-hand side of the ‘-‘ operator.” · Issue #29 · shiftkey/chocolatey-beyondcompare:
Archive for the ‘PowerShell’ Category
Chocolatey on Windows 7: “You must provide a value expression on the right-hand side of the ‘-‘ operator.”
Posted by jpluimers on 2022/06/08
Posted in Chocolatey, CommandLine, Development, Microsoft Surface on Windows 7, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2 | Leave a Comment »
A twitter call to say nice things about technology sparked interesting threads
Posted by jpluimers on 2022/05/27
A while ago [Archive.is] Adam Jacob on Twitter: “Let’s say nice things about technology today. I’ll start. If it wasn’t for @lkanies and @puppetize, there is no way we would have been able to adapt as an industry to the rise of the cloud. Quote tweet me with your own.” sparked some interesting threads.
First posts are below; click on them to see the full threads.
Posted in Chrome, Configuration Management, Development, DevOps, Firefox, History, IaC - Infrastructure as Code, Infocom and Z-machine, Infrastructure, KVM Kernel-based Virtual Machine, LSI/3ware, Open Source, PDP-11, Power User, PowerShell, Puppet, Python, Qemu, Rust, Safari, Scripting, Software Development, UCSD Pascal, Vagrant, Veewee, Virtualization, Web Browsers, Xen | Leave a Comment »
Chocolatey 1.0.0 got released last week (chocolatey/choco · GitHub)
Posted by jpluimers on 2022/03/24
Last week finally there was the stable [Wayback/Archive] Release version 1.0.0 · chocolatey/choco · GitHub.
So I fixed the Wikipedia page
- from: [Wayback/Archive] Chocolatey – Wikipedia (only mentioning 0.12.1 preview release)
- to: [Wayback/Archive] Chocolatey – Wikipedia (now including the 1.0.0 stable release)
It was a few days after the 11th birthday “Celebration”: [Wayback/Archive] Chocolatey Software Blog | This One Goes To 11! Celebrating 11 Years Of Chocolatey. Not a really festive post, though it does have a really nice overview of 11 years of Chocolatey history and clearly showing the momentum of it has been a few years behind us.
The thing is: hardly anybody noticed the celebration nor the 1.0.0 release. Being at various 0.* versions for like a decade makes people not follow sudden version bumps closely. I only noticed when updating a bunch of testing VMs of which one had a problem, so I inspected the logs and saw the 1.0.0 version.
So these recent tweets did not gain much attention:
- 20220321: [Wayback/Archive] Chocolatey on Twitter: “Join us in ONE HOUR to mark a milestone in Chocolatey history! No excuses. Take the dog out. Grab a coffee. Sit down. Watch us on Twitch. 4pm UTC. “
- 20220320: [Wayback/Archive] Chocolatey on Twitter: “Join the Chocolatey Team TOMORROW, 21 March, and mark a milestone in Chocolatey history! On Twitch. 4pm UTC. And join our Discord server for a little thank you to our Community. “
- 20220317: [Wayback/Archive] Chocolatey on Twitter: “ICYMI we have a … special event marking a milestone in Chocolatey history this Monday, 21 March at 4pm UTC. Join @pauby, @gep13 and the @chocolateynuget Team. And join our Discord server for a little thank you to our Community. “
Anyway: the release notes indicate a few things scheduled for 2.0.0. Given the sudden 0.12.0 -> 1.0.0 bump, I have no clue far (or near!) in the future that will be.
It is kind of both a saddening and relieved feeling: like for instance Stack Overflow/Stack Exchange (both in the same age cohort as Chocolatey), Chocolatey is just there and mostly works.
–jeroen
Posted in .NET, Batch-Files, C#, Chocolatey, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »
PowerShell debugging in Visual Studio Code: “PowerShell: Launch Current File w/Args” configuration template is missing
Posted by jpluimers on 2022/03/09
Not sure why, but most of my Visual Studio configurations have the “PowerShell: Launch Current File w/Args” debug configuration template. So here is the JSON you need to add in your launch.json configuration file.
{ "type": "PowerShell", "request": "launch", "name": "PowerShell Launch Current File w/Args Prompt", "script": "${file}", "args": [ "${command:SpecifyScriptArgs}" ], "cwd": "${file}" }
The trick is the bold part that prompts Visual Studio for the arguments.
Note: in order to have such a file, you need to have opened a folder in Visual Studio Code first, then open a PowerShell script file from that directory second.
Related:
- [WayBack] PowerShell Parameters – PowerShell – SS64.com
- [WayBack] Passing Arguments to vscode-powershell · Issue #965 · PowerShell/vscode-powershell · GitHub
- [WayBack] Tahir Hassan’s Blog: PowerShell/VSCode: Debugging a script which has parameters
- [WayBack] “PowerShell Launch Current File w/Args Prompt” does not work when VS Live Share extension is enabled · Issue #1332 · PowerShell/vscode-powershell · GitHub
- [WayBack] initial commit · PSVortex/Powershell@944a90a · GitHub
- [WayBack] On non-Windows, the debug command line expects a `sh` compliant shell · Issue #81399 · microsoft/vscode · GitHub
- [WayBack] PowerShell – Not running the PowerShell script. What is the error? – Helperbyte
–jeroen
Posted in .NET, CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Windows Defender: adding and removing exclusions from PowerShell (via Stack Overflow)
Posted by jpluimers on 2022/02/16
I use this small script to install or update [Wayback] Chocolatey package NirLauncher (which is the [Wayback] Nirsoft Launcher that has all the [Wayback] Nirsoft freeware tools in it).
powershell -Command Add-MpPreference -ExclusionPath "%TEMP%\chocolatey\NuGetScratch" choco update --yes NirLauncher powershell -Command Remove-MpPreference -ExclusionPath "%TEMP%\chocolatey\NuGetScratch"
It works around the issue that many times NirLauncher is marked by anti-virus tools or/and listed on VirusTotal, which means you get an error like this:
NirLauncher not installed. An error occurred during installation: Operation did not complete successfully because the file contains a virus or potentially unwanted software.
followed by
Chocolatey upgraded 0/1 packages. 1 packages failed. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
I wrote about this error before Need to research: Nirlauncher v1.23.42 to 1.23.43 upgrade through Chocolatey fails with “Operation did not complete successfully because the file contains a virus or potentially unwanted software.”, and this post is explaining how I got to the above workaround.
Context: I was running Windows Defender (now officially called Microsoft Defender, but most people still use the old name), which is a good baseline anti-virus tool that is included with Windows.
Finding out the location of the offending file
The offending location is not actually in the C:\ProgramData\chocolatey\logs\chocolatey.log file.
I did a small search to see if one could list Windows Defender messages, and there was [Wayback] Use PowerShell to See What Windows Defender Detected | Scripting Blog explaining the Get-MpThreatDetection available since around Windows 8.x.
This little command got what I wanted:
C:\temp>PowerShell Get-MpThreatDetection ^| Format-List ^| Out-String -Width 4096 | findstr /I "nir" Resources : {file:_C:\Users\jeroenp\AppData\Local\Temp\chocolatey\NuGetScratch\a78a5776-0fdd-48c0-8313-9b0107f54cba\hy3odwgw.1dc\tools\nirsoft_package_1.23.44.zip}
A few tricks I used here:
^|allows pipes to run within PowerShell itself (instead of thecmdwrapper)Out-String -Width 4096makes for a really wide output (soFormat-Listdoes not wrap around any lines; I mentioned that trick before in PowerShell: when Format-Table -AutoSize displays only 10 columns and uses the width of the console when redirecting to file)| findstr /I "nir"uses thecmdwrapper pipe through the oldfindstrcommand from the DOS era that allows to filter output (I triedSelect-String, but that failed – despite tricks mentioned in [Wayback] pipingGet-ChildItemintoSelect-Stringin powershell – Stack Overflow – likely because that is not text-oriented, but object oriented in nature)
Searching for [Wayback] “chocolatey\NuGetScratch” – Google Search, I found out %Temp%\chocolatey\NuGetScratch is the default value for [Wayback] chocolatey cacheLocation – Google Search. I run default settings, so that is good enough for me.
Adding / removing a recursive folder exclusion to Windows defender
I found [Wayback] Windows Defender – Add exclusion folder programmatically – Stack Overflow through [Wayback] “Windows Defender” exclusion from commandline – Google Search explaining these (thanks [Wayback] gavenkoa!):
Run in elevated shell (search
cmdin Start menu and hit Ctrl+Shift+Enter).powershell -Command Add-MpPreference -ExclusionPath "C:\tmp" powershell -Command Add-MpPreference -ExclusionProcess "java.exe" powershell -Command Add-MpPreference -ExclusionExtension ".java" powershell -Command Remove-MpPreference -ExclusionExtension ".java"
This was a short step to these documentation pages (note to self: figure out the origin of the Mp prefix)
- [Wayback] Add-MpPreference (Defender) | Microsoft Docs
- [Wayback] Remove-MpPreference (Defender) | Microsoft Docs
Windows Defender still marks individual tools
Of course Windows Defender still marks individual tools as “unsafe” (for instance C:\tools\NirLauncher\NirSoft\mailpv.exe). To alleviate that, you have to permanently add this directory to the exclusion list: C:\tools\NirLauncher.
–jeroen
Posted in CommandLine, Development, NirSoft, Power User, PowerShell, Software Development, Windows | Leave a Comment »
VFrontDe/ESXi-Customizer-PS: PowerCLI script that greatly simplifies and automates the process of creating fully patched and customized VMware ESXi installation images
Posted by jpluimers on 2021/11/30
On my list of things to try, as it allows me to have an ISO at hand in case I ever need to quickly re-install a machine to the current patch level (for instance when the USB boot stick breaks down: these things happen in reality): [Wayback] VFrontDe/ESXi-Customizer-PS: PowerCLI script that greatly simplifies and automates the process of creating fully patched and customized VMware ESXi installation images
ESXi-Customizer-PS is a Powershell script that greatly simplifies and automates the process of creating fully patched and customized ESXi 5.x and 6.x installation ISOs using the VMware PowerCLI ImageBuilder module/snapin.
…
Requirements
- A Windows computer (XP or newer) with Powershell 2.0 or newer
- VMware PowerCLI version 5.1 or newer
…
You can get the code from [Wayback] ESXi-Customizer-PS/ESXi-Customizer-PS.ps1 at master · VFrontDe/ESXi-Customizer-PS.
The old site (which still has most of the documentation) can be reached at two places:
- [Wayback] esxi-customizer-ps.v-front.de which redirects to
- [Wayback] www.v-front.de/p/esxi-customizer-ps.html
A video showing how to use it is below the signature.
The above links via [Wayback] Custom ESXi ISO with ne1000 driver for install on Intel NUC Frost Canyon – seanwalsh.dev.
Oh: you can check if you have a PXE, USB or HDD installation of ESXi via the steps here: Determining the ESXi installation type (2014558) | VMware KB.
More on a failing USB stick later…
–jeroen
Posted in CommandLine, Development, ESXi6, ESXi6.5, ESXi6.7, ESXi7, Power User, PowerCLI, PowerShell, PowerShell, Software Development, Virtualization, VMware, VMware ESXi | Leave a Comment »
Windows 10: remove applications from the uninstall list
Posted by jpluimers on 2021/11/04
After doing Windows upgrades to Windows 10, every now and then I bump into applications that do not fully uninstall themselves and get stuck on the uninstall list (that you get when running appwiz.cpl or browse to the Control Pannel installed programs list).
[WayBack] How to Manually Remove Programs from the Add/Remove Programs List mentions to inspect registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall, but that didn’t include some of the applications.
Then I found [WayBack] Remove entry from Windows 10 Apps & Features – Super User, where the answers mentions two other keys (thanks users [WayBack] Kreiggott and [WayBack] NutCracker):
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\UninstallHKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall
Neat!
So I made the below PowerShell script to dump installed programs.
It grabs the list of registry keys containing installed software and their registry values, then empirically filters out most values that are also now shown in AppWiz.cpl.
Like database work, the values can have properties having a value or being null. So it’s SQL like expression galore to do the filtering.
This post is slightly related to Still unsolved since 2015 NetBeans: Bug 251538 – Your Installer is Creating Invalid Data for the NoModify DWORD Key which crashes enumeration of the Uninstall Key in at least PowerShell, where I already did (without documenting) some Uninstall spelunking.
## The collection of registry keys gives Name and Property of each registry key; where Property is compound containing all registry values of that key. ## Get-ItemProperty will get you all the values on which you can filter, including a few special PS* values that allow you to browse back to the registry key. # x86 installs on x64 hardware: http://stackoverflow.com/questions/12199372/get-itemproperty-not-returning-all-properties/12200100#12200100 $nonUninstallableSoftwareRegistryKeys = (@ (Get-Item HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*)) + (Get-Item HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*) + (Get-Item HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*) #$nonUninstallableSoftwareRegistryKeys.GetType().FullName #$nonUninstallableSoftwareRegistryKeys | Get-Member #$nonUninstallableSoftwareRegistryKeys | Out-GridView #$nonUninstallableSoftwareRegistryKeys | Get-ItemProperty | Get-Member #$nonUninstallableSoftwareRegistryKeys | Get-ItemProperty | Out-GridView #Return $nonUninstallableSoftwareRegistryNameValues = $nonUninstallableSoftwareRegistryKeys | Get-ItemProperty | Where-Object { $_.SystemComponent -ne 1 -and $_.NoRemove -ne 1 -and $_.UninstallString -ne "" -and $_.UninstallString -ne $null } # Filters out most things that AppWiz.cpl will leave out as well. # Might need more fine tuning, but is good enough for now. # PSPath shows the path to the underlying registry key of each value $nonUninstallableSoftwareRegistryNameValues | Select-Object SystemComponent, NoRemove, DisplayName, DisplayVersion, UninstallString, PSChildName <#, PSPath #> | Sort-Object DisplayName | Out-GridView # Need to find a good way to output this in a really wide Format-Table text format.
–jeroen
Posted in CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows, Windows 10 | Leave a Comment »
Terminating a script in PowerShell – Stack Overflow
Posted by jpluimers on 2021/11/03
I have the same problem mentioned in the answer to [WayBack] Terminating a script in PowerShell – Stack Overflow: confused by most answers, and keeping to forget what each method means (there is Exit, Return, Break and (if you love exception handling to do simple flow control), Throw.
So here is the full quote of what [WayBack] User New Guy answered:
Posted in *nix, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »
Reminder to self: script blocks inside .ForEach calls can have Begin/Process/End blocks
Posted by jpluimers on 2021/10/21
I need to write some tests for this, but it looks like you can use the keywords Begin/Process/End with code blocks when the script block is inside a .ForEach member call.
The behaviour seems to be the same as if these blocks are part of a function that executes inside a pipeline (Begin and End are executed once; Process is executed for each item in the pipeline).
It’s hard to Google on this, as all hits of all queries I tried got me into these keywords in the context of functions.
The below links are on my reading list.
Microsoft documentation:
- [WayBack] about_Arrays: Methods of Arrays – PowerShell | Microsoft Docs
- [WayBack] ForEach-Object
- [WayBack] about_Script_Blocks – PowerShell | Microsoft Docs
- [WayBack] about_Functions – PowerShell | Microsoft Docs
- [WayBack] about_Functions_Advanced – PowerShell | Microsoft Docs
- [WayBack] about_Functions_Advanced_Methods – PowerShell | Microsoft Docs
SS64 docs (which has guidance on which of the 3 foreach constructs to use when):
- [WayBack] ForEach method – PowerShell – SS64.com
- [WayBack] ForEach – PowerShell – SS64.com on the foreach statement)
- [WayBack] ForEach-Object % – PowerShell – SS64.com (aliased
ForEachand%) - [WayBack] Function Begin Process End – PowerShell – SS64.com[WayBack] Powershell Arrays – PowerShell – SS64.com
- [WayBack] Scriptblocks – PowerShell – SS64.com
Social media and blog posts:
- [WayBack] PowerShell:
$array.ForEach({})| Saved Keystrokes - [WayBack] PowerShell 4.0 Where and ForEach Method Syntax – TechNet Articles – United States (English) – TechNet Wiki
- [WayBack] Extending the Reach of ForEach in PowerShell — Microsoft Certified Professional Magazine Online
- [WayBack] PowerShell functions: begin, process and end blocks
- [WayBack] $input gotchas | Dmitry’s Blog: Cloud, PowerShell and beyond
- [WayBack] Advanced PowerShell Functions: Begin to Process to End – SAPIEN Blog (shows what happens when nesting functions having these blocks)
- [WayBack] PowerShell – Begin Process End – CodeAndKeep.Com – Code and keep calm…
- [WayBack] Implement Pipeline Support by making proper use of begin, process and end blocks in PowerShell functions – mohitgoyal.co
StackOverflow entries:
- [WayBack] powershell – How does begin/process/end save the need for foreach? Still needed for the parameter isn’t it? – Stack Overflow
- [WayBack] PowerShell: the mysterious -RemainingScripts parameter of ForEach-Object – Stack Overflow
- [WayBack] powershell – Use Begin, Process, End in Scriptblock – Stack Overflow
- [WayBack] Difference between ForEach and ForEach-Object in powershell – Stack Overflow
- [WayBack] PowerShell: How to get count of piped collection? – Stack Overflow
- [WayBack] powershell – Nested function inside a function with begin/process/end blocks? – Stack Overflow
- [WayBack] PowerShell Pipeline iteration – Stack Overflow
- [WayBack] powershell – How to query registry values skipping the PS* ones – Stack Overflow (thanks [WayBack] User Keith Miller – Stack Overflow / [WayBack] Keith A. Miller – Microsoft Community for bringing this to my attention)
I know this is truly old, but here’s a function I added to my Profile to facilitate registry exploration:
Function Get-KeyProperty { Param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [ValidateScript( {(Resolve-Path $_).Provider.Name -Like 'Registry'} )] [String[]] $Path, [String[]] $Name=@("*") ) Process { $Name.ForEach({ (Get-Item $Path).Property -like $_}).ForEach({ Begin {$Hash = @{}} Process { $Hash += @{ $_ = (Get-Item $Path).GetValue($_)} } End {[PSCustomObject]$Hash} }) }}…
–jeroen
Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Some links on xargs simulation in PowerShell
Posted by jpluimers on 2021/10/13
On nx, I’m used to xargs which allows to convert from a pipe of output into arguments passed to a command. This is useful, as many commands only accept arguments as parameters.
In PowerShell, you can usually avoid an xargs equivalent because commandlet output is a stream of objects that you can post-process using . I for instance used that in PowerShell: recovering from corrupt empty *.nupkg files after a disk was accidentally full during update.
Here are some xargs equivalency examples:
Posted in *nix, *nix-tools, bash, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, xargs | Leave a Comment »





