Adding in WSL into Hyper-V VM in Windows Server

Default Windows OS doesn’t allow hyperV feature to be enabled in VM

Create nested Hyper-V

  1. Shut down the VM.
  2. In the host open Powershell with administrator rights.

    Set-VMprocessor ExposeVirtualizationExtension $true
    VMName

  3. Turn on VM.

Installation

  1. Open PowerShell with administrator rights

    Hyper-V is requirement for WSL installation
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

    Enable WSL
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  2. Windows server does not have Microsoft store, we will have to download the distribution files.
    https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distributions
  3. Extract the .appx package’s contents, using PowerShell:

Copy-Item .\Ubuntu.appx .\Ubuntu.zip
Expand-Archive .\Ubuntu.zip .\Ubuntu

Add-AppxPackage .\app_name.appx

Add your Linux distribution path to the Windows environment PATH
$userenv = System.Environment::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Administrator\Ubuntu", "User")

You can now launch your distribution from any path by typing .exe. For example:
ubuntu.exe.

After launching the ubuntu.exe you might encounter Kernel error. WslRegisterDistribution failed with error: 0x800701bc,

link to package https://learn.microsoft.com/en-us/windows/wsl/install-manual

Reference

https://learn.microsoft.com/en-us/windows/wsl/install-on-server

https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distributions

Powershell on Android Mobile (Userland)

The idea behind this is to install a Linux OS into your mobile and install powershell into the OS.

screenshot from PlayStore

Step 1 – Install and Run Userland.
Step 2 – Choose Ubuntu (18.04) – Enter username and Passwords, choose SSH

Wait a few minutes while loading filesystem

Step 3 – You will eventually see this. Login using ssh password entered before.

Step 4 – Do update and upgrade. (Press Y to agree to upgrade)
sudo apt-get update && sudo apt-get dist-upgrade

Setp 5 – Install wget
sudo apt-get install wget

Step 6 – Create a folder
mkdir ps
cd ps

Step 7 – Download latest release from https://github.com/PowerShell/PowerShell/releases/,
be sure to choose a powershell-xxx-linux-arm64.tar.gz.

wget https://github.com/powershell/powershell/relases/download/download/v7.0.3/powershell-7.0.3-linux-arm64.tar.gz

Step 8 – extract the files from tar.gz
tar -xzvf powershell-7.0.3-linux-arm64.tar.gz

Step 9 – Additional tools needed for this.
sudo apt-get install libunwind8 icu-devtools

Step 9 – type in ./pwsh in the /ps directory to run powershell.

Step 10 (optional) – Adding in PATH variable permanently.
Install file editor
sudo apt-get install nano

Verify the PATH of pwsh directory
sudo find / -name pwsh

Edit ~/.Profile
sudo nano ~/.Profile

Add in PATH=$PATH:/home/username/ps at the bottom of the page

Save and Exit (Ctrl + X)

Type in pwsh to run powershell after this.

Bulk Change Azure Storage Tier

Updated
Script that i got from https://github.com/directorcia/Azure/blob/master/az-blob-tierset.ps1

Run in Powershell

#Module Installation
Install-Module -Name Az -AllowClobber

#Connection to Azure, need to login via browser
connect-azaccount

$systemmessagecolor = “cyan”
$processmessagecolor = “green”
$storageaccountname = “storage account name”
$storageresourcegroup = “storage resource group”
$storagetier = “Archive” # Hot, Cool or Archive

clear-host

write-host -foregroundcolor $systemmessagecolor “Script started`n”

write-host -foregroundcolor $processmessagecolor “Get Storage Account”
$storageaccount = Get-AzStorageAccount -name $storageaccountname -ResourceGroupName $storageresourcegroup

write-host -foregroundcolor $processmessagecolor “Get Storage Account key”
$key = (get-azstorageaccountkey -ResourceGroupName $storageaccount.ResourceGroupName -Name $storageaccount.StorageAccountName).value[0]

write-host -foregroundcolor $processmessagecolor “Get Storage context”
$context = New-AzstorageContext -StorageAccountName $storageaccount.StorageAccountName -StorageAccountKey $key

write-host -foregroundcolor $processmessagecolor “Get Storage containers”
$storagecontainers = get-azstoragecontainer -Context $context

write-host -foregroundcolor $processmessagecolor “Get Items”
$Blobs = @()
foreach ($StorageContainer in $StorageContainers) {
$Blobs += Get-AzStorageBlob -Context $Context -Container $StorageContainer.Name
}

write-host -foregroundcolor $processmessagecolor “Change tier of all items`n”
Foreach ($Blob in $Blobs) {
#Set tier of all blobs to desired tier
$blob.icloudblob.SetStandardBlobTier($StorageTier)
write-host “Changed -“, $blob.name
}

write-host -foregroundcolor $systemmessagecolor “Script finished`n”

—————————- old version—————————-
Module Installation

Install-Module -Name AzureRM
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Import-Module AzureRM

SCRIPT

#Define storage account information
$StorageAccount = "xxxxx"
$StorageAccountKey = "xxxxx"
$containername = "xxxxx"

#Create a storage context
$context = New-AzStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageAccountKey

# Get the blobs
$blobs = Get-AzStorageBlob -Container $containername -Context $context
$blob = $blobs[0]

$blob.ICloudBlob.SetStandardBlobTier("Archive")

$StgAcc = “azuredata”

$StgKey = “qPogbxIVfFD1s57bFemCoQT6xMRyLNCGc0yho+ldeX0aNdYNmMgl9kTQ==”

$Container = “photo”

$ctx = New-AzureStorageContext -StorageAccountName $StgAcc -StorageAccountKey $StgKey

Connect-AzureRmAccount

Get all the blobs in container

$blob = Get-AzureStorageBlob -Container $Container -Context $ctx

Set tier of all the blobs to Archive

$blob.icloudblob.setstandardblobtier(“Archive”)

With reference to https://webmakers.co.nz/how-to-convert-entire-data-in-a-blob-storage-from-cool-storage-tier-into-archive-access-tier/