The Wiert Corner – irregular stream of stuff

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

  • My work

  • 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,842 other followers

Archive for the ‘PowerShell’ Category

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 »

PowerShell: when Format-Table -AutoSize displays only 10 columns and uses the width of the console when redirecting to file

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 | Leave a Comment »

Regularly forcing Microsoft Silverlight to be a hidden Windows Update

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:

  1. In the past, I hid “Skype for Windows desktop 7.3 (KB2876229)” which stayed hidden.
  2. 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 »

Determine Domain and username used when a network share was mapped

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 »

 
%d bloggers like this: