This appears to work well. It uses the olde ‘rwinsta’ command to work around some Powershell oddities.
# Get list of disconnected RDP sessions
$RDPDiscSessions = Get-RDUserSession | Where-Object SessionState -eq STATE_DISCONNECTED
# Disconnect each of them one by one
foreach ($row in $RDPDiscSessions) {
'Logging off ' + $row.SessionID
rwinsta $row.SessionID
}
An in-script fix:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
A permanent fix:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
To download a single file in binary mode, try translating this:
Invoke-WebRequest -Uri "http://fq.dn/sub/binary.exe" -Outfile "C:\folder\binary.exe"
Prefix this, add a space to the end, and then type your Powershell:
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command
My current favorite way:
[string]$PSVersionTable.PSVersion.Major + '.' + [string]$PSVersionTable.PSVersion.Minor
If it’s 1.0, you’ll get an error, otherwise you will have what you need.
If you place a tilde (~) before the command you enter, no space after, your command will be run within Powershell. For instance:
~dir
“The PowerShell Gallery is the central repository for PowerShell content. You can find new PowerShell commands or Desired State Configuration (DSC) resources in the Gallery.”
http://www.powershellgallery.com/
As part of Windows Management Framework 5.1. Not indicated for Windows 10 / Server 2016.
https://www.microsoft.com/en-us/download/details.aspx?id=54616