Skip to content

Instantly share code, notes, and snippets.

@techdecline
Created April 17, 2019 07:53
Show Gist options
  • Select an option

  • Save techdecline/b851826984f5d1c7911e06fe81dd4a3b to your computer and use it in GitHub Desktop.

Select an option

Save techdecline/b851826984f5d1c7911e06fe81dd4a3b to your computer and use it in GitHub Desktop.
# Get all Farm Session Hosts
$sessionHostArr = Get-RDSessionCollection -ConnectionBroker rds-cb1.rds.lab | Get-RDSessionHost
foreach ($sessionHost in $sessionHostArr) {
$serverName = $sessionHost.SessionHost
Write-Verbose "Current Object is: $($sessionHost.SessionHost)"
# Test on SMB Protocol
if (-not (Test-NetConnection -ComputerName $serverName -Port 445)) {
# Test if target is online
if (-not (Test-WSMan $serverName)) {
Write-Warning "Connectivity Check failed for: $serverName"
continue
}
else {
# Remotely enable SMB Firewall Rules
Invoke-Command -ComputerName $serverName -ScriptBlock {
Enable-NetFirewallRule -DisplayGroup "File and Printer Sharing"
}
}
}
Copy-Item C:\cb.pfx -Destination "\\$serverName\c$\cb.pfx"
Invoke-Command -ComputerName $serverName -ScriptBlock {
$securePassword = ConvertTo-SecureString -AsPlainText -Force "Passw0rd"
Import-PfxCertificate -Exportable -CertStoreLocation Cert:\LocalMachine\My `
-FilePath C:\cb.pfx -Password $securePassword
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment