Powershell, Server 2016


The Set-WebApplicationProxyApplication cmdlet modifies settings of a web application published through Web Application Proxy. Specify the web application to modify by using its ID. Note that the method of preauthentication cannot be changed. The cmdlet ensures that no other applications are already configured to use any specified ExternalURL or BackendServerURL.

Set-WebApplicationProxyApplication -ID 994A4543-7983-77A3-1E6D-1163E7419AC1 -ExternalUrl https://webapp.abc.com/

[-ClientCertificateAuthenticationBindingMode <String>]
[-BackendServerCertificateValidation <String>]
[-ExternalUrl <String>]
[-ExternalCertificateThumbprint <String>]
[-BackendServerUrl <String>]
[-ADFSUserCertificateStore <String>]
[-PersistentAccessCookieExpirationTimeSec <UInt32>]
[-BackendServerAuthenticationMode <String>]
[-BackendServerAuthenticationSPN <String>]
[-Name <String>]
[-InactiveTransactionsTimeoutSec <UInt32>]
[-ClientCertificatePreauthenticationThumbprint <String>]
[-ID] <Guid>
[-CimSession <CimSession[]>]
[-ThrottleLimit <Int32>]

Powershell, Server 2016

How to access a Nano Server

Because Nano Server does not support a local session, it must be accessed remotely.

IP Address of the Nano Server:
1. Start an elevated PowerShell ISE session.
2. Set the Trusted Host. This is a one-time setting for each remote machine. You’re basically telling your development machine to trust the remote Nano Server.
Set-Item WSMan:\LocalHost\Client\TrustedHosts “”
3. Start the session.
Enter the following commands into the PowerShell ISE command line:
$ip = “” 
$s = New-PSSession -ComputerName $ip -Credential ~\Administrator
Enter-PSSession -Session $s

Powershell, Server 2016

Deploy Network Controller using Windows PowerShell

Install-WindowsFeature -Name NetworkController –IncludeManagementTools


New-NetworkControllerNodeObject –Name <string> -Server <String> -FaultDomain <string>-RestInterface <string> [-NodeCertificate <X509Certificate2>]

Install-NetworkControllerCluster –Node <NetworkControllerNode[]> –ClusterAuthentication <ClusterAuthentication> [-ManagementSecurityGroup <string>][-DiagnosticLogLocation <string>][-LogLocationCredential <PSCredential>] [-CredentialEncryptionCertificate <X509Certificate2>][-Credential <PSCredential>][-CertificateThumbprint <String> ] [-UseSSL][-ComputerName <string>]

Install-NetworkController –Node <NetworkControllerNode[]> –ClientAuthentication <ClientAuthentication> [-ClientCertificateThumbprint <string[]>] [-ClientSecurityGroup <string>] -ServerCertificate <X509Certificate2> [-RESTIPAddress <String>] [-RESTName <String>] [-Credential <PSCredential>][-CertificateThumbprint <String> ] [-UseSSL]

Powershell, SCCM, System Center Configuration Manager

Hot to use PowerShell to manage System Center Configuration Manager

The easiest way is by launching the Configuration Manager console. In the upper left corner, there’s a blue rectangle. Click the white arrow in the blue rectangle, and choose Connect via Windows PowerShell.


Now, you need to import the Configuration Manager module by using the Windows PowerShell Import-Module cmdlet. To import the Configuration Manager module, you will have to specify the path to the Configuration Manager module or change to the directory that contains the module. Here, we’re going to change to the module’s directory.

PS C:\>

PS C:\> CD ‘C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager’

PS C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager>

Then import the module;

Import-Module .\ConfigurationManager.psd1

To run the Configuration Manager cmdlets, you need to switch the path to the Configuration Manager site.

PS C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager>CD MSN

MSN – is my site code


Confirm that the Configuration Manager module has been loaded by using the cmdlet below;

PS MSN:\> Get-CMSite

BuildNumber : 7958

Features : 0000000000000000000000000000000000000000000000000000000000000000 InstallDir : C:\Program Files\Microsoft Configuration Manager

Mode : 0

ReportingSiteCode :

RequestedStatus : 110

ServerName : cm1.company.pri

SiteCode : MSN

SiteName : MSN pri site

Status : 1

TimeZoneInfo : 000001E0 0000 000B 0000 0001 0002 0000 0000 0000 00000000 0000 0003 0000 0002 0002 0000 0000 0000 

Type : 2

Version : 5.00.7958.1000


Powershell special characters

When you are using Powershell, it really helps if you use special characters to write your own scripts or interpret someone else’s scripts. Some of them are really common and get used very often….

# Hash – Single line comment


#This script is for ....
#This variable is to ...


$ Dollar sign – is used to declare a variable

$ComputerName = "Server1"
$password = "p@sw0rd"


| Pipeline- Executes the left side and with  the output feeds to the right


Get-Process | Select -first 10


% Percentage – Short for “FOREACH”


% ($Server in $Servers) { Write-Host $_}


? Question Mark – Short for “Where”


Get-process | ? {$_.name -like 'win*' -and $_.status -eq 'Running'}


@ () – Declares an array


$Servers = @ ("server1", "server2", "server3")


@ {} – Declares an hash table


$servers = @{"server1" = "Dell";
             "server2" = "HP";
             "server3" = "Nutanix"}


------------------------------------ OR

$params = @{};
$params['class'] = 'Win32_DiskDrive';
$params['filter'] = 'size=256052966400'; #find a drive which is 256GB in size
Get-WmiObject @params
Get-WmiObject -Class 'Win32_DiskDrive' -Filter 'size=256052966400'


& Ampersand – Executes strings as commandlets


& "Get-Scheduledjob"


! Exclamation – Short for “not”

$serverName = $null;
if(!$serverName) { Write-Host '$a is null' }


:: Double colon – Reference static member of a class. The class name must be enclosed in square brackets.

[string]::Equals = ("Computers", "COMPUTERS")
False # this will compare these two strings and returns false




Failover Clustering, Hyper-V, Powershell

PowerShell Script Monitors Security Logs and Sends Email Alerts

function Get-ADAuditLogsv2{

Param ($from = “abc@domain.local”,
$servers = (“DCVM01”),
$eventids = @(1076,1039),
$date = ((Get-Date).AddMinutes(-60))

$ErrorActionPreference= ‘silentlycontinue’
foreach ($server in $servers){
foreach ($eventid in $eventids) {

$events = Get-WinEvent -FilterHashtable @{logname=’security’;id=$eventid;StartTime=$date} -ComputerName $server
if ($events -ne $null){
foreach ($event in $events){
$eventsubject=$eventsubject.replace(“`n”, “”)
$eventsubject=$eventsubject.replace(“`r”, “”)
$body = @($timecreated,$eventmessage )| Out-String
$subject= “Event ID” + ” ” + $eventid + ” ” + $eventsubject
Send-MailMessage -Body $body -From $from -SmtpServer $smtpserver -Subject $subject -To $to


Get-Date | Out-File c:\errorlog.txt -Append -Force
$Error | Out-File c:\errorlog.txt -Append -Force

Failover Clustering, Hyper-V, Powershell

Monitoring Cluster Shared Volume – PowerShell

I have found this but haven't tested yet. I will tweak and use it soon.
#Cluster Shared Volume Free Disk Space
#Emails results of CSV free space on CLUSTER1
#Created 03-08-2011

#Import Failover Cluster PowerShell Module--------------------------------------------------------
Import-Module FailoverClusters

#Begin customization-------------------------
$SmtpServer = "mail.company.com" #Enter FQDN of SMTP server
$SmtpFrom = "CSV Status <CSVFreeSpace@company.com>" #Enter sender email address
$SmtpTo = "you@company.com" #Enter one or more recipient addresses in an array ("abc@company.com","def@company.com")
$SmtpSubject = "CLUSTER1 CSV Free Disk Space Report" #Enter subject of message
#End customization---------------------------

#Get Cluster Shared Volume details and put into array. Convert results from bytes into gigabytes.
$objs = @()

$csvs = Get-ClusterSharedVolume
foreach ( $csv in $csvs )
   $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
   foreach ( $csvinfo in $csvinfos )
      $obj = New-Object PSObject -Property @{
         Name        = $csv.Name
         Path        = $csvinfo.FriendlyVolumeName
         Size        = $csvinfo.Partition.Size
         FreeSpace   = $csvinfo.Partition.FreeSpace
         UsedSpace   = $csvinfo.Partition.UsedSpace
         PercentFree = $csvinfo.Partition.PercentFree
      $objs += $obj

#Original code
#$objs | ft -auto Name,Path,@{ Label = "Size(GB)" ; Expression = { "{0:N2}" -f ($_.Size/1024/1024/1024) } },@{ Label = "FreeSpace(GB)" ; Expression = { "{0:N2}" -f ($_.FreeSpace/1024/1024/1024) } },@{ Label = "UsedSpace(GB)" ; Expression = { "{0:N2}" -f ($_.UsedSpace/1024/1024/1024) } },@{ Label = "PercentFree" ; Expression = { "{0:N2}" -f ($_.PercentFree) } }

#Give a brief description of the output
$output = "The following shows the amount of free space available on the cluster shared volumes on DRSRVVSA."
#Modified code that puts results into a variable and formats results into list format
$output += $objs | fl Name,Path,@{ Label = "Size(GB)" ; Expression = { "{0:N2}" -f ($_.Size/1024/1024/1024) } },@{ Label = "FreeSpace(GB)" ; Expression = { "{0:N2}" -f ($_.FreeSpace/1024/1024/1024) } },@{ Label = "UsedSpace(GB)" ; Expression = { "{0:N2}" -f ($_.UsedSpace/1024/1024/1024) } },@{ Label = "PercentFree" ; Expression = { "{0:N2}" -f ($_.PercentFree) } } | out-string

#Email results
$SmtpClient = New-Object System.Net.Mail.SmtpClient
$MailMessage = New-Object System.Net.Mail.MailMessage
$SmtpClient.Host = $SmtpServer
$MailMessage.From = $SmtpFrom
Foreach ($address in $smtpTo)
$MailMessage.Subject = $SmtpSubject
#$MailMessage.IsBodyHTML = $true
$MailMessage.Body = $output