How to delete disk partitions on Windows using PowerShell

Today I just added an old SSD to a Windows machine to use it as a back up drive. With old disks, usually they come with existing data, and I wanted to get rid of it. The problem is I couldn’t figure out how to do this using the Disk Management, the native GUI application used to manage disks. The problem could be simple to Windows users. Basically, when I right-clicked on the 2 partitions (450 MB and 100 MB) on Disk 0, there is no option to remove them....

May 15, 2022 · 3 min · 618 words · kenno

Where is which in PowerShell

As the title says, an easy way to find out the path of a program/command on Windows using PowerShell can be done with Get-Command cmdlet. For example, I want to find out where I had installed nvim (Neovim) on a rarely use Windows machine. To do this, I can execute the following command: ❯ Gt-Command nvim CommandType Name Version Source ----------- ---- ------- ------ Application nvim.exe 0.0.0.0 C:\Program Files\Neovim\bin\nvim.exe With PowerShell, we can also just print a specific attribute (?...

June 16, 2021 · 1 min · 114 words · kenno

Line Continuation in PowerShell

Usually on bash command-line, the line break character is \. So when I first started to use PowerShell, the \ didn’t work for me. It turned out that the line-break or line continuation in PowerShell is the back tick: `. Here is an exmaple of PowerShell command to create a DNS delegation in one line: PS C:\ Add-DnsServerZoneDelegation -Name "example.net" -ChildZoneName "lab.example.net." -NameServer "idm.lab.example.net." -IPAddress 172.25.250.8 -PassThru -Verbose And we can break it to mutiple line as:...

December 23, 2020 · 1 min · 99 words · kenno

DNS Delegation on Windows Server

One of the requirements to join an Identity Management Server (IdM) to an Active Directory (AD), a DNS delegation needs to be created on AD. With the Red Hat training for RH362, we were taught to use a command-line interface program called dnscmd on AD server. I personally found this command very cumbersome, and I think a better way is to do this DNS delegation using PowerShell cmdlet. I’ll demonstrate how to do DNS delegation both using dnscmd and PowerShell cmdlet....

November 19, 2020 · 2 min · 400 words · kenno

Create Folder Recursively With Powershell

Let’s say I want to create the following directories: C:/Program Files/MiKTeX 2.9/tex/latex/math using PowerShell because, as you may guess it, it’s a Windows directory structure. Here’s the command to do that: PS C:\> New-Item -Type Directory -Path "C:/Program Files/MiKTeX 2.9/tex/latex/math" The command seems simple enough. So why did I create this post? Well, guess what? I have to Google this out for the 3rd time this month. From now, if I need to look it up again, I can just go to https://blog....

May 14, 2020 · 1 min · 91 words · kenno

Delete a Local User Account With PowerShell

I need to delete a user from the PowerShell terminal and I don’t know how to do it. Well, fear no more, let’s have a quick read on Remove-LocalUser on how to do this. The command to delete the user is Remove-LocaUser. Remove-LocalUser [-InputObject] <LocalUser[]> [-WhatIf] [-Confirm] [<CommonParameters>] Remove-LocalUser [-Name] <String[]> [-WhatIf] [-Confirm] [<CommonParameters>] Remove-LocalUser [-SID] <SecurityIdentifier[]> [-WhatIf] [-Confirm] [<CommonParameters>] Here is an example of deleting a local user called simba....

April 22, 2020 · 1 min · 132 words · kenno

Create a User Account with PowerShell

Today I learned how to create a user account on Windows 10 using PowerShell. Let’s create a small exercise to demonstrate how can this be easily done. Task: “Create a local user account named ’localaccount’ with the password BlueHat. This new user should have admin privilege.” First, launch the PowerShell (terminal?), by running as Administrator. The password will be stored in a variable called $Password: $Password = Read-Host -AsSecureString ******* Now we’re ready to create a new local account:...

October 24, 2019 · 1 min · 161 words · kenno