Screenconnect commandline: Difference between revisions

From SWKLS WIKI
Jump to navigation Jump to search
No edit summary
Line 157: Line 157:
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\NcdAutoSetup\Private" /v "AutoSetup" /t REG_SZ /d "0" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\NcdAutoSetup\Private" /v "AutoSetup" /t REG_SZ /d "0" /f
</syntaxhighlight>
</syntaxhighlight>
==SAM==
Various commands for SAM time & print management software
===SAM Local Server===
====Open port 100====
<syntaxhighlight lang="powershell" line="line">
netsh advfirewall firewall add rule name="SAM10 Port 100" dir=in action=allow protocol=TCP profile=any localport=100
</syntaxhighlight>
====Allow FTP access====
<syntaxhighlight lang="powershell" line="line">
netsh advfirewall firewall add rule name="FTP (no SSL)" action=allow protocol=TCP dir=in profile=any localport=21
netsh advfirewall set global StatefulFtp enable
</syntaxhighlight>
====Stop and Start FTP service====
<syntaxhighlight lang="powershell" line="line">
net stop ftpsvc
net start ftpsvc
</syntaxhighlight>
===SAM Clients===
====Enable / Disable / Show Firewall state (for testing !!!)====
<syntaxhighlight lang="powershell" line="line">
NetSh Advfirewall set allprofiles state off
NetSh Advfirewall set allprofiles state on
Netsh Advfirewall show allprofiles
</syntaxhighlight>
====Set permissions on SAM_10 folder(s)====
<syntaxhighlight lang="powershell" line="line">
icacls "C:\Program Files\SAM_10" /grant Everyone:(OI)(CI)F
icacls "C:\Program Files (x86)\SAM_10" /grant Everyone:(OI)(CI)F
</syntaxhighlight>
====Set permissions on ACM and SAM folder (staff machines or SAM9 clients)====
<syntaxhighlight lang="powershell" line="line">
icacls "C:\ACM" /grant Everyone:(OI)(CI)F
icacls "C:\SAM" /grant Everyone:(OI)(CI)F
</syntaxhighlight>
====Check ACL Permissions on C:\SAM Folder====
<syntaxhighlight lang="powershell" line="line">
#!ps
get-acl c:\sam | format-list
</syntaxhighlight>
====Allow port 2002 TCP traffic====
<syntaxhighlight lang="powershell" line="line">
netsh advfirewall firewall add rule name="SAM Client Port 2002" dir=in action=allow protocol=TCP profile=any localport=2002
</syntaxhighlight>
====Check for Listening Port 2002 on Local Machine====
<syntaxhighlight lang="powershell" line="line">
netstat -a -n
</syntaxhighlight>
====Check for Listening Port 2002 on Local Machine (Powershell 4+)====
<syntaxhighlight lang="powershell" line="line">
#!ps
#timeout=90000
Test-NetConnection -ComputerName localhost -Port 2002
</syntaxhighlight>
====Check for Firewall Rule Port 2002 (Powershell 4+)====
<syntaxhighlight lang="powershell" line="line">
#!ps
#timeout=9000
Get-NetFirewallPortFilter –Protocol TCP | Where { $_.localport –eq ‘2002’ } | Get-NetFirewallRule
</syntaxhighlight>
====Determine if SAM client or SAM printing processes are running====
<syntaxhighlight lang="powershell" line="line">
tasklist /fi "Imagename eq SamClient10.exe"
tasklist /fi "Imagename eq SamPrinting.exe"
</syntaxhighlight>
====Check for existence of themes folder via ScreenConnect CLI====
<syntaxhighlight lang="powershell" line="line">
dir "C:\Program Files\SAM_10\Themes"
</syntaxhighlight>


[[Category:ScreenConnect]]
[[Category:ScreenConnect]]

Revision as of 16:31, 24 July 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

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

Set default printer

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

Remove Printers

printui.exe /dl /n "Fax" /q
printui.exe /dl /n "Microsoft XPS Document Writer" /q
printui.exe /dl /n "Send To OneNote 2016" /q

Add printer port

Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_192.168.24.132 -h 192.168.24.132 -o raw -n 9100

Change printer port

cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs -t -p "Brother HL-2270DW" -r IP_192.168.24.132

Rename printer

cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs -x -p "NPI3AEC0A (HP Color LaserJet CM1312nfi MFP)" -z "HP CM1312"

List print drivers (may truncate)

cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -l

List printer configuration

cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs -g -p "hp LaserJet 1300 PCL 5"

Clear print queue

net stop spooler
del %systemroot%\System32\spool\printers\* /Q /F /S
net start spooler
Find printers with WSD port
wmic printer where "PortName LIKE 'WSD%%'" get name,portname

Delete printers with WSD port

wmic printer where "PortName LIKE 'WSD%%'" delete

Disable Auto Install of Network Devices (WSD Printer Ports, etc.)

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\NcdAutoSetup\Private" /v "AutoSetup" /t REG_SZ /d "0" /f

SAM

Various commands for SAM time & print management software

SAM Local Server

Open port 100

netsh advfirewall firewall add rule name="SAM10 Port 100" dir=in action=allow protocol=TCP profile=any localport=100

Allow FTP access

netsh advfirewall firewall add rule name="FTP (no SSL)" action=allow protocol=TCP dir=in profile=any localport=21
netsh advfirewall set global StatefulFtp enable

Stop and Start FTP service

net stop ftpsvc
net start ftpsvc

SAM Clients

Enable / Disable / Show Firewall state (for testing !!!)

NetSh Advfirewall set allprofiles state off
NetSh Advfirewall set allprofiles state on
Netsh Advfirewall show allprofiles

Set permissions on SAM_10 folder(s)

icacls "C:\Program Files\SAM_10" /grant Everyone:(OI)(CI)F
icacls "C:\Program Files (x86)\SAM_10" /grant Everyone:(OI)(CI)F

Set permissions on ACM and SAM folder (staff machines or SAM9 clients)

icacls "C:\ACM" /grant Everyone:(OI)(CI)F
icacls "C:\SAM" /grant Everyone:(OI)(CI)F

Check ACL Permissions on C:\SAM Folder

#!ps
get-acl c:\sam | format-list


Allow port 2002 TCP traffic

netsh advfirewall firewall add rule name="SAM Client Port 2002" dir=in action=allow protocol=TCP profile=any localport=2002

Check for Listening Port 2002 on Local Machine

netstat -a -n

Check for Listening Port 2002 on Local Machine (Powershell 4+)

#!ps
#timeout=90000
Test-NetConnection -ComputerName localhost -Port 2002

Check for Firewall Rule Port 2002 (Powershell 4+)

#!ps
#timeout=9000
Get-NetFirewallPortFilter Protocol TCP | Where { $_.localport eq 2002 } | Get-NetFirewallRule

Determine if SAM client or SAM printing processes are running

tasklist /fi "Imagename eq SamClient10.exe"
tasklist /fi "Imagename eq SamPrinting.exe"

Check for existence of themes folder via ScreenConnect CLI

dir "C:\Program Files\SAM_10\Themes"