Screenconnect commandline: Difference between revisions

From SWKLS WIKI
Jump to navigation Jump to search
No edit summary
Line 25: Line 25:
<syntaxhighlight lang="powershell" line='line'>Set-ExecutionPolicy RemoteSigned</syntaxhighlight>
<syntaxhighlight lang="powershell" line='line'>Set-ExecutionPolicy RemoteSigned</syntaxhighlight>


==Show Processes Names Like X==
==Processes and Services==
<syntaxhighlight lang="powershell" line="line">Get-Process sam* | Select-object name</syntaxhighlight>
===Show Processes Names Like X===
<syntaxhighlight lang="powershell" line="line">
#!ps
Get-Process sam* | Select-object name
</syntaxhighlight>


==Test if Service is Running==
===Test if Service is Running===
<syntaxhighlight lang="powershell" line="line">(Get-Service -Name 'Spooler').Status -eq 'Running'</syntaxhighlight>
<syntaxhighlight lang="powershell" line="line">
#!ps
(Get-Service -Name 'Spooler').Status -eq 'Running'
</syntaxhighlight>


==Show Drives and Space Usage==
==Show Drives and Space Usage==
<syntaxhighlight lang="powershell" line="line">get-psdrive -psprovider filesystem</syntaxhighlight>
<syntaxhighlight lang="powershell" line="line">
#!ps
get-psdrive -psprovider filesystem
</syntaxhighlight>


==Shortcuts==
==Create a Desktop shortcut to a folder==
==Create a Desktop shortcut to a folder==
<syntaxhighlight lang="powershell" line="line">
<syntaxhighlight lang="powershell" line="line">
#!ps
$TargetFile = "C:\scan\"
$TargetFile = "C:\scan\"
$ShortcutFile = "$env:Public\Desktop\folder.lnk"
$ShortcutFile = "$env:Public\Desktop\folder.lnk"
Line 42: Line 54:
$Shortcut.TargetPath = $TargetFile
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
$Shortcut.Save()
</syntaxhighlight>
===File Downloads===
==Download a file to a directory (full paths required)==
<syntaxhighlight lang="powershell" line="line">
#!ps
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(new-object System.Net.WebClient).Downloadfile("http://myurl.com/somefile.jpg", "C:\Users\bob\Desktop\somefile.jpg")
</syntaxhighlight>
==Download a large file to a directory (full paths required)==
<syntaxhighlight lang="powershell" line="line">
#!ps
#timeout=9000000
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(new-object System.Net.WebClient).Downloadfile("http://myurl.com/large.zip", "C:\temp\large.zip")
</syntaxhighlight>
==Time==
===See Current Timezone===
<syntaxhighlight lang="powershell" line="line">
#!ps
[System.TimeZone]::CurrentTimeZone
</syntaxhighlight>
==Hyper-V==
===List Hyper-V VMs and file paths===
<syntaxhighlight lang="powershell" line="line">
#!ps
#timeout=90000
get-vm | Get-VMHardDiskDrive | select vmname, path
</syntaxhighlight>
==Printers==
===Show default printer===
<syntaxhighlight lang="powershell" line="line">
Get-WmiObject -Query "SELECT * FROM Win32_Printer WHERE Default=$true"
</syntaxhighlight>
===Set default printer===
<syntaxhighlight lang="powershell" line="line">
(Get-WmiObject -ComputerName . -Class Win32_Printer -Filter "Name='HP Color LaserJet Pro MFP M477 PCL 6'").SetDefaultPrinter()
</syntaxhighlight>
</syntaxhighlight>



Revision as of 20:46, 13 March 2020

CLI Notes

Running Commands

There exist a few ways to issue CLI commands in ScreenConnect / Connectwise Control.

  • Right-Clicking on a session and choosing 'Run Command'
  • Clicking on the 'Commands' icon in the right-hand panel
  • Right-Clicking on a session, selecting 'Join With Options' and then selecting 'Backstage'

Normal (CMD) style commands do not require anything other than the command itself to be issued. Powershell commands require being prefaced with one of the two listed examples:

  • #!ps
  • powershell

Timeouts

Commands may time out if running for too long. The default time-out value can be overridden by using

#timout=90000

replacing 90000 with the desired interval.

Truncated Output

The output from a command may be truncated, but can be extended by overriding the default using

#maxlength=1000000

replacing 1000000 with desired output length.

Example of Options

#!ps
#timeout=90000
Get-Process sam* | Select-object name

Enable Remote Execution

Set-ExecutionPolicy RemoteSigned

Processes and Services

Show Processes Names Like X

#!ps
Get-Process sam* | Select-object name

Test if Service is Running

#!ps
(Get-Service -Name 'Spooler').Status -eq 'Running'

Show Drives and Space Usage

#!ps
get-psdrive -psprovider filesystem

Shortcuts

Create a Desktop shortcut to a folder

#!ps
$TargetFile = "C:\scan\"
$ShortcutFile = "$env:Public\Desktop\folder.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

File Downloads

Download a file to a directory (full paths required)

#!ps
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(new-object System.Net.WebClient).Downloadfile("http://myurl.com/somefile.jpg", "C:\Users\bob\Desktop\somefile.jpg")

Download a large file to a directory (full paths required)

#!ps
#timeout=9000000
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(new-object System.Net.WebClient).Downloadfile("http://myurl.com/large.zip", "C:\temp\large.zip")

Time

See Current Timezone

#!ps
[System.TimeZone]::CurrentTimeZone

Hyper-V

List Hyper-V VMs and file paths

#!ps
#timeout=90000
get-vm | Get-VMHardDiskDrive | select vmname, path

Printers

Show default printer

Get-WmiObject -Query "SELECT * FROM Win32_Printer WHERE Default=$true"

Set default printer

(Get-WmiObject -ComputerName . -Class Win32_Printer -Filter "Name='HP Color LaserJet Pro MFP M477 PCL 6'").SetDefaultPrinter()