You are browsing the archive for PowerShell.

Replica DCs on Azure – Manage the Time Configuration settings on the DCs

1:46 pm in Azure, Cloud, DC, hybrid cloud, IaaS, PowerShell, Replica DC, Time Service, W2K12R2 by Wim Matthyssen

This blog post is part of the step-by-step to deploy replica domain controllers (DCs) on Microsoft Azure which can be found here: http://scug.be/wim/2015/09/28/deploying-replica-dcs-in-windows-azure/

Because time management is one of the most critical things to take care of in an AD domain, I will discuss this topic in this part of the series. Like you probably all know, all DCs should be in time synchronization with the DC holding the PDC Emulator role. This DC is responsible for the time in the AD environment. Therefore it’s a best practice to manually set this server to synchronize his time with an external time source on the Internet (time.windows.com, be.pool.ntp.org, us.pool.ntp.org, …). In their place all other DCs sync their time with the this PDC Emulator.

Other than the DCs, all member servers and workstations will sync time with their authenticated DC. Be aware that when the local time of a server or workstation is out of sync (more than 5 minutes – default setting) Kerberos authentication will fail and users won’t be able to login. Besides all that, time stamps are also used in AD replication process. Below I will list some commands you can run in PowerShell, which will manage the time configuration settings on the DCs. Some oh these commands can also be used on a member server or even on a workstation. I hope you have some time to go through it.

 

 

* Picture source: https://technet.microsoft.com/en-us/library/cc773013.aspx

Check and set the Time Zone on a DC (PowerShell):

1) Logon to one of the DCs, open PowerShell and check the Time Zone via following cmdlet:

clip_image003

2) To set the time zone, run following command:

clip_image005

Set the DC which holds the PDC Emulator role to synchronize time with an external time server (PowerShell):

1) To find the server who holds the PDC Emulator FSMO role run following PowerShell command:

clip_image007

2) Logon to the DC holding the PDC Emulator role (GR-DC-01), open PowerShell As an Administrator and run the below command to check the current time against an external time server (time.windows.com):

clip_image009

3) The following command needs to be run on the PDC Emulator (GR-DC-01). Logon to an Azure DC, open PowerShell as an Administrator and run the below command to set the current time in synchronization with an external time server (time.windows.com):

clip_image011

4) The following command needs to be run on the Azure IaaS DCs (or all other DCs not holding the PDC Emulator role). Logon to an Azure DC (AZGR-DC-01), open PowerShell as an Administrator and run the below command to set the current time in synchronization with the PDC Emulator (GR-DC-01):

clip_image013

5) To check if all if the time settings are applied correctly, open up PowerShell (as admin) again and run following command. If you run this on the PDC Emulator and on another DC, you should see different settings under [TimeProviders] if all is configured well:

clip_image015

clip_image017

This concludes this part of the series, but if you’re interested in reading more about the Windows Time Service you can do so via following Microsoft TechNet article: Windows Time Service Technical Reference

Till next time!

Wim Matthyssen (@wmatthyssen)

Replica DCs on Azure – Domain Controller Health Check

9:56 am in Azure, Cloud, Command-line, hybrid cloud, IaaS, PowerShell, Replica DC, W2K12R2 by Wim Matthyssen

This blog post is part of the step-by-step to deploy replica domain controllers (DCs) on Microsoft Azure which can be found here: http://scug.be/wim/2015/09/28/deploying-replica-dcs-in-windows-azure/

After we successfully installed and promoted both IaaS virtual machines (VMs) as DCs it’s time to do an overall health check of your hybrid active directory (AD) environment. Below I will show you some tools you can use to perform these checks. Probably it’s not a complete list but it gets you started.

Check Windows Update for the latest updates (GUI)

It’s always advisable when you install new roles on a server to check for new Windows updates after the completion of the installation. To check and install new updates, follow the steps below:

1) To open the Windows Update page, logon to one of the DCs, open Run and type:

image

2) Click Check for updates and if updates are available, install all preferred updates

Check the Event Viewer (GUI)

Another important tool to advise when you completed the promotion is to check the system, security, application, and other logs in the Event Viewer. To check these Event Viewer logs, follow the steps below:

1) To open Event Viewer, logon to one of the DCs, open Run and type:

image

2) Check the logs for possible warnings or errors

image

Run Dcdiag (command-line)

With the Domain Controller Diagnosis (DCDIAG) utility we can analyze the state of all DCs and domain services in the forest and we can create a report to troubleshoot possible problems. To run Dcdiag, follow the steps below:

1) Logon to one of the DCs as a user with Domain Admin privileges, open PowerShell as an Administrator and run following commands:

image

2) Open the file C:\Dcdiagresult.txt to view the result and to find possible issues

image

Run Repadmin (command-line)

With Repadmin you can diagnose (and in some cases repair) your AD replication status and health. To run Repadmin, follow the steps below:

1) Logon to one of the DCs as a user with Domain Admin privileges, open PowerShell as an Administrator and run following commands:

image

2) Open the file C:\Repadminresult.txt to view the result and to find possible replication issues

image

Run the Best Practice Analyzer (BPA) tools (GUI)

With the BPA tools we can conduct a scan against the DCs to ensure they are configured based on Microsoft and industry best practices. With BPA we can find incorrect configuration settings and security violations, but also investigate poor performance. To run BPA, follow the steps below:

1) Logon to one of the DCs and open Server Manager from the taskbar

2) Select a server role on the left and scroll down to the BPA section. Click TASKS and select Start BPA Scan

image

3) Select all servers you want to scan and click Start Scan

image

4) When the scan is completed, you can review all the results and fix possible issues if preferred

image

I hope this short DC health checklist helps you in the future and if you have any questions just let me know. Till next time!

Wim Matthyssen (@wmatthyssen)

Replica DCs on Azure – Promote the Azure IaaS VMs to a domain controller

12:59 pm in Azure, Cloud, DC, hybrid cloud, IaaS, PowerShell by Wim Matthyssen

This blog post is part of the step-by-step to deploy replica DCs on Microsoft Azure which can be found here: http://scug.be/wim/2015/09/28/deploying-replica-dcs-in-windows-azure/

We will start were we left of in the previous blog post http://scug.be/wim/2016/06/06/replica-dcs-on-azure-add-the-active-directory-domain-services-role/ . We have just installed the Active Directory Domain Services (AD DS), so now it’s time to promote both servers to a domain controller (DC). We will use both the GUI (AZGR-DC-01) and PowerShell (AZGR-DC-02). So let’s kickoff.

Promote this server to a domain controller (GUI)

1) Logon to the server (AZGR-DC-01) as a domain administrator and open Server Manager. If you start were I left off in the previous blog post, you should see a question mark near the flag. Click on it and click on Promote this server to a domain controller

image

image

2) Select Add a domain controller to an existing domain. Normally the correct Domain is filled in automatically, if this is not the case select the proper domain or enter the domain name in the field provided. Select a user (Enterprise Administrator) who has to rights to add a domain controller to the domain and apply the proper credentials

image

3) Select both Domain Name System (DNS) server and Global Catalog (GC). Select the Site (AZU-VNET-1) to which the DC belongs. Fill in the Directory Services Restore Mode (DSRM) password and click Next. As a quick comment I just want to remind you that for best practice reasons this password should be documented, as it can help you to gain access to the AD environment in the event that all domain administrator accounts lose access

image

4) Since we are not using a parent zone, you will receive below warning message A delegation for this DNS server cannot be created because the authoritative zone cannot be found… We may ignore the warning message, as this will not affect whether the DNS feature gets installed. Click Next

image

5) In the Replicate from field select the on premise DC (GR-DC-01) to replicate from and click Next

image

6) Select as location for the AD DS database, log files and SYSVOL data the added Azure data disk with drive letter E: and click Next

image

7) The following window summaries all selected options. If all is right click Next

image

8) If the prerequisites check passes successfully, click Install

image

9) Installation will start and once it’s completed, by clicking on the Close button, the server will reboot. If the server is restarted the DC setup is completed

image

image

image

 

Promote this server to a domain controller (PowerShell)

1) Logon to the server (AZGR-DC-02) as a domain administrator and open PowerShell as Administrator

2) Run following PowerShell automation script (store with .ps1 extension or copy and run directly) to promote this server to a DC:

image

3) When asked enter a username and password (this user should have Enterprise Administrator rights)

image

4) Fill in the Directory Services Restore Mode (DSRM) password and confirm it a second time

image

5) Installation will go on and when succeeded the server will reboot. After the restart the DC installation is completed

image

image

This ends the seventh part of the series. Still a few steps to go, so please continue through the rest of the series to complete the setup. Till next time!

Wim Matthyssen (@wmatthyssen)

Replica DCs on Azure – Add the Active Directory Domain Services role

2:57 pm in Azure, Cloud, DC, hybrid cloud, IaaS, PowerShell by Wim Matthyssen

This blog post is part of the step-by-step to deploy replica DCs on Microsoft Azure which can be found here: http://scug.be/wim/2015/09/28/deploying-replica-dcs-in-windows-azure/

As a next step we need to install the Active Directory Domain Services (AD DS) role. We can do this trough the GUI (on Azure IaaS v1 VM 1 – AZGR-DC-01) or with the use of PowerShell (on Azure IaaS v1 VM 2 – AZGR-DC-02). Below I will show you both.

Install AD DS (GUI)

1) Logon to the server trough RDP, open Server Manager, on the Dashboard select Add roles and features

image

2) Click Next on the Before you begin screen

3) Select Role-based or feature-based installation and click Next

4) Select to correct server and click Next

5) Select Active Directory Domain Services

image

6) On the screen popped up, select Add Features

image

7) Click Next on the Select server roles page

image

8) Click Next

image

9) Click Next

image

10) Click Install

image

11) Wait until the installation is finished and then click Close

image

image

 

Install AD DS (PowerShell)

1) Logon to the server trough RDP and open a PowerShell window (as an administrator)

2) To install AD DS, run the following command as shown below

image

image

image

3) You can also verify the success of the role installation by running following command

image

That ends this part of the series. In the next part we will start were we ended, with the promotion of the server to a DC. So please continue through the rest of the series to complete the setup. Till next time!

Wim Matthyssen (@wmatthyssen)

Microsoft Azure Backup Server: System State backup fails with WSB Event ID: 546

7:07 am in Azure, Azure Backup, DC, IaaS, Microsoft Azure Backup Server, PowerShell, Public Cloud by Wim Matthyssen

After setting up a Microsoft Azure Backup Server (MABS) running on an IaaS v1 VM for a customer, I encountered a problem with a System State backup. The server having the problem was a Domain Controller (DC) also running as an Azure IaaS v1 VM and a member of the Domain Controller Protection Group on the MABS server. You can see the error message found on the MABS server in the screenshot below

clip_image002

“DPM cannot create a backup because Windows Server Backup (WSB) on the protected computer encountered an error (WSB Event ID: 546, WSB Error Code: 0x1751870). (ID 30229 Details: Internal error code: 0x80990ED0)”

On the DC itself following error message was found:

clip_image004

“The backup operation attempted at ‘‎2016‎-‎05‎-‎10T14:00:28.139491000Z’ has failed to start, error code ‘2155348032’ (The backup storage location is invalid. You cannot use a volume that is included in the backup as a storage location. ). Please review the event details for a solution, and then rerun the backup operation once the issue is resolved.”

To fix this problem I followed the steps below:

1) On the server with the problem, verify if no other backup or recovery operation is running by opening a PowerShell window (as administrator) and typing:

clip_image006

If the command output indicates that no operation is running, then you can proceed to step 2. Otherwise wait until the current job is completed and retry the failed System State backup job

2) In the same PowerShell windows type the following command:

clip_image008

Verify of the writer named System Writer is running Stable and without any errors. If so proceed to step 3. Otherwise manually restart the VSS Writer, if it fails again it’s necessary to reboot the server

3) Open Services and verify if the Cryptographic Services is running and set to startup Automatically.

clip_image009

clip_image011

4) The check if Windows Server Backup (WSB) is able to take a local System State Backup, open up PowerShell (as an administrator) and run the below command. When asked press (Y). Be aware it could take a while before the job completes:

clip_image013

clip_image015

clip_image017

If the backup is successfully proceed to step 5. Otherwise check the Windows event viewer for other errors

5) Open the registry editor and go to the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wbengine. Create a key called SystemStateBackup and set the values of this entry as follows:

Name: AllowSSBToAnyVolume
Data type: DWORD
Value data: 1

clip_image018

clip_image020

You also can use PowerShell (as an administrator) to create the registry key, to do so run following command:

6) When done, logon to the MABS server and retry the failed System State backup job by right-clicking and selecting Perform consistency check … Verification will start and at the end the job will complete with success

clip_image022

image

This concludes this blog post, hope it’s useful. Till next time!

Wim Matthyssen (@wmatthyssen)

Microsoft Azure Backup Server: System State backup fails with the message replica is inconsistent

8:00 pm in Azure, Azure Backup, Cloud, IaaS, Microsoft Azure Backup Server, PowerShell, Public Cloud, Windows Server Backup by Wim Matthyssen

Last week I was setting up a Microsoft Azure Backup Server (MABS) for a customer running on an Azure IaaS v1 VM for taking disk and System State backups which are stored in an Azure Backup vault for long-term retention. After done all of the configuration, like deploying the agents and creating the Protection Group(s), most of the backup jobs ran without any issues, only the System State backups were failing. This is shown in the screenshot below.

clip_image002

For those who not know, I will first list some extra information to clarify what a System State backup really is:

  • A System State backup uses the Windows Server Backup (WSB) feature to take a snapshot of the system state and saves it locally to the server before moving it to the MABS server storage pool
  • It contains the following system components: System Registry, SYSVOL directory, Boot files including the system files, Active Directory, COM + Class Registration Database, Certificate Services, Cluster service information, IIS Metadirectory and System files that are under Windows File Protection (some of these items are only included if the specified service is installed – AD, ISS, Certificates)
  • §System state backup and restore operations include all system state data: you cannot choose to backup or restore individual components due to dependencies among the system state components. However, you can restore system state data to an alternate location in which only the registry files, Sysvol directory files, and system boot files are restored.

Troubleshooting a System State backup failure can be frustrating as there are a lot of underlying components that come into play during the process. To figure out what was causing the System State backup(s) to fail, I followed the steps below:

1) Check out the Critical alerts for a specific server having the issue in the Monitoring pane on the MABS server. Here I found the following error:

clip_image004

2) After reading the description carefully, you can see there should be enough free space on the target server and also WSB should be installed. So to verify,  first logon to the specific server trough RDP

3) Check out the free disk space by opening Disk Management

clip_image005

4) Like you can see, there is plenty enough of free disk space to store a local System State backup

clip_image007

5) To check if WSB is installed, run following cmdlet in PowerShell (as an Administrator)

clip_image009

6) Like you can see WSB is not installed and probably causing the failure of the System State backup

7) Install WSB trough PowerShell (as an Administrator)

clip_image011

clip_image013

8) Check if this fixes the issue by opening the Microsft Azure Backup MMC on to the MABS server. Go to Protection and select Perform consistency check …

clip_image015

9) Click Yes to perform the consistency check

clip_image016

10) You will see the Protection Status changing to “Replica is inconsistent, verification in progress”

clip_image018

11) To be sure everything is working like it should, you can logon to the specific server and open WSB locally by opening the Run box and typing wbadmin.msc

clip_image019

12) Select Local Backup. If all is running fine, their should be a local backup job running at the moment

clip_image021

13) After a while the job should complete Successful

clip_image023

14) You should also verify the successful System State backup in the MABS console. Like you can see the Protection Status of the job is OK now (also for all other System State jobs, after WSB was installed locally on all those servers)

clip_image025

This concludes this blog post, hope it helps!

Wim Matthyssen (@wmatthyssen)

Replica DCs on Azure – Adjustment of some server settings before promoting the DCs

9:05 pm in Azure, Cloud, DC, hybrid cloud, IaaS, PowerShell by Wim Matthyssen

This blog post is part of the step-by-step to deploy replica DCs on Microsoft Azure which can be found here: http://scug.be/wim/2015/09/28/deploying-replica-dcs-in-windows-azure/

Before we promote the servers to DCs, we can do some configuration like for example adding the server(s) to the domain, place the server(s) in the correct organizational unit (OU), create an inbound rule in Windows Firewall to allow ICMPv4 and set the correct time zone. Installing all Windows Updates is also an important step to do for security reasons, but also to fix problems or to foresee additions to the operating system (OS). Below I will show you how you can do all of the above by using the GUI or/and trough PowerShell.

Add the server to the domain (GUI)

1) Logon to the server trough RDP, open Server Manager, select Local Server and select WORKGROUP

image

2) Click Change…

image

3) Fill in the name of the Domain (for example contoso.local) and when asked enter a username and password of an account who is able to add a server to the domain. Click OK

image

4) Click OK when the “Welcome to the contoso.local domain.” shows up

image

5) Click OK

image

6) Click Close

image

7) Click Restart Now

image

8) After the reboot the server is added to the domain

image

Add the server to the domain (PowerShell)

1) Logon to the server trough RDP and open PowerShell as an administrator. Run following cmdlets (replace contoso.local by your own domain name):

image

2) When asked restart the server with following cmdlet:

image

3) After the reboot the server is added to the domain

image

 

Place the server(s) in the correct OU (GUI)

1) Logon to an on premise DC and open Active Directory Users and Computers by opening Run and typing dsa.msc. Click OK

image

2) Click Action and select Find…

image

3) In the Find Computers screen, select Computers in the Find: field and Entire Directory in the In: field. Type the name in the Computer name field (in my case I typed I the 4 first characters of both Azure IaaS VMs who will be promoted to DC)

image

4) Select both servers and right-click. Select Move…

image

5) Select the correct OU (in my case DC) and click OK. Close the Find Computers window

image

6) After a refresh (F5), the servers are added to the correct OU

image

 

Place the servers in the correct OU (PowerShell)

1) Logon to an on-premise DC trough RDP and open PowerShell as an administrator. Run following cmdlets (replace contoso.local by your own domain name):

image

2) After a refresh (F5), the servers are added to the correct OU

image

 

Install Windows Updates (GUI)

1) Logon to the server trough RDP, open Run and type wuapp.exe. Click OK

image

2) To change Windows Update settings (mostly already taken care of with a GPO), click Change settings

image

3) Change the settings like your company prefers. Press OK

image

4) The server will start Checking for updates…

image

5) Install all necessary updates and if needed reboot (repeat this step until all updates are installed)

image

 

Enable ICMPv4 rule in Windows Firewall (PowerShell)

1) Logon to the server trough RDP and open PowerShell as an administrator. Run following cmdlet:

image

2) Like you can see the rule is created and I’m now able to ping the server

image

image

 

Set the time zone (PowerShell)

1) Open up PowerShell as an administrator and run the following command:

image

image

 

Enabling the High Performance Power Plan (PowerShell)

1) Open up PowerShell as an administrator and run the following script:

image

image

 

That ends the fifth part of this series. Please continue through the rest of the series to complete the setup (if all are available).

Till next time!

Wim Matthyssen (@wmatthyssen)

Replica DCs on Azure – Initialize and format the additional data disk

11:34 am in Azure, Cloud, DC, IaaS, PowerShell by Wim Matthyssen

 

This blog post is part of the step-by-step to deploy replica DCs on Microsoft Azure which can be found here: http://scug.be/wim/2015/09/28/deploying-replica-dcs-in-windows-azure/

Before we can promote the servers to DCs, we need to initialize and format the additional data disk that we added with the VM creation script to store the Active Directory Database and logs. I will explain how you can do this trough the GUI and via PowerShell.

Initialize and format the additional data disk trough the GUI

1) Logon to your Azure IaaS VM trough RDP, open Run and type diskmgmt.msc, press OK

clip_image001

2) The Disk Management console will open and a screen will pop-up to initialize the additional data disk. Select disk 2 and GPT as the partition style, press OK

clip_image002

3) Right-click Disk 2 and select New Simple Volume…

clip_image004

4) Click Next

clip_image005

5) Click Next on the Specify Volume Size page

clip_image006

6) Choose E as the drive letter and press Next

clip_image007

7) Fill in a name for the Volume label (in my case I use AD) and click Next

clip_image008

8) Click Finish

clip_image009

clip_image011

Initialize and format the additional data disk trough PowerShell

1) Logon to the Azure IaaS VM trough RDP and open PowerShell as an administrator.

2) Run following PowerShell cmdlet:

clip_image013

3) To confirm type Y and press Enter

 

clip_image015

clip_image017

clip_image019

That ends the fourth part of this series. Please continue through the rest of the series to complete the setup (if all are available).

Till next time!

Wim Matthyssen (@wmatthyssen)

Replica DCs on Microsoft Azure – Create the VMs with Azure PowerShell

4:43 pm in Azure, Cloud, DC, IaaS, PowerShell, Public Cloud by Wim Matthyssen

This blog post is part of the step by step to deploy replica DCs on Azure which can be found here: http://scug.be/wim/2015/09/28/deploying-replica-dcs-in-windows-azure/

In this part I will setup the replica DC VMs with the use of an Azure PowerShell script. To do so follow the steps below:

1) Download the Built_DCs.xlsx file here. When downloaded rename the extension from .xlsx to .csv and adjust the file to your needs. In my example I saved it in the following folder C:\Temp\Azure_setup_DC

 

clip_image003

2) To check if the Cloud Service name used in the .csv already exists on Azure, run the below PowerShell cmdlet. If the name exists, the cmdlet returns $True. If the name does not exist and can be used, it returns $False

 
3) Deploy both Azure IaaS VMs with the following Azure PowerShell script, in my example named Azure_built_DCs.ps1. This file is also stored under the folder C:\Temp\Azure_setup_DC. This script accesses the previously created Built_DCs.csv file were all necessary variables are declared. Both VMs will be built from the Azure Windows Server 2012 R2 Datacenter image, will be placed in an Availability Set and an extra data disk will be attached (stored in the azudata01 Storage Account) with a size of 1023 GB and the host-cache mode set to None

 

clip_image005

4) When the script has run you can verify if all settings are applied correctly from the Azure classic portal

clip_image007

clip_image009

clip_image011

clip_image013

5) You should also be able to RDP into both VMs

clip_image015

image

That ends the second part of this series. Please continue through the rest of the series to complete the setup (if all are available).

Till next time!

Wim Matthyssen (@wmatthyssen)

Useful PowerShell commands for Hyper-V management

5:48 pm in Hyper-V, PowerShell, Private Cloud by Wim Matthyssen

Hi all,

In this blog post I will list some PowerShell commands I use from time to time on customers Hyper-V hosts to get some work done a little bit easier and faster. You can just run these commands directly in PowerShell (run as administrator) or you can copy them and save them as a .PS1.

This list is a work in progress and will be expanded in the future. So be sure to bookmark this post if you find it useful.

For the moment PowerShell v4 already includes 178 Hyper-V related cmdlets. If your interested in het entire list you can go to the following link: https://technet.microsoft.com/en-us/library/hh848559.aspx

In my commands I use the virtual machine (VM) CON-VM-01 as an example. If you want use the command just change the name to the name of your VM. Also for IP Addresses I use the 192.168.0.0 range, so if your IP range is different just change it.

Below you can find the PowerShell commands:

1) Show what PowerShell Hyper-V cmdlets are available

Get-Command –Module Hyper-V

image

2) List the current configuration of the Hyper-V host

Get-VMHost | Format-List *

image

3) Listing all VMs on a Hyper-V host

Get-VM

image

4) Listing all running VMs on a Hyper-V host

Get-VM | where {$_.state -eq 'running'} | sort Uptime | select Name,Uptime,@{N="MemoryMB";E={$_.MemoryAssigned/1MB}},Status

image

5) Check if a VM has the processor compatibility mode enabled. You can find more info about this mode via following link: https://technet.microsoft.com/en-us/library/dn859550.aspx

Get-VMProcessor -VMName * | select VMName, CompatibilityForMigrationEnabled

image

6) Enable Offload Data Transfer (ODX). You can find more info about ODX via following link: https://technet.microsoft.com/en-us/library/hh831628.aspx

Set-ItemProperty hklm:\system\currentcontrolset\control\filesystem -Name "FilterSupportedFeaturesMode" –Value 0

7) Change the default location where VMs and virtual hard disks are stored on your Hyper-V host

Set-VMHost -VirtualHardDiskPath E:\VMs -VirtualMachinePath E:\VMs

8) Retrieve information about all network adapters on the Hyper-V host

Get-NetAdapter -Name * | Format-List -Property Name, InterfaceDescription, InterfaceName

image

9) Write the Hyper-V host event log to a txt file (also applicable for other servers)

Get-EventLog application -Newest 1000 | where {$_.EntryType -eq "Error"} | Out-File "$env:systemdrive\eventlog.txt" -width 300
Notepad "$env:systemdrive\eventlog.txt"

10) Get the IP Adress of a certain VM

Get-VMNetworkAdapter -VMName CON-VM-01 | Select -expand IPAddresses

11) List the IP4 Adresses of all currently running VMs

Get-VM | where { $_.state -eq 'running'} | Get-VMNetworkAdapter | Select VMName,SwitchName,@{Name="IP";Expression={$_.IPAddresses | where {$_ -match "^192\."}}} | Sort VMName

image

12) Remove a VM with all folders and virtual hard disks

Get-VM CON-VM-01 | %{ Stop-VM -VM $_ -Force; Remove-VM -vm $_ -Force ; Remove-Item -Path $_.Path -Recurse -Force}

As a final remark I want to mention that PowerShell can’t prevent mistakes and like you all probably know they’re easy to make. So keep your eyes open when your running these commands on production Hyper-V hosts.

Till next time!

Wim Matthyssen (@wmatthyssen)