Tuesday, March 31, 2026

A powershell script to update rustdesk in action 1

For maintaining remote access for our IT systems we use a mix of action1 and rustdesk.  Though action1 has a very good remote web interface it can be slow at times.  I've setup a rustdesk server for additional security.  Below is a powershell script that I created.  

The script creates a folder for downloading rustdesk from github; and if it isn't there create it, download and install.  There is a else where if it is installed, uninstall rustdesk then create the install directory and install the latest version.


$Folder = 'c:\#NAMEOFFOLDER'

"Test to see if folder [$Folder]  exists"

if (Test-Path -Path $Folder) {

Remove-Item -Recurse -Force c:\#NAMEOFFOLDER\*.*

Remove-Item 'c:\#NAMEOFFOLDER'

Get-CimInstance -ClassName win32_product | Where-Object Name -Match "RustDesk" | 

    ForEach-Object -Process { 

        Invoke-CimMethod -InputObject $_ -Name Uninstall 

                            }

New-Item -Path "c:\" -Name "#NAMEOFFOLDER" -ItemType "directory"

Invoke-WebRequest https://github.com/rustdesk/rustdesk/releases/download/1.4.6/rustdesk-1.4.6-x86_64.msi -OutFile c:\saplit\rustdesk-1.4.0-x86_64.msi

$pkg = "c:\#NAMEOFFOLDER\rustdesk-1.4.0-x86_64.msi";

Start-Process msiexec "/i $pkg /norestart /qn" -Wait;

##Start-Process msiexec "/i $pkg /qn" -Wait;

##Start-Process msiexec "/i $pkg /norestart /qn" -Wait;

Start-Sleep -Seconds 30

Remove-Item -Recurse -Force c:\#NAMEOFFOLDER\*.*

Remove-Item 'c:\#NAMEOFFOLDER'


} else {

#uninstall rustdesk

Get-CimInstance -ClassName win32_product | Where-Object Name -Match "RustDesk" | 

    ForEach-Object -Process { 

        Invoke-CimMethod -InputObject $_ -Name Uninstall 

                            }

New-Item -Path "c:\" -Name "#NAMEOFFOLDER" -ItemType "directory"

Invoke-WebRequest https://github.com/rustdesk/rustdesk/releases/download/1.4.6/rustdesk-1.4.6-x86_64.msi -OutFile c:\saplit\rustdesk-1.4.0-x86_64.msi

$pkg = "c:\#NAMEOFFOLDER\rustdesk-1.4.0-x86_64.msi";

Start-Process msiexec "/i $pkg /norestart /qn" -Wait;

##Start-Process msiexec "/i $pkg /qn" -Wait;

##Start-Process msiexec "/i $pkg /norestart /qn" -Wait;

Start-Sleep -Seconds 30

Remove-Item -Recurse -Force c:\#NAMEOFFOLDER\*.*

Remove-Item 'c:\#NAMEOFFOLDER'

}

Monday, March 30, 2026

Removing a VM from Hyper-V High Availability cluster

 To remove a virtual machine from a Hyper-V High Availability cluster is really relatively trivial, so long as you don't have any system on the cluster in failover, you right click on the role and click remove



You will then be prompted; asking if you want to remove the role and you select YES.


Then the system is removed from the cluster and is operating on the host the VM was assigned to run to.




Wednesday, March 11, 2026

Automating SQL Data Dump and SFTP File Transfer with Powershell and WinSCP on Windows



We work with a third party that takes care of a few systems for us that we automated and to make that work we had to script an automated process to export data from our SQL server and automatically upload it to an SFTP Server.

For this setup we are using WINSCP for doing the file transfer and a combination of a bat file and powershell for exporting the data out of SQL and automating the process.  I am using windows for automating this process.

What will be required:



So install powershell and WINSCP on to the system.  

Open powershell as and administrator and install the Clobber the WINSCP Module and the SQLServer module

Install-Module -Name PowershellGet
Install-Module -Name SQLServer
Install-Module -Name WinSCP

Once done we will make two files, they will be running from the same directory.
SQLDataExport.ps1 and gen_sql_data.bat
The powershell file is fairly straight forward. It essentially gets and runs the sql query and saves it to a directory as a txt or csv.

SQLDataExport.ps1

$serverInstance = "$address, $port" 
$databaseName = "$databaseName" 
$Username = "$databaseUser" 
 $Password = "$databasePassword" 
$filePath = "$PATH\$FILENAME" + (Get-Date).ToString("yyyyMMddTHHmmss") + ".txt" 

Import-Module SqlServer 

$sqlQuery = "$YOURSQLQUERY" 

Invoke-Sqlcmd -ServerInstance $serverInstance -Username $Username -Password $Password -Database $databaseName -TrustServerCertificate -Query $sqlQuery | Out-File $filePath -Encoding UTF8


BatFile (This is where all the FTP Magic happens)

@ECHO OFF
powershell.exe -executionpolicy remotesigned -File $PATHTOPOWERSHELLSCRIPT.ps1

timeout /t 120

echo "FTP Started" >> seed_exReport.rpt
date /t >> exReport.rpt
time /t >> exReport.rpt
echo option batch abort > ftpPutCmds.txt
echo option confirm off >> ftpPutCmds.txt


echo open sftp://$USERNAME@$SFTPURL -privatekey=$SFTPPRIVATEKEY.ppk -passphrase=$PASSWORD -hostkey=acceptnew >> ftpPutCommands.txt
echo option transfer binary >> ftpPutCmds.txt
echo cd seed >> ftpPutCmds.txt
echo put $SQLDATA_*.txt >> ftpPutCmds.txt
echo close >> ftpPutCmds.txt
echo exit >> ftpPutCmds.txt


"C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /script=ftpPutCmds.txt /log="$PATH2Error.log" /loglevel=1* /logsize=5*100M
echo "FTP Finished" >> seed_exReport.rpt
IF EXIST *.txt (move *SQLDATA_*.txt Old\) REM move old file to a folder called old
date /t >> exReport.rpt
time /t >> exReport.rpt
echo. >> exReport.rpt

Once done you can setup the task scheduler to run the batfile.  You will need the script to start in the directory that the bat file and powershell file are in.

Upgrading Windows 11 From 23H2 to 25H2

 I had a heck of a time upgrading my Windows 11 Pro System from 23H2 to 25H2 and I really did not want to do a clean install.  I really shou...