Invoke-ConditionalShutdown.ps1

Windows natively won’t let you schedule a system shutdown, but there are plenty of posts on the Internet that show you how to create a Scheduled Task that will do that for you.

Having recently added a solar+battery setup to our home, I’ve been on a (belated) mission to reduce our overnight power consumption, and I’ve decided that a scheduled shutdown of my desktop PC around bedtime would be a good idea. HOWEVER I don’t want it to be completely automatic, because sometimes I might be running a process that needs to be let run. I might have a WinSCP or PowerShell session open to a Pi I’m monitoring, or I’m capturing real-time traffic from KNX’s “ETS” app, and the shutdown would be A Bad Thing. And here’s where I hit a roadblock.

“Invoke-ConditionalShutdown.ps1” is the solution.

Create your scheduled task as required, but instead of calling “shutdown”, call PowerShell, invoke the script, and add some attributes to define a “skip list” of processes to whitelist, or a “skip file” with the power of regular expressions to look for a list of processes and title bar text.

Features

 
Simple modeSupply a comma-separated list of process names to whitelist. e.g. “Notepad++,Bounsky 2015”.
Power-user modeProvide a CSV file naming the process and what its title bar must say for it to be whitelisted. These values are regular expressions, where a blank entry is a wildcard “$true”.
HibernateAll the power, but just hibernate instead of shutting down. (The script will abort and report an error if Hibernate is disallowed for your machine or o/s).
Shutdown timerWindows’ shutdown command has a “-t nn” attribute, and I’ve catered for that here too, with a default 20s delay for some in-built “OMG NOOOO” protection. (“shutdown -a” is your “undo” command here.)
Reopen previously-running appsIf enabled and invoked, when the machine next boots, all the previously-running apps will reopen. See “ARSO” below.
Validate the regex in the SkipFile Not sure if your RegEx is up to scratch? Don’t worry, neither is mine. Run the script with the “-ValidateSkipFile” switch and it will tell you which of your RegEx rules are no good. Rinse and repeat until it’s all valid, then proceed to “TestMode”.
TestModeTest your settings are correct without risking an unexpected shutdown/hibernate event. The script will drop a message to the screen telling you if it would have shutdown or not, and what criteria triggered the ‘skip’. (Run -ValidateSkipFile first if you’re using the SkipFile).
VerboseOutput verbose info to screen.
Code SignedWith thanks to DigiCert, the released version of the script has been signed, so it’ll run in environments where a strict security policy is enforced.

Continue reading ‘Invoke-ConditionalShutdown.ps1’ »

Get-EnphaseProduction.py

Our new home has provided the opportunity to add a lot of “tech toys” to an otherwise blank canvas, and the most expensive by far has been the combination of solar panels, Enphase micro-inverters and Tesla PowerWall2 battery.

Solar + Battery

Here’s a very high level drawing of the setup, with thanks to Finn at SolarQuotes.com.au for the image.

We have two arrays, with 11 x 400W panels facing East and another 11 facing North, to a total of 8.8kW production.

Unlike a traditional solar panel setup where multiple panels are wired in series in “strings”, then the combined output sent to an inverter, EACH of our panels has its own dedicated inverter. This is usually a more expensive option, and one of the more obvious benefits is that if a single inverter fails you’re only down “1/n”% production until it can be replaced.

Whilst the house is fed by a 3-phase supply, the only load currently requiring all three phases is the ducted air-conditioning. The downside is that should we have a total power failure, we won’t be able to run the aircon off the battery, which we’ve decided is an unnecessary luxury we can forgo under the circumstances.
Continue reading ‘Get-EnphaseProduction.py’ »

PRTG – No module named ‘requests’

We use Paessler’s “PRTG” monitoring and reporting software for keeping tabs on everything here.

We’ve increasingly started writing scripts in Python to serve as “sensors”, feeding data into PRTG, but we’ve hit a couple of road-blocks on the way.

ModuleNotFoundError: No module named ‘requests’

If you encounter this error, or any similar ones reporting “no module named…”, the fix is simple:

  1. First it’s critical that you’re logged in as THE Windows “Administrator”. Logging in as a user who’s a member of the Administrator’s group is insufficient:

  2. Change directory to where python.exe lives:
    CD "C:\Program Files (x86)\PRTG Network Monitor\python\"
    
  3. Install the required module. In this example it's 'requests':
    .\python.exe -m pip install requests

That should be all you need ... with one more potential pitfall: PRTG needs to be running on a release later than 22.2.77.2204:

PRTG Version 22.2.77.2204 broke compatibility with pip.exe install (to install Python packages). With this PRTG release we have removed support for this command to prevent unexpected errors. As of now the only supported way of installing a Python package to use Python Script Advanced sensor is python.exe -m pip install. Please also see our Knowledge Base article for more information about Python installation: https://kb.paessler.com/en/topic/90686.

References / Credits

Revision History

5th November 2022. This is the initial publication.

 
– G.

Stream Deck to KNX

I’ve blogged about our love affair with the Stream Deck programmable buttons before. If you’re not familiar with them, they’re a neat little “mini keyboard”, and under each key is a full-colour display. One of these will let you send a frequently-used key sequence with a gentle tap, and the inbuilt ‘Profiles’ allow it to change its layout depending upon which app has the focus.

With one of these on our desks here at home it was only a matter of time before the hubby asked me to add lighting control to it.
Continue reading ‘Stream Deck to KNX’ »

SfB 2019 Server Update – October 2022

Our last update to Skype for Business Server 2019 was July’s security update, to 7.0.2046.404.

Today we see build 7.0.2046.409, which updated four components on my Standard Edition Front-End.

What’s Fixed?

  • Kb5018063 Cannot assign policy for usernames that have a backslash by using MACP

What’s New?

Nothing noted, however ONE new cmdlet snuck into the SfB module in this update:

Test-CsPersistentChatMessage

This “test-” cmdlet joins the only other verb we have for that noun, the “remove-“.
Continue reading ‘SfB 2019 Server Update – October 2022’ »

Why KNX?

In What is this Home Automation stuff anyway? i mentioned the primitive electrical state of our new home. Whilst there were separate circuits for the fridge and wall oven, the rest of the two-storey house was fed with 1 lighting circuit and 1 power circuit per floor. Individual residual current breakers? No chance.

The lighting was dismal too. The upstairs rooms all had ceiling fans with no two alike. Some were AC, the rest DC, and all had some kind of inbuilt “light”, with luxurious on/off control. I’m using quotes there because they didn’t do much of a job of illuminating the room. The fans went, replaced by MATCHING (heaven forbid!) DC devices, however that left us with even less light upstairs.

We’d lived in our last home for just shy of 20 years, and I’d built up quite the well-established Home Automation setup, based upon Clipsal’s “C-Bus” building management platform, so some degree of Home Automation (herein “HA”) was a given for the new place. In that 20 years, Clipsal’s been bought out by Schneider Electric, and to my mind poor C-Bus has been largely left to rot. Sure, the switches have been updated into the current plate designs, but there’s not been much movement beyond that.

So what’s KNX?

 
The KNX association logo
Continue reading ‘Why KNX?’ »

What is this Home Automation stuff anyway?

At the start of 2022, Rocky and I bought a new home and moved in. (It’s 15 years old but it’s new to us.)

To say it was rather devoid of technology was an understatement. It was almost entirely devoid of *lighting*, FFS!

We’ve spent the year thus far making it a comfortable little “tech nest”, filling it with things like servers, Raspberry Pi’s, Wi-Fi, data cabling, solar panels, a Tesla PowerWall [currently on back-order Oct 2022: OMG it’s here and I love it], the magic of the electric light – and also home automation.

The term “home automation” (herein “HA”) is used a lot these days, and it covers a vast range of technologies and functionality.

Wikipedia defines HA as “building automation for a home, called a smart home or smart house. A home automation system will monitor and/or control home attributes such as lighting, climate, entertainment systems, and appliances. It may also include home security such as access control and alarm systems. When connected with the Internet, home devices are an important constituent of the Internet of Things (“IoT”).”

That sounds all very Jetsons or Star Trek, complicated, expensive and futuristic, but you don’t need to go all-out to have HA.

I like to consider HA as just using a non-traditional control system or input to switch an output, something other than a directly-connected wall-mounted switch or a dial to control a light. (Maybe HA comes when you abstract the control system from the device?)

Continue reading ‘What is this Home Automation stuff anyway?’ »

SfB 2019 Server Security Update – July 2022

This Security update for SfBS 2019 is build 7.0.2046.404, up from April’s 7.0.2046.396. It updated four components on my Standard Edition Front-End.

What’s Fixed?

This security update resolves a remote code execution vulnerability in Microsoft Skype for Business Server and Microsoft Lync Server. To learn more about these vulnerabilities, see Microsoft Common Vulnerabilities and Exposures CVE-2022-33633.

What’s New?

Nothing noted. No cmdlets have been added to the SfB module in this update.

What’s Changed?

Nothing noted.

Continue reading ‘SfB 2019 Server Security Update – July 2022’ »

SfB 2015 Server Security Update – July 2022

This security update for SfBS 2015 is build 6.0.9319.634, up from April’s 6.0.9319.628. It updated four components on my Standard Edition Front-End.

What’s Fixed?

This security update resolves a remote code execution vulnerability in Microsoft Skype for Business Server and Microsoft Lync Server. To learn more about these vulnerabilities, see Microsoft Common Vulnerabilities and Exposures CVE-2022-33633.

What’s New?

Nothing noted. No cmdlets have been added to the SfB module in this update.

What’s Changed?

Nothing noted.

Continue reading ‘SfB 2015 Server Security Update – July 2022’ »

SfB 2015 Server Security Update – April 2022

This security update for SfBS 2015 is build 6.0.9319.628, up from February’s 6.0.9319.623. It updated only three components on my Standard Edition Front-End.

What’s Fixed?

This security update (KB5012686) resolves vulnerabilities in Microsoft Skype for Business Server. To learn more about these vulnerabilities, see Microsoft Common Vulnerabilities and Exposures CVE-2022-26910 and Common Vulnerabilities and Exposures CVE-2022-26911.

What’s New?

Nothing noted. No cmdlets have been added to the SfB module in this update.

What’s Changed?

Nothing noted.

Continue reading ‘SfB 2015 Server Security Update – April 2022’ »