OK, so a few things to debug here…
But before I do I’d recommend you do a little more customising of the script so it is more re-usable for future releases
I’ve noticed you have not defined any of the Variables in this section:
##*===============================================
##* VARIABLE DECLARATION
##*===============================================
## Variables: Application
[String]$appVendor = ''
[String]$appName = ''
[String]$appVersion = ''
[String]$appArch = ''
[String]$appLang = 'EN'
[String]$appRevision = '01'
[String]$appScriptVersion = '1.0.0'
[String]$appScriptDate = 'XX/XX/20XX'
[String]$appScriptAuthor = '<author name>'
##*===============================================
Although these settings are not entirely required it does make the dialogs and log file names a lot clearer and the populated details are useful as they can easily be presented to your users in the various PSADT dialogs
If I may be so bold I’d suggest:
##*===============================================
##* VARIABLE DECLARATION
##*===============================================
## Variables: Application
[String]$appVendor = 'Purslane Ltd'
[String]$appName = 'Rustdesk'
[String]$appVersion = '1.2.3'
[String]$appArch = 'x64'
[String]$appLang = 'EN'
[String]$appRevision = '01'
[String]$appScriptVersion = '1.0.0'
[String]$appScriptDate = '19/10/2023'
[String]$appScriptAuthor = 'Your Name'
##*===============================================
‘Assuming’ the installers are always available using the same naming convention, “rustdesk-1.2.3-x86_64.exe”, “rustdesk-1.2.4-x86_64.exe”, “rustdesk-1.3.0-x86_64.exe” etc. The above would also be useful for reducing the modifications you need to make to the script, so on the Install and Uninstall commands, you could replace the version number with $($appVersion). You could also use this info to inject into you RDD.txt file.
e.g. Install:
Execute-Process -Path "rustdesk-$($appVersion)-x86_64.exe" -Parameters "--silent-install" -PassThru -CreateNoWindow
Uninstall:
Execute-Process -CreateNoWindow -Path "rustdesk-$($appVersion)-x86_64.exe" -Parameters "--uninstall"
Add to text file (Note change of quotes)
Set-Content C:\Temp\RustDesk\RDD.txt "This file is for SCCM Detection only for $($appName) Version: $($appVersion)." -ErrorAction SilentlyContinue -Force
So, on to the debugging…
I am not completely familiar with the settings in SCCM (I use Intune), but in which context is your deployment set to install as - System or as the user?
If being deployed as the user, do your users have admin rights on their machines? (N.B. Definitely NOT security best practice!)
Because if it is installed as the user and they do not have admin rights:
New-Item -Path 'C:\Temp\RustDesk' -ItemType Directory -ErrorAction SilentlyContinue -Force
They may not have permission to create the C:\Temp\RustDesk
folder (they may not by default have the rights to create folders off the root of C:\
), They may also be unable create or modify the RDD.txt
file.
Also, by having the -ErrorAction SilentlyContinue
parameter set you will not know whether it has succeded or failed, plus, because you are using native PowerShell commands New-Item
& Set-Content
these events would not be logged to the PSADT log file, @That-Annoying-Guy wrote a good explanation how to log non-PSADT commands to the PSADT log file:
It might be worth reviewing this advice and adjusting your script.
I am going to assume you need to run this deployment as system because in your uninstall commands only the first command would likely work if it was running as a user without admin priviledges
Start-Sleep -seconds 2
Remove-Item -Path "C:\Users\$Env:UserName\AppData\Roaming\RustDesk\" -Recurse -ErrorAction SilentlyContinue -Force
Start-Sleep -seconds 2
Remove-Item -Path "C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\" -Recurse -ErrorAction SilentlyContinue -Force
Start-Sleep -seconds 2
Remove-Item -Path "$env:ProgramFiles\RustDesk\" -Recurse -ErrorAction SilentlyContinue -Force
So the only major question is - in what context is this being installed?
I hope that gives you a start.