Ylianst / MeshCentralRouter

Windows tool that performs TCP/UDP port mapping thru the MeshCentral server
https://meshcentral.com
Apache License 2.0
57 stars 39 forks source link

Script for automapping of a port #37

Open ddkooker2 opened 2 years ago

ddkooker2 commented 2 years ago

Goodday,

I hope someone can help me with an issue that i am having with the MeshCentralRouter. What i am trying to script (with powershell) is a mapping of a RDP connection without the need for entering a password when it is run. This coudl then also be used to auto-map a port for specific functions or monitoring when there is no vpn access to a location.

Whitin Powershell I use the ConvertFrom-SecureString to save a password file in my script directory and a ConvertTo-SecureString to read it back into a variable to be used when connecting to Meshcentral.

but when i run the script somehow the router does not recognize my password. It looks like it cannot read it form a secure powershell string? Is there a way to fix/work around this or how would you advise me to do this.

My script so far: (I removed my personal information for privacy) `

This script is used for setting up a remote desktop connection with MeshCentral Router.

Use the command below to generate the password file in the folder (Place this together with this script)

Variables

Set-Location -Path $PSScriptRoot $hostname = "mesh.example.com" $username = "danny@example.com"

Password

if (!(Test-Path .\Password.txt)) {
    ECHO "ERROR: Password file is not generated... Generating file"
    Read-Host "Enter Meshcentral Password" -AsSecureString | ConvertFrom-SecureString | Out-File ".\Password.txt"
    $password = Get-Content ".\Password.txt" | ConvertTo-SecureString
}
else {
    $password = Get-Content ".\Password.txt" | ConvertTo-SecureString
}

$password

Start the connection to the MeshCentral server

if (!(Test-Path .\MeshCentralRouter.exe)) { ECHO "Error: MeshCentralRouter.exe was not found. Please download the application from the Meshcentral server before conecting" BREAK } .\MeshCentralRouter.exe -debug -host:$hostname -user:$username -pass:$password `