Invoke PowerShell commands to multiple servers at the same time

One of the best things of PowerShell is that you can invoke commands to multiple servers at once. This can save a lot of time when implementing new features or troubleshooting errors. The PowerShell Command that makes this possible is:

  • Invoke-Command -ComputerName [Computername1], [Computername1] -command {[PowerShell Command here]}

In this example i have installed the Windows Clustering Feature on three different servers with the following command:

  • Invoke-Command -ComputerName 2012R2-AS07, 2012R2-AS08, 2012R2-AS09 -command {Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools}

2014-10-25 15_11_29-mRemoteNG - confCons.xml

In this example i have added a Firewall rule on three different servers with the following command:

  • Invoke-Command -Computername 2012R2-AS07, 2012R2-AS08, 2012R2-AS09 -command {New-NetFirewallRule -DisplayName “SQL Server Browser Service” -Direction inbound –LocalPort 1434 -Protocol TCP -Action Allow -Profile Domain}

In this example i have specified the sxs folder:

  • Install-WindowsFeature –name NET-Framework-Core -source \\[Servername]\sxs -ComputerName 2012R2-AS07

RD Session Host server Install Mode

Applications developed for end users of your system must be installed properly on an RD Session Host server so that they can be accessed remotely. Before you install an application on an RD Session Host server, make sure you understand any compatibility issues associated with the application when it is running in a Remote Desktop Services environment.

Make sure you install the RD Session Host role service on your server before you install any applications that users will need to run within their remote sessions or as RemoteApp programs. If you install the RD Session Host role service after you have installed your applications, the applications might not function correctly in a multi-user environment.

To install an end-user application on an RD Session Host server, the RD Session Host server must first be switched into a special install mode called RD-Install to ensure that the application will be able to run in a multi-user environment. After your applications have been installed on your RD Session Host server, you must switch the server back into execution mode before users can remotely connect to your server. You can switch between the install and execute modes from the command line using these commands:

  • change user /install
  • change user /execute

To determine the current install mode of your RD Session Host server, use this command:

  • change user /query

2014-10-21 21_39_04-mRemoteNG - confCons.xml

 

Set Network Location to Private in Windows 8.1 or Server 2012 R2

Sometimes a new Network Location gets mis-identified as Public when it should be Private, or the other way around. Changing this in the GUI is certainly possible, but the PowerShell method is faster. So let’s take advantage of the improved Windows PowerShell support in Windows 8.1 and do it quickly and easily.

2014-10-21 21_14_00-2012R2-DC02 on I5-PC - Virtual Machine Connection

First, let’s open up an elevated PowerShell window from our user session and find out what our current network location is set to:

  • Get-NetConnectionProfile

2014-10-21 21_12_20-2012R2-DC02 on I5-PC - Virtual Machine Connection

From this, we see that the problem interface has an Interface Index of 12. To change the network type execute the following command:

  • Set-NetConnectionProfile -InterfaceIndex 12 -NetworkCategory Private

2014-10-21 21_13_11-2012R2-DC02 on I5-PC - Virtual Machine Connection

The network has been changed to a Private Network.

2014-10-21 21_13_40-2012R2-DC02 on I5-PC - Virtual Machine Connection