Archive for the ‘PowerShell’ Category
Posted by jpluimers on 2018/06/19
Thanks [WayBack] gbabu 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 »
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 / homebrew, 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 »
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: [WayBack] Let’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 »
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 »
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 »
Posted by jpluimers on 2017/03/09
Lets start with the second problem: There are various ways to redirect PowerShell output to a file.
- Shell redirect with a greater than sign (
>) to create/overwrite output or two greater than signs (>>) to append output.
- Use Out-File [WayBack] with a filename and either
-FilePath (default, similar to >) or -Append (similar >>).
I write “similar” as they are not fully equivalent. That’s where Format-Table [WayBack] with the -AutoSize parameter comes in (with or without a -Wrap parameter).
Apart from Format-Table displaying only 10 columns by default (see below), the -AutoSize will change columns presentation depending not just on the -Wrap parameter but also to the total width it thinks it has available.
Useful Format-Table parameters
First the representation:
Read the rest of this entry »
Posted in CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | 3 Comments »
Posted by jpluimers on 2017/01/03
I got a bit fed-up with the deprecated Microsoft Silverlight reappearing as KB3056819 in each Windows Update within minutes of hiding it (I’m not alone on this, it does this when you have configured to favour the Microsoft Update Servers – that also update Office – in favour of the Windows Update Servers).
Two really odd things:
- In the past, I hid “Skype for Windows desktop 7.3 (KB2876229)” which stayed hidden.
- I never installed Silverlight, there is no Silverlight on the system (I checked the registry, file system with Everything and more), but the update keeps re-appearing (like KB960353 does for others).
So I wanted a script that every minute could check for a Microsoft Silverlight update, then hide it.
That appeared a lot more cumbersome than I anticipated, hence this blog post.
The reason is that unlike many other operating systems, Windows does not come with a build-in package manager that you can script (there is Windows Installer, but is’s not easily scriptable).
Read the rest of this entry »
Posted in Development, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2016/11/15
Need to research this a bit further as this works:
powershell gwmi -Query 'Select LocalName, RemoteName, UserName from Win32_NetworkConnection'
__GENUS : 2
__CLASS : Win32_NetworkConnection
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 3
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
LocalName :
RemoteName : \\w701ujpl\IPC$
UserName : EN81ENTx64SCAN\jeroenp
PSComputerName :
But this fails for some Powershell versions:
powershell
gwmi -Query 'Select * from Win32_NetworkConnection' | Select-Object LocalName, RemoteName, UserName, ConnectionState | Sort-Object LocalName | ft -auto
–jeroen
Source: user – Determine Domain and username used to map a network drive – Stack Overflow
Posted in Development, PowerShell, Scripting, Software Development | 1 Comment »
Posted by jpluimers on 2016/08/24
I’ve posted an update to List-Delphi-Installed-Packages.ps1 that:
- added HKCU/HKLM registry key values for each BDS version
- doesn’t truncate fields any more when your console has limited width
- is now in UTF-8 format so the BitBucket web-interface can show it
For the first two: Phry for helping me to force Format-Table to show more than 10 columns and pointing me how find out how to do this with Out-String so it doesn’t truncate fields; blog post about it will follow.
Now – as I can display more than 10 columns- I can start working in integrating all the other info about various BDS versions.
Source is at https://bitbucket.org/jeroenp/besharp.net/src/tip/Native/Delphi/Scripts/List-Delphi-Installed-Packages.ps1?fileviewer=file-view-default
A text dump of the current output is below with the Delphi versions including CompilerVersion, RTLVersion, VERXXX Define, DllSuffix and more.
–jeroen
via: If you need to know underlying information on Delphi versions « The Wiert Corner – irregular stream of stuff
Read the rest of this entry »
Posted in Delphi, Development, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2016/07/25

PowerShell 4.0 is madly in love with “English (United States)”
A long time ago I started writing up my blog post like this in March 2015 when I bumped into this the first time when upgrading from PowerShell 2 to PowerShell 4:
It seems there is no real workaround:
Good and not so good news: after reading the below linked posts, this is what works:
- PowerShell 4 and up works fine with any [Wayback] Lucida Console size (including 12) and boldness
- only when the “Language for non-Unicode programs” is set to “English (United States)”.
- PowerShell 4 works fine with [Wayback] Consolas on any size and boldness
- for any “Language for non-Unicode programs”
So if you’re like me and switch between “Dutch (Netherlands)” and “English (Ireland)” a lot (both use the EURO as currency, but have distinct enough other locale settings to cover a lot of European stuff) then you need to get used to the Consolas font.
Source:
Edit 20210930: a possible solution
I need to fire up some old systems having PowerShell v3 or v4 on them to test the below possible solution.
Read the rest of this entry »
Posted in CommandLine, Development, Font, Lucida Console, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows 9 | Leave a Comment »