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,380 other followers

Archive for the ‘PowerShell’ Category

PowerShell – query reboot/shutdown events

Posted by jpluimers on 2018/06/19

Thanks [WayBackgbabu for the below PowerShell ide

As PowerShell command:

Get-EventLog System | Where-Object {$_.EventID -eq "1074" -or $_.EventID -eq "6008" -or $_.EventID -eq "1076"} | ft Machinename, TimeWritten, UserName, EventID, Message -AutoSize -Wrap

Based on it and my own experience, thse Event IDs can be interesting:

  • 41 – The system has rebooted without cleanly shutting down first
  • 109 – The kernel power manager has initiated a shutdown transition.
  • 1073 – The attempt by user [domain]\[username] to restart/shutdown computer [computername] failed.
  • 1074 – The process [filename].[extension] has initiated the restart of computer [computername] on behalf of user [domain]\[username\ for the
  • 1076 – ???
  • 6008 – The previous system shutdown at [time-in-local-format] on [date-in-local-format] was unexpected.

You can also run this as a batch file, but not you need to escape the pipe | into ^| like this:

PowerShell Get-EventLog System ^| Where-Object {$_.EventID -eq "1074" -or $_.EventID -eq "6008" -or $_.EventID -eq "1076"} ^| ft Machinename, TimeWritten, UserName, EventID, Message -AutoSize -Wrap

If you have PowerShell 3.0 or greater, then you can use the [Archive.is-In operator:

PowerShell Get-EventLog System ^| Where-Object {$_.EventID -in "41", "109", "1074", "6008", "1076"} ^| ft Machinename, TimeWritten, UserName, EventID, Message -AutoSize -Wrap

–jeroen

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

Installing PowerShell Core on macOS and Linux | Microsoft Docs

Posted by jpluimers on 2018/03/26

I forgot to blog about this before, but 2 months ago PowerShell core came available: [WayBack] PowerShell Core 6.0: Generally Available (GA) and Supported! | PowerShell Team Blog.

[WayBack] Installing PowerShell Core on macOS and Linux | Microsoft Docs is easy (one way is through homebrew:

$ brew tap caskroom/cask
$ brew cask install powershell

If you already installed a beta, then the steps are these:

$ brew update
$ brew cask reinstall powershell

Note that after installation, it is known as pwsh (at least one of the betas named it powershell) to set PowerShell Core apart from PowerShell*:

$ pwsh --version
PowerShell v6.0.2

Via: [WayBack] PowerShell Core 6.0 is a new edition of PowerShell that is cross-platform (Windows, macOS, and Linux), open-source, and built for heterogeneous environm… – Lars Fosdal – Google+

*pwsh versus powershell

There has been quite a discussion on the PowerShell Core repository on the rename, but I think it is for a good reason.

Too bad that during part of the beta, the old name powershell was used, but beta-time means things break every now and then.

PowerShell Core is sufficiently different from prior PowerShell versions to warrant a name change. This also makes it a lot easier to use them side-by-side.

Many other names (like posh, pcsh or psh) were considered, usually because of naming conflicts with existing tools (like posh) or easy confusion with existing shells (like pcsh and csh). A benefit on Linux/macOS is that it now ends with sh like virtually all other shells.

More background information is at:

–jeroen

Posted in Apple, CommandLine, Development, Home brew, Mac, Mac OS X / OS X / MacOS, MacBook, MacBook Retina, MacBook-Air, MacBook-Pro, MacMini, Power User, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »

Let’s stop copying C / fuzzy notepad

Posted by jpluimers on 2017/12/07

Ah, C. The best lingua franca we have… because we have no other lingua francas. Linguae franca. Surgeons general? C is fairly old — 44 years, now! — and comes from a time when there were possibly more architectures than programming languages. It works well for what it is, and what it is is a relatively simple layer of indirection atop assembly. Alas, the popularity of C has led to a number of programming languages’ taking significant cues from its design, and parts of its design are… slightly questionable. I’ve gone through some common features that probably should’ve stayed in C and my justification for saying so. The features are listed in rough order from (I hope) least to most controversial. The idea is that C fans will give up when I call it “weakly typed” and not even get to the part where I rag on braces. Wait, crap, I gave it away.

Great re-read towards the end of the year: [WayBackLet’s stop copying C / fuzzy notepad

Via: [WayBack] Old and busted: emacs vs vi. New and hot: Language war, everybody against everybody else. – Kristian Köhntopp – Google+

–jeroen

Posted in .NET, APL, Awk, bash, BASIC, C, C#, C++, COBOL, CoffeeScript, CommandLine, D, Delphi, Development, F#, Fortran, Go (golang), Java, Java Platform, JavaScript/ECMAScript, Pascal, Perl, PHP, PowerShell, PowerShell, Python, Ruby, Scala, Scripting, Software Development, TypeScript, VB.NET, VBScript | 3 Comments »

how to filter name/value pairs under a registry key by name and value in PowerShell – Stack Overflow

Posted by jpluimers on 2017/09/06

A long time ago I asked this question how to filter name/value pairs under a registry key by name and value in PowerShell? – Stack Overflow [WayBack] but forgot to schedule a post about it.

It’s an interesting scenario, so lets start with a log of the outcome (it’s on my ix500 scanning VM which has Office15 a.k.a. Office 2013 installed) of this script:

$path = 'hkcu:\Software\Microsoft\Windows\CurrentVersion\Extensions'
$key = Get-Item $path
$key

$namevalues = $key | Select-Object -ExpandProperty Property | 
  ForEach-Object { 
    [PSCustomObject] @{ 
      Name = $_; 
      Value = $key.GetValue($_) 
    } 
  }
$namevalues | Format-Table

$matches = $namevalues | 
  Where-Object { 
    $_.Name -match '^xls' `
    -or $_.Value -match 'msaccess.exe$' 
  }
$matches | Format-Table

It outputs this:

Read the rest of this entry »

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

How bad is the Windows command line really?

Posted by jpluimers on 2017/04/13

How bad is the Windows command line really?

The Windows command line is bad. Very bad.

But it took until recently for old Windows versions – that out of the box had either no or poor PowerShell versions – to have slowly died.

So only now PowerShell finally has become an option that really works across all Windows versions I use. Go PowerShell!

–jeroen

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

 
%d bloggers like this: