Showing posts from September, 2018

Create a PowerShell Module

Recently I came across an issue on our Hyper-V Cluster. One of the VM was stuck in the “Stopping” state. I had to force the VM to shutdown by kill its process on the Hyper-V host. To do so, I first find out the VM’s GUID and then kill the process with the same GUID. Needless to say, the whole process can be achieved with the PowerShell commands below. # Get the VM GUID and find the process with the GUID $VM = Get-VM -Name $VMName -ErrorAction Stop $VMGUID = $VM .Id $VMWMProc = ( Get-WmiObject Win32_Process | Where-Object { $_ .Name -match 'VMWP' -and $_ .CommandLine -match $VMGUID }) # Kill the VM process Stop-Process ( $VMWMProc .ProcessId) – Force This is a pretty short and simple script, which is perfect for making a module. We have number of Hyper-V hosts across our environment. Instead of copying the script around, module will help us better organize the code and make it more re-usable. I also like to share this small function with our glo

Build a PDC in Azure with DSC

There are a lot ARM templates out there can do this. But in this post, we will go through the nitty gritty of using DSC to automate the PDC setup. Before we begin, I assume you already know what DSC is and does. Otherwise, check it out here . First, let’s build a new VM in Azure with these PowerShell commands. In this case, the VM will have direct Internet and can be accessed via Internet directly. Just to state here that this is definitely not the practice you want to adopt in production. # Create a new resource group New-AzureRmResourceGroup -Name $ rsgName -Location $ location # Create a subnet configuration $ subnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name "adsubnet" -AddressPrefix 10.188 . 0.0 / 24 # Create a virtual network $ vnet = New-AzureRmVirtualNetwork -ResourceGroupName $ rsgName -Location $ location -Name "tomlabVNET1" -AddressPrefix 10.188 . 0.0 / 16 -Subnet $ subnetConfig # Create a public IP address and spec

Install AWS CLI on WSL Ubuntu

Within Windows command prompt, AWS CLI does not provide autocomplete feature. According to AWS document, the feature is only available on “Unix-like systems”. Luckily we have WSL (Windows Subsystem for Linux)on Windows 10. We can simply run AWS CLI from the WSL with autocomplete provided natively. Problem solved! Here are the steps I took to get AWS CLI installed on my WSL Ubuntu. Before we install AWS CLI package itself, we need to get Python package manager pip installed first. Download pip install script. Notice I use –k here, this is because I am running this behind company proxy, the proxy changes HTTPS certificate to its own certificate. Without –k the command will fail. You can leave it out if you have direct Internet access $ curl -O -k Next, the usual update apt command $ sudo apt-gt update Then we download and install Python minimal $ sudo apt install python-minimal Now we can install pip, the --trusted-host here is again