ConnectWise Control Remote Powershell Commands

Welcome to the ConnectWise Control Remote Powershell Commands. They are my go to remote commands. Some commands will need extra configuration or tweaking depending on your environment. The others are cut and paste. Enjoy!

PowerShell & Command Prompt Commands

The commands are either PowerShell (#!ps) or Command Prompt (#!cmd) commands. There are a couple attributes that affect how the commands respond.

#MaxLength - The max length of output characters. Some may need to be larger due to amount of output data.
#TimeOut - The period of time the command can run and will be terminated after the max has been hit. Most commands are quick to respond.

SUCCESS or FAILURE
The Command Prompt commands should work fine however the PowerShell commands may fail due to the set level of running commands remote.
"ps cannot be loaded because the execution of scripts is disabled or restricted on this system."
Let's set the execution policy.

Set Execution Policy

#!ps
#maxlength=50000
#timeout=9000000
Set-ExecutionPolicy Unrestricted

Show System Information

syteminfo

List Performance Data

#!ps
#maxlength=50000
#timeout=9000000
Get-Counter

List Event Log Data

Application Log
#!ps
#maxlength=500000
#timeout=900000
Get-EventLog -Log "Application"

 
System Log
#!ps
#maxlength=500000
#timeout=900000
Get-EventLog -Log "System"

 
Attributes
-Newest X (number of events.)
#!ps
#maxlength=500000
#timeout=900000
Get-EventLog -Log "Application" -Newest 100

 
Find unique ID
#!ps
#maxlength=500000
#timeout=900000
Get-EventLog -LogName Application -InstanceId <id #>

Run SFC Scan

#!ps
#maxlength=50000
#timeout=9000000
sfc /scannow

Run DISM

#!ps
#maxlength=50000
#timeout=9000000
dism /online /cleanup-image /restorehealth

Find Last OS Reboot Time

#!ps
#maxlength=50000
#timeout=9000000
wmic path Win32_OperatingSystem get LastBootUpTime

Check Power Settings

#!ps
#maxlength=50000
#timeout=9000000
powercfg -query

Disable Hibernation and Set Power Settings

#!ps
#maxlength=50000
#timeout=9000000
powercfg.exe /h off
powercfg /x -disk-timeout-ac 0
powercfg /x -disk-timeout-dc 0
powercfg /x -monitor-timeout-ac 30
powercfg /x -monitor-timeout-dc 30
Powercfg /x -standby-timeout-ac 0
powercfg /x -standby-timeout-dc 0
powercfg /x -hibernate-timeout-ac 0
powercfg /x -hibernate-timeout-dc 0

Find Hard Drive Information

#!ps
#maxlength=50000
#timeout=9000000
wmic logicaldisk get size,freespace,caption

Old School ChkDsk

#!cmd
#maxlength=50000
#timeout=9000000
chkdsk

Empty Recycle Bin

#!ps
#maxlength=50000
#timeout=9000000
Get-ChildItem -Path 'C:\$Recycle.Bin' -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue

Old School Defrag

#!cmd
#maxlength=50000
#timeout=9000000
defrag <drive>:

List Hard Drive Manufacturer Information

#!ps
#maxlength=50000
#timeout=9000000
wmic diskdrive get Name"," Manufacturer"," Model"," InterfaceType"," MediaType"," SerialNumber

List Memory Information

#!ps
#maxlength=50000
#timeout=9000000
wmic MEMORYCHIP get BankLabel,DeviceLocator,MemoryType,TypeDetail,Capacity,Speed

List Memory Capacity

#!ps
#maxlength=50000
#timeout=9000000
Get-WmiObject Win32_PhysicalMemory | Select-Object Capacity

List Process Information by Memory Consumption

#!ps
#maxlength=50000
#timeout=9000000
Get-Process | Sort-Object -Descending WS

List Printer Information

#!ps
#maxlength=50000
#timeout=9000000
wmic printer list brief

List Printer Drivers

#!ps
#maxlength=50000
#timeout=9000000
Get-PrinterDriver

Restart Printer Spooler

#!ps
#maxlength=50000
#timeout=9000000
Restart-Service -Name Spooler -Force

Restart Services

#!ps
#maxlength=50000
#timeout=9000000
Get-Service
 
Restart-Service -Name <Service> -Force

List HotFix Updates

#!ps
#maxlength=50000
#timeout=9000000
wmic qfe list

Windows Updates

#!ps
#maxlength=50000
#timeout=9000000
Install-Module PSWindowsUpdate -Force
 
Get the updates
#!ps
#maxlength=50000
#timeout=9000000
Get-WindowsUpdate
 
Category (-NotCategory);
Title (-NotCategory);
Update number (-NotKBArticleID)
 
EX: Get-WindowsUpdate -NotCategory "Drivers"
 
Install Updates
#!ps
#maxlength=50000
#timeout=9000000
Install-WindowsUpdate -AcceptAll -MicrosoftUpdate -AutoReboot
 
Client restart behavior:
AutoReboot: automatically reboots system if required
IgnoreReboot: suppresses automatic restarts
ScheduleReboot: specifies the date when the system will be rebooted.
 
EX: Install-WindowsUpdate -AcceptAll -MicrosoftUpdate -ScheduleReboot 20:00
 
Old School Update
#!cmd
#maxlength=50000
#timeout=9000000
wuauclt /detectnow /updatenow
 
If you get this error running the PS scripts. Run the commands below.
---- Exception calling "ShouldContinue" with "2" argument(s): "Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available." At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7455 char:8 + if($Force -or $psCmdlet.ShouldContinue($shouldContinueQueryMessag ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : PSInvalidOperationException Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed. At C:\Windows\TEMP\ScreenConnect\19.3.25270.7185\12666585-634d-4922-82d3-063a0c99dcdbrun.ps1:1 char:1 + Install-Module PSWindowsUpdate -Force -Confirm:$false + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Install-Module], InvalidOperationException + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module
----
 
#!ps
#maxlength=500000
#timeout=900000
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force
 
#!ps
#maxlength=500000
#timeout=900000
Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201

Remove Software

#!ps
#maxlength=50000
#timeout=9000000
wmic product get name
 
Remove the product
#!ps
#maxlength=500000
#timeout=900000
get-package '*<software>*' | uninstall-package

Kill Process

#!ps
#maxlength=50000
#timeout=9000000
get-process
 
Kill the process.
#!ps
#maxlength=500000
#timeout=900000
stop-process -id <id #> -force

List Plug and Play Devices

#!ps
#maxlength=50000
#timeout=9000000
Get-PnpDevice

List USB Devices

#!ps
#maxlength=50000
#timeout=9000000
Get-PnpDevice -FriendlyName '*USB*'

List PNP Error Devices

#!ps
#maxlength=50000
#timeout=9000000
Get-PnpDevice -PresentOnly -Status ERROR,DEGRADED,UNKNOWN

IP Release and Renew

ipconfig /release && ipconfig /renew

Reboot

shutdown /r /t 30
 
/r - reboot
/t 30 - timeout period

Turn Off Firewall

netsh advfirewall firewall set rule group="Network Discovery" new enable=Yes
NetSh Advfirewall set allprofiles state off

Force Group Policy

#!ps
#maxlength=50000
#timeout=9000000
gpupdate /force

Server Azure Delta Sync

#!ps
#maxlength=50000
#timeout=9000000
Start-ADSyncSyncCycle -PolicyType Delta

Add Local Azure User As Admin

net localgroup administrators /add "AzureAD\UserUpn"

Make Workstation Speak

#!ps
#maxlength=50000
#timeout=9000000
powershell Add-Type -AssemblyName System.speech; $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer; $speak.Speak('Help me, I am stuck')

Conclusion

There you go! These are the remote commands that help me with my day to day MSP life.


Questions, comments, want to point out errors or just want to say Hi? Please fill out the contact form below.

4/22/2021 - ConnectWise Control Remote PowerShell Commands
4/25/2021 - ConnectWise Control Remote PowerShell Commands PT 2

First Name:

About Wade

I am dedicated and accomplished application developer and multi-hat information system administrator and manager. Extensive background with the full lifecycle of hardware with systems, devices, networks, databases and software development while ensuring optimal performance.
 
WadeBach.com

Last Name:
Email:
Message: