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.