Skip to content

Instantly share code, notes, and snippets.

View smoonlee's full-sized avatar
🏠
Working from home

Simon Lee smoonlee

🏠
Working from home
View GitHub Profile
@smoonlee
smoonlee / Get-AzSystemUptime
Created May 5, 2024 13:17
Get Uptime for Linux and Windows machines in Azure
function Get-AzSystemUptime {
param (
[string] $resourceGroup,
[string] $vmName
)
$osType = (Get-AzVM -ResourceGroupName $resourceGroup -Name $vmName).StorageProfile.OsDisk.OsType
if ($osType -eq 'Windows') {
Write-Output "Getting System Uptime for $vmName in $resourceGroup..."
Write-Warning "This may take up to 35 seconds"
@smoonlee
smoonlee / ubuntu-linux-virtual-installer.sh
Created March 29, 2024 16:58
Hyper-V Ubuntu Virtual Kernel Setup script
#!/bin/bash
# Microsoft Hyper-V Intergration Services (Ubuntu/Debian Install Script)
# Author: Simon Lee
# Script Revision: 1.0
# Description: Install linux-virtual kernal for Ubuntu/Debian Server
# Clear Current Screen
clear
# Check Session Status
@smoonlee
smoonlee / gist:802b38d57f04f9d316ea9f5cc7c83fa3
Created March 26, 2024 18:18
Convert REG_BINARY to Human
# Get the value of a REG_BINARY from the registry
$value = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\Path\To\Your\Key" -Name "ValueName"
# Convert the REG_BINARY value to a readable format
$readableValue = [System.BitConverter]::ToString($value.ValueName)
# Display the readable format
Write-Output $readableValue
# AutoBuild Operating System Installation
if ($autoBuild) {
Write-Output `r "ABC :: AutoBuild is enabled, Applying Operating System Image..." `r
Write-Output "ABC :: Checking AutoBuild Configuration..." `r
Write-Output "ABC :: VM Generation: [$hvGeneration]"
Write-Output "ABC :: Iso Path: [$isoPath]"
# Mount OS Disk
Write-Output `r "ABC :: Mounting OS Disk"
$osDiskContext = Mount-VHD -Path $osDiskPath | Out-Null
@smoonlee
smoonlee / hugo-shortcode-example
Created January 16, 2024 17:20
github-hugo-shortcode-sample-code
This is a public gist
created in January 2024
to show case Hugo Gist Shorcodes.
- Created by Simon, 16-01-2024
## This Script is intended to be used for Querying remaining time and resetting Terminal Server (RDS) Grace Licensing Period to Default 120 Days.
## Developed by Veli Kadir KOZAN(kadir@kadirkozan.com.tr) June 20th 2021
## www.kadirkozan.com.tr
Clear-Host
$ErrorActionPreference = "SilentlyContinue"
## Display current Status of remaining days from Grace period.
$GracePeriod = (Invoke-WmiMethod -PATH (gwmi -namespace root\cimv2\terminalservices -class win32_terminalservicesetting).__PATH -name GetGracePeriodDays).daysleft
Write-Host -fore Green ======================================================
Set-Location C:\Code\<repo-name>
# Create me a File
$i = (Get-Item *.txt).Count + 1 ; New-Item file$i.txt
@smoonlee
smoonlee / gist:aa22592603235de46e1c3bad24dc2a8e
Created November 30, 2023 13:21
linux-hyper-v-enhanced-session-patch-notes
# Enhanced Session HvBus
``` pwsh
Set-VM ubuntu -EnhancedSessionTransportType HvSocket
https://github.com/Hinara/linux-vm-tools
wget https://raw.githubusercontent.com/Hinara/linux-vm-tools/ubuntu20-04/ubuntu/22.04/install.sh
Reboot
> [!NOTE]
> Highlights information that users should take into account, even when skimming.
> [!TIP]
> Optional information to help a user be more successful.
> [!IMPORTANT]
> Crucial information necessary for users to succeed.
> [!WARNING]
@smoonlee
smoonlee / Get-LastRebootTime.ps1
Last active November 10, 2023 08:40
PowerShell 5 - Get Last Reboot for Azure VM
# Function to convert seconds to a readable format
function ConvertToReadableTime {
param (
[int]$uptimeSeconds
)
$uptime = New-TimeSpan -Seconds $uptimeSeconds
"{0} days, {1} hours, {2} minutes, {3} seconds" -f $uptime.Days, $uptime.Hours, $uptime.Minutes, $uptime.Seconds
}
# Get the hostname