my first PowerShell script

On Windows 10, I don’t like navigating through several screens to find what OS build is currently installed on my laptop. Being an expert in the Linux bash shell, I thought it would be easy to write a PowerShell script that is similar to the Linux “uname” command. I was wrong!

  1. The standard suffix for a PowerShell script is “ps1”. The third character is the number one, which in some fonts looks like a lower case letter.
  2. You have to give yourself permission to execute your own script. Open a PowerShell ISE window and display the permissions using:
    Get-ExecutionPolicy  -List

    There are five different scopes. You need to set permissions for “LocalMachine” and “CurrentUser” scopes using:

    Set-ExecutionPolicy Unrestricted
    Set-ExecutionPolicy -Scope CurrentUser Unrestricted

    You must use Administrator mode to set permissions.

  3. The article, “PowerShell equivalents for common Linux/bash commands” by, gives this approximation to the Linux “uname” command:
    Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize

    Copy the Get-CimInstance pipeline into file “uname.ps1” and make it executable.
    Executing this command in a PowerShell ISE window gives this result:

    PS C:\cygwin64\home\rhmcc\bin> ./uname.ps1
    SystemDirectory     Organization BuildNumber RegisteredUser SerialNumber            Version
    ---------------     ------------ ----------- -------------- ------------            -------
    C:\WINDOWS\system32              17763       Windows User   00330-80000-00000-AA454 10.0.17763
  4. If you want to get a nice one-line output like uname produces, you have to pipe the output into the appropriate PowerShell editing commands.
  5. If you try to execute “uname.ps1” by the point-and-click method, you will find that the “Notepad” command is executed (to edit the file). If you try to use the Settings menu to change the command, your only option is get a different command from the Microsoft Store. The Microsoft Store does not have the PowerShell command.
  6. The PowerShell command is in directory

    which is already in the PATH environment variable. You can use cmd.exe or bash (in WSL or Cygwin or Msys) to execute powershell.exe.

  7. You can find more details by searching

use PowerShell to reset the system clock

I have a dual boot Windows 10 Pro/Ubuntu 18 laptop. Every time I reboot from Ubuntu to Windows, Windows sets my system clock ahead by  8 hours and says it is California time.

I am a Windows Insider, and I complained about this bug for several years with no results. I guessed that Windows PowerShell would be able to control the clock. A Google search gave me a link to a detailed description of the Set-Date command:

An example showed exactly how to adjust the system clock. Execute PowerShell in administrative mode:

PS C:\WINDOWS\system32> set-date  -adjust  -8:0:0
Saturday, March 16, 2019 1:39:17 AM
PS C:\WINDOWS\system32>
This magic one-liner saves me a lot of time.

myenv package update

The Windows Subsystem for Linux home page is set with this command:

export LHOME=”$(wslhome)”

If you don’t have permission to access $LHOME, the home page was previously set to the last directory name which you do have permission to access.

The updated wslhome command prints the correct home page even if you don’t have permission to access it. If access is desired, you must use Administrator privilege to give yourself access to the later directories in the path.

myenv package update

There are three significant changes in myenv (

  1. $USER is used for userid. The only place that may cause a problem is wslhome, because the Linux userid need not be the same as the Windows userid. You can fix this problem by putting a modified wslhome command in $HOME/bin.
  2. wslhome uses the latest location (obtained from How-To Geek). The path is established in several steps corresponding to the locations where the command may fail because of permissions. You will have to use the Windows security tab to give yourself permission to access your WSL home directory. If you are not using Ubuntu, you need to change “*Ubuntu*” to match your choice of Linux systems. Remember to treat the Linux files as read-only.
  3. A machome command and MHOME environment variable are added to accommodate macOS, which uses “/Users/userid” instead of “/home/userid”. The mkzip command is changed to use $HOME/tmp because macOS links /tmp to /private/tmp.

my first Alexa routine

For my first try I chose to implement a simple “missing” Alexa command: Restart Fire TV Stick. Amazon Fire TV Stick, like every Android program, is prone to losing its internet connection while still connected to WiFi. The only way to restore the internet connection is to restart the program. Restart has two steps: turn off power; turn on power.

An Alexa routine consists of a trigger phrase, a list of action phrases and an Alexa  device name. It is stored with all other Alexa information at To define and/or edit a routine you must use the Amazon Alexa app on an Android phone or iPhone. You can choose your own trigger phrase, but you have to test whether Alexa can distinguish it from other valid phrases. Each action phrase is chosen from a fixed list of alternatives.

This is my intended restart routine:


Alexa, Restart Fire TV Stick


Turn Off rhmFireTV

Turn On rhmFireTV


The device you speak to

When I execute the Amazon Alexa app on my Android phone, it enables Routines and checks the validity of my mobile phone number. I then select the Routines menu and enter my new routine. But I find that rhmFireTV is not an allowed object for an action — it is not a Smart Home device. Fortunately, I have a TP-Link mini smart plug. I change its name to “Fire TV power”, and use that name instead of rhmFireTV. I check my routine and discover that the editor has changed the order of my actions. I press the six dots and slide my second action to the bottom of the list. I click CREATE to record my new routine at, wait a minute, and test my new routine:

Alexa, Restart Fire TV Stick

and Alexa responds

Sorry, I am unable to restart the book right now.

I make a good guess: I change the trigger phrase to “Restart” and Alexa executes my routine. But my second action does not work; I need a delay before turning the power back on. I insert an Alexa Says action: “Au revoir!”. I test again, and it works as intended!

Alexa Routines are still in an early stage of development. I expect that future changes will make Routines into a powerful, useful tool.

myenv package for Windows 10 + Cygwin + WSL/Ubuntu

Windows 10 can run two Linux subsystems simultaneously: Cygwin and Ubuntu. I developed a small package of commands ( to conveniently access files from all three operating systems. It creates five environment variables

myOS — Cygwin or GNU/Linux

myDRIVE — install drive of Windows 10

WHOME — Windows home directory

CHOME — Cygwin home directory

LHOME — Ubuntu home directory

Just add “.  myenv” to your .profile and you can access files like this:

$WHOME/OneDrive     (Microsoft cloud store)

$CHOME/KE/bin/ke.exe     (my Knowledge Explorer)

$LHOME/../../rootfs/etc/shadow     (to delete forgotten password)

There’s one caveat: Microsoft has a complex scheme for buffering $LHOME (Windows file system) and $HOME (Ubuntu file system). Don’t try to access $LHOME until you exit the Ubuntu terminal window.

The myenv package includes three other useful commands:

path — prints each $PATH directory on separate line

wordpad — example command not found in $PATH directory

mkzip — zip all files in directory and its subdirectories

To install the free myenv package, download and unzip in any directory in $PATH. I suggest using directory $myDRIVE/bin or /usr/local/bin or $HOME/bin.