Skip to main content

Posts

Showing posts from April, 2021

Creating and logging in to a Windows Containers user with a password

Windows Containers by default uses ContainerAdministator user account with blank password. Creating a new user with password can be done but cannot be used in DockerFile for example. If you want to use another user in a container you have to create a user with blank password! To login to a container with a password, do the following: PS C:\> $cert = New-SelfSignedCertificate -DnsName "dontcare" -CertStoreLocation Cert:\LocalMachine\My PS C:\> winrm create winrm/config/Listener?Address=*+Transport=HTTPS ('@{Hostname="notimportant"; CertificateThumbprint="' + $cert.Thumbprint + '"}') PS C:\> winrm set winrm/config/service/Auth '@{Basic="true"}' PS C:\> $cred = New-Object pscredential 'timus', (ConvertTo-SecureString -String 'P@$$w0rd' -AsPlainText -Force) PS C:\> Enter-PSSession -Credential $cred -ComputerName localhost -Authentication Basic -UseSSL -SessionOption (New-PSSessionOption -Skip

Remove blank lines using Notepad++

Say you have a document as shown below. And you want to remove the blank lines - represented by {CR}{LF}. To do this using Notepad++, bring up Replace dialog ( Search | Replace...  or CTRL+H ) and use ^\r\n in Find What  and blank for Replace . In Search Mode, change it to Regular Expression . See below for an example. What it does it use regular expression to search for carriage return and linefeed characters and match only if it is the beginning of the line (^). And of course replace it with a blank character.

Split a line into multiple lines using Notepad++

Say you have a document like below. And you want to split "hello world" into multiple lines. Doing this using Notepad++ is easy. Bring up Replace dialog ( Search | Replace... or CTRL+H ), in  Find what use hello world\r\n . This matches the entire line including carriage return and linefeed character. In Replace with replace the string with the intended multi-line data, for example, hello\r\n\world\r\n , will replace the line into two. One is hello , followed by world in the next line. And of course, for this to work you need to select Regular expression in the Search Mode .

How to delete Windows protected partition

How to delete Windows protected partition Run diskpart in elevated command prompt, like: c:\> diskpart Then follow the prompts like below: Microsoft DiskPart version 10.0.18362.1171 Copyright (C) Microsoft Corporation. On computer: M1 DISKPART> list disk Disk ### Status Size Free Dyn Gpt -------- ------------- ------- ------- --- --- Disk 0 Online 180 GB 53 GB * DISKPART> select disk 0 Disk 0 is now the selected disk. DISKPART> list partition Partition ### Type Size Offset ------------- ---------------- ------- ------- Partition 1 System 100 MB 1024 KB Partition 2 Reserved 16 MB 101 MB Partition 3 Primary 126 GB 117 MB Partition 4 Recovery 499 MB 126 GB DISKPART> select partition 4 DISKPART> delete partition override DISKPART> exit Leaving DiskPart...

Windows containers cannot use USER instruction to change user with a password

 I have a Dockerfile like below: FROM mcr.microsoft.com/windows/servercore:20H2 as final RUN net user timus P@$$w0rd123!@# /add /Passwordchg:No RUN WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE RUN net localgroup administrators timus /add USER timus RUN whoami Running this will fail with an error message like below: C:\mydocker>docker build -t myimages:1.0.0 -f Dockerfile Sending build context to Docker daemon 678.8MB Step 1/6 : FROM mcr.microsoft.com/windows/servercore:20H2 as final ---> 4943ff812624 Step 2/6 : RUN net user timus P@$$w0rd!@# /add /Passwordchg:No ---> Running in 95d4d70138d8 The command completed successfully. Removing intermediate container 95d4d70138d8 ---> d00130167ea2 Step 3/6 : RUN WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE ---> Running in 0d05945d8f70 Updating property(s) of '\\0D05945D8F70\ROOT\CIMV2:Win32_UserAccount.Domain="0D05945D8F70",Name=&q

My docker cheat sheet

My docker cheat sheet Installing base container image for Server Core 2019. If you are running Windows Server 2019 virtual machine, this will allow you to run the container in process isolation mode instead of Hyper-V isolation. Process isolation is more light-weight and allows you to run a Server 2019 VM with dynamic memory setting in Hyper-V. PS C:\> docker image pull mcr.microsoft.com/windows/servercore:ltsc2019 To list downloaded images, do PS C:\> docker images This will show something like below PS C:\> docker images REPOSITORY TAG IMAGE ID CREATED SIZE mcr.microsoft.com/windows/servercore ltsc2019 3eaa9ebbf51f 5 weeks ago 5.25GB To run a Windows container based on servercore:ltsc2019, do: PS C:\> docker run -it mcr.microsoft.com/windows/servercore:ltsc2019 cmd.exe This will open a cmd.exe prompt. This should allow you to play inside that container. This contain

Can’t install Hyper-V Management Tools on Windows Server 2019 if the machine/VM does not support virtualization

Can’t install Hyper-V Management Tools on Windows Server 2019 if the machine/VM does not support virtualization   I tried to install PowerShell Direct to manage docker containers but can't install the feature, trying to run: PS C:\> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell  yields with error below: PS C:\Users\Administrator> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled. At line:1 char:1 + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V- ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException     + FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand Apparently this happens when the OS is running on a ma

Creating new Windows admnistrator user from the command line

Creating new Windows admnistrator user from the command line I am not quite comfortable with too few options available when creating a new user in Windows 10 Home edition, so I do the following. c:\> net user timus P@$$w0rd123!@# /add /Passwordchg:No c:\> WMIC USERACCOUNT WHERE "Name='timus'" SET PasswordExpires=FALSE c:\> net localgroup administrators timus /add

Logging in to remote ssh server using private/public key pair

Logging in to remote ssh server using private/public key pair I have recently used VS Code for remote development and I am experiencing multiple disconnections a day. Like disconnecting form the docking station, moving around the house or just plain network issues. Using password to reconnect is becoming an annoyance. To help improve the workflow I have enabled private/public key pair, like: PS C:\> ssh-keygen -t rsa -b 2048 PS C:\> cat ~/.ssh/id_rsa.pub | ssh user@remote_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" This was tested on Windows 10 v1909.