Screenconnect commandline: Difference between revisions

From SWKLS WIKI
Jump to navigation Jump to search
No edit summary
No edit summary
Line 56: Line 56:
</syntaxhighlight>
</syntaxhighlight>


==File Downloads==
==File Downloads & Creation==
===Download a file to a directory (full paths required)===
===Download a file to a directory (full paths required)===
<syntaxhighlight lang="powershell" line="line">
<syntaxhighlight lang="powershell" line="line">
Line 70: Line 70:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(new-object System.Net.WebClient).Downloadfile("http://myurl.com/large.zip", "C:\temp\large.zip")
(new-object System.Net.WebClient).Downloadfile("http://myurl.com/large.zip", "C:\temp\large.zip")
</syntaxhighlight>
===Create a file and write contents===
<syntaxhighlight lang="powershell" line="line">
#!ps
new-item c:\users\director\Desktop\login.txt
set-content c:\users\director\Desktop\login.txt 'myaccount@readinks.info mysecretpassword'
</syntaxhighlight>
</syntaxhighlight>



Revision as of 17:29, 8 June 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 & Creation

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")

Create a file and write contents

#!ps
new-item c:\users\director\Desktop\login.txt
set-content c:\users\director\Desktop\login.txt 'myaccount@readinks.info mysecretpassword'

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()