The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘PowerShell’ Category

Shadow IT has entered the chat – got caught running scripts again : sysadmin

Posted by jpluimers on 2024/09/05

Shadow IT has entered the chat

Many companies have hardly any idea how many scripts are being used by their people to get the chores of day to day work done.

Read the rest of this entry »

Posted in Batch-Files, Development, Power User, PowerShell, Python, Scripting, Software Development, Windows, Windows Development | Leave a Comment »

What to do when suddenly some or many .nupkg became zero length and Chocolatey thinks none of them are installed?

Posted by jpluimers on 2024/09/04

A few years back I suddenly had almost all my .nupkg files that Chocolatey uses to track installed software become zero sized.

So I posted a question at [Wayback/Archive] Need help restoring .nupkg files having zero size · Discussion #2765 · chocolatey/choco which got this answer:

Read the rest of this entry »

Posted in Chocolatey, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »

Kugane/winget: A Winget script to automatically install predefined programs and MS Store apps. Includes automatic update and cleanup job

Posted by jpluimers on 2024/09/03

For my link archive: [Wayback/Archive] Kugane/winget: A Winget script to automatically install predefined programs and MS Store apps. Includes automatic update and cleanup job

–jeroen

Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »

PoshCode/PowerShellPracticeAndStyle: The Unofficial PowerShell Best Practices and Style Guide

Posted by jpluimers on 2024/07/31

For my link archive, the source code [Wayback/Archive] PoshCode/PowerShellPracticeAndStyle: The Unofficial PowerShell Best Practices and Style Guide and on-line “book” version that starts with:

[Wayback/Archive] About this Guide – PowerShell Practice and Style

It covers many topics grouped into a Style Guide and Best Practices:

Read the rest of this entry »

Posted in Development, PowerShell, Scripting, Software Development | Leave a Comment »

Script alternatives to the Windows-L keyboard shortcut (SwitchUser / LockWorkstation)

Posted by jpluimers on 2024/05/23

More than a decade ago I wrote about Programmatic alternatives to Windows-L keyboard shortcut (SwitchUser / LockWorkstation).

Still, I see many scripts invoke rundll32.exe or  to call the [Wayback/Archive] LockWorkStation function (winuser.h) inside user32.dll. Don’t!

The BOOL LockWorkStation()function has a calling convention that is incompatible with rundll32.exe () which will corrupt the call stack likely will lead to random problems as after two decades, this post from Raymond Chen still holds: [Wayback/Archive] What can go wrong when you mismatch the calling convention? – The Old New Thing

Read the rest of this entry »

Posted in .NET, Batch-Files, C#, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Security, Software Development, Windows, Windows 10, Windows 11, Windows 7, Windows 8, Windows 8.1, Windows Server 2016 | Leave a Comment »

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal – Scott Hanselman’s Blog

Posted by jpluimers on 2024/03/21

Via [Archive.is] Kevin on Twitter: “Gotta say this looks amazing and I actually didn’t know you can customize the command line on Windows this far. Read this blogpost by @shanselman , highly recommended. 👇 “

For my link archive: [Wayback] My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal – Scott Hanselman’s Blog

Read the rest of this entry »

Posted in CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows, Windows 10, Windows Development | Leave a Comment »

Forgot to blog: on Windows, use Certutil to Get File Hashes

Posted by jpluimers on 2023/10/19

I have had these two batch files on my system forever:

  • sha1.bat:
    :: https://superuser.com/questions/245775/is-there-a-built-in-checksum-utility-on-windows-7
    :: https://www.mcbsys.com/blog/2017/03/use-certutil-to-get-file-hash/
    :: Windows 7 has case sensitive Hash algorithms: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512
    certUtil -hashfile %* SHA1
  • sha256.bat:
    :: https://superuser.com/questions/245775/is-there-a-built-in-checksum-utility-on-windows-7
    :: https://www.mcbsys.com/blog/2017/03/use-certutil-to-get-file-hash/
    :: Windows 7 has case sensitive Hash algorithms: MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512
    certUtil -hashfile %* SHA256

But I forgot to blog about [Wayback/Archive] Use Certutil to Get File Hash | MCB Systems mentioning:

on Windows 7, the hash algorithms are case-sensitive. Be sure to type, for example, “MD5”, not “md5”. On Windows 8.1 and 10, case doesn’t matter

I did mention the first link in “error: invalid object 100644” “git svn”, though only in a by-line. So thanks [Wayback/Archive] user64996 for asking and:

–jeroen

Posted in Batch-Files, CertUtil, Development, Power User, PowerShell, Scripting, Software Development, Windows | Leave a Comment »

Getting the Chocolatey shimgen generated shim target

Posted by jpluimers on 2023/10/10

For tomorrow’s post Ookla speedtest CLI for Windows has some undocumented arguments to accept license and GDPR I neede the full path to the speedtest.exe which I had installed using Chocolatey.

I know chocolatey uses a shim that redirects to the actual executable, so a simple where speedtest.exe would not cut it.

My guess would be that the generated shim allowed to either get the target pathname out, or have the target pathname encoded in it.

Luckily the first applies: a few of the shim command-line parameters are in [Wayback/Archive] Chocolatey Software Docs | Executable shimming (like symlinks but better):

You pass these arguments to an executable that is a shim (e.g. executables in the bin directory of your Chocolatey install, not choco.exe):

  • --shimgen-help – shows this help menu and exits without running the target
  • --shimgen-log – logging is shown on command line
  • --shimgen-waitforexit – explicitly tell the shim to wait for target to exit – useful when something is calling a gui and wanting to block – command line programs explicitly have waitforexit already set.
  • --shimgen-exit – explicitly tell the shim to exit immediately.
  • --shimgen-gui – explicitly behave as if the target is a GUI application. This is helpful in situations where the package did not have a proper .gui file.
  • --shimgen-usetargetworkingdirectory – set the working directory to the target path. Useful when programs need to be running from where they are located (usually indicates programs that have issues being run globally).
  • --shimgen-noop – Do not actually call the target. Useful to see what would happen if you ran the command.

But the below dumps show more more (using [Wayback/Archive] Strings – Windows Sysinternals | Microsoft Docs, [Wayback/Archive] clip | Microsoft Docs and post-processing in [Wayback/Archive] Notepad++).

Back to the second solution,

strings C:\ProgramData\chocolatey\bin\speedtest.exe | findstr speedtest.exe

showed

speedtest.exe
..\\lib\speedtest\tools\speedtest.exe
Cannot find file at '..\\lib\speedtest\tools\speedtest.exe' (
speedtest.exe
speedtest.exe

And towards the first,

strings C:\ProgramData\chocolatey\bin\speedtest.exe | clip

resulted in this fragment:

Read the rest of this entry »

Posted in Batch-Files, Chocolatey, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »

Microsoft Store: update all apps from the command-line

Posted by jpluimers on 2023/09/12

TL;DR

I have converted the below PowerShell one-liner into this batch file (the ^| syntax is to ensure the pipe runs within PowerShell, not within the batch file):

PowerShell 'Get-CimInstance -Namespace "Root\cimv2\mdm\dmmap" -ClassName "MDM_EnterpriseModernAppManagement_AppManagement01" ^| Invoke-CimMethod
 -MethodName UpdateScanMethod'

The why and how

Since I am a CLI person, and some Windows applications are only available on the Microsoft Store, I wanted to be able to initiate an update cycle from the command-line interface.

So I searched for [Wayback/Archive] microsoft store update all apps from the command-line – Google Search and found these to be valuable:

Read the rest of this entry »

Posted in Batch-Files, Development, Microsoft Store, Power User, PowerShell, Scripting, Software Development, Windows, Windows 10, Windows 11 | Leave a Comment »

Seams I might in part be the cause of (#3186) Remove easter egg “You are smarter than the average bear …” by pauby · Pull Request #3276 · chocolatey/choco

Posted by jpluimers on 2023/09/11

Only having really learned to speak English starting in my late teens, I never got the “smarter than the average bear” reference, so I filed what I thought was a bug early 2019: [Wayback/Archive] “You must be smarter than the average bear…” after upgrading to 7zip.install v18.6 and notepadplusplus.install v7.6.2 · Issue #1700 · chocolatey/choco which last year got this useful comment

I had this for several packages now, since I am updating them daily.
I am assuming there is a way to remove versions, which leads to this error until there is a new update.

It was confirmed this summer from

I’m smarter than the average bear at least once or twice a month. I think it might be packages which are pulled back and you happen to have installed that version

The bug got referenced this summer from [Wayback/Archive] Remove warning message about “smarter than the average bear” · Issue #3186 · chocolatey/choco.

This in turn lead to [Wayback/Archive] (#3186) Remove easter egg “You are smarter than the average bear …” by pauby · Pull Request #3276 · chocolatey/choco

That made me realise that for large groups of English speaking people “smarter than the average bear” would actually be a well known thing.

So I searched and learned a thing or two:

Read the rest of this entry »

Posted in .NET, Chocolatey, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »