Forum / Remote Desktop Manager - Macro/Script/Tools

powershell issues

  • Create an Issue
  • Cancel

Hi,

I'm trying to run the following command on remote hosts:

Get-WmiObject Win32_Service -filter "Startname Like '[^NT Authority|LocalSystem]%' OR Startname Like '%@%'" | select systemname,name,startname

which should print out a list of services that are not running with the default accounts.

if I run this locally on the host it works.

I tried to put this in an embedded script without success. Tried the get-wmiobject in command and the rest in argument without success, also tried get-wmiobject win32_service in the command and the rest in argument. it runs but none of the filters are being applied.

some help would be greatly appreciated.

thanks

Simon

Clock3 yrs

Hello,

What version of RDM are you using?

Which PowerShell entry type are you using to run the Get-WmiObject command?

Best regards,



Érica Poirier

signaturesignature

Clock3 yrs

Hi Erica,

using version 12.0.8.0

I'm using the PowerShell (Remote) type of entry.

this is the powershell error I get when using the embedded script:


Invoke-Command : Missing argument in parameter list.
At line:11 char:15
+ Invoke-Command <<<< -Session $rdm_pssession -ScriptBlock $rdm_script;
+ CategoryInfo : InvalidOperation: (,:String) [Invoke-Command], RuntimeException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.InvokeCommandCommand


after I get the message, I have a PS prompt on the server I'm running it against. If I paste the exact same command I get proper results.

thanks

Clock3 yrs

I would also no mind being able to run the PS locally using -comp $HOST$ argument but I have yet to figure out how to run this against a target entry. The icon does not show up in the entry dashboard like the remote PS one does.

Clock3 yrs

Hello,

Could you please post a print screen of the property dialog of your PowerShell (remote) entry?

Best regards,



Érica Poirier

signaturesignature

Clock3 yrs

sure

Merci !

Capture.PNG
Clock3 yrs

Hello,

I think I have found the problem. I have finally been able to reproduce your issue and fix it on my local computer that is not joined to the domain of the remote host.

I am unable to run the command line from RDM because the remote host is not in the TrustedHost list of my local computer. When you get the error message, if you scroll up, you should get more information about it like the following screen shot. Do you also get the same error message?

image

So, first I have to add this remote computer in my local TrustedHost list with the winrm PowerShell cmdlet.

I have created a PowerShell (Local) entry with the following command line. And the Run as Administrator option must be activated. I run it on the remote host and then run the Get-WmiObject PowerShell entry.

winrm set winrm/config/client ‘@{TrustedHosts="$HOST$"}’

image

Does it help to resolve the issue on your side?

Best regards,



Érica Poirier

signaturesignature

Clock3 yrs

Hi Team,
while trying to import PSModule for RDM getting below error:
PS C:\Users\dl-dvls-svc> Import-Module “${env:ProgramFiles(x86)}\Devolutions\Remote Desktop Manager\RemoteDesktopManager
.PowerShellModule.dll”
Import-Module : The specified module 'C:\Program Files (x86)\Devolutions\Remote Desktop
Manager\RemoteDesktopManager.PowerShellModule.dll' was not loaded because no valid module file was found in any module
directory.
At line:1 char:1
+ Import-Module “${env:ProgramFiles(x86)}\Devolutions\Remote Desktop Manager\Remot ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Program File...ShellModule.dll:String) [Import-Module], FileNot
FoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Clock3 yrs

Hello Aammir,

Does RDM is installed on the computer where you try to load the RDM PowerShell module?

If so, does the RemoteDesktopManager.PowerShellModule.dll file exist in this folder "C:\Program Files (x86)\Devolutions\Remote Desktop
Manager\"?

If the folder doesn't exist, please adapt the path in the Import-Module command to point to the right location.

Best regards,



Érica Poirier

signaturesignature

Clock3 yrs

Erica Poirier wrote:

Hello Aammir,

Does RDM is installed on the computer where you try to load the RDM PowerShell module?

If so, does the RemoteDesktopManager.PowerShellModule.dll file exist in this folder "C:\Program Files (x86)\Devolutions\Remote Desktop
Manager\"?

If the folder doesn't exist, please adapt the path in the Import-Module command to point to the right location.

Best regards,

Yes Erica 'RemoteDesktopManager.PowerShellModule.dll' file exist in the same folder. I think it's talking about 'no valid module file was found in any module
directory.', which should be <modulefile>.PSM1. That file is not present, and I am not sure from where to get it.

Clock3 yrs

Hello,

From an email you sent us today, because you are running RDM 11.7.6.0, the PowerShell module doesn't exist.

Here is the commands you have to use to load the PowerShell snap-in.

$rdmVersion = "11.7.6"

set-alias installutil "$([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())installutil.exe"
installutil "C:\Program Files (x86)\Devolutions\Remote Desktop Manager\RemoteDesktopManager.PowerShell.dll"
if ( (Get-PSSnapin -Name Remote.Desktop.Manager.$rdmVersion -ErrorAction SilentlyContinue) -eq $null ) { Add-PsSnapin Remote.Desktop.Manager.$rdmVersion }

And it is possible that some RDM CdmLets will not work in this version of RDM.

Best regards,



Érica Poirier

signaturesignature

Clock3 yrs

Thanks for instructions Erica.
And you are right, some cmdlets are not working. Still my requirement met for automating the backup schedule of Session.


PS C:\Windows\system32> $sessions = get-rdmsession; $password = read-host -assecurestring "Password" Export-RDMSession
-Path C:\Session_Backup\MyFilename.html -Sessions $sessions -ExportType "HTML" -Password $password
Password: ********


Thanks,
Erica

Clock3 yrs

Hello,

Do you get an error message with this command line?

The Export-RDMSession contains the correct parameters to work in RDM 11.7.6.0. The only thing I see in your command is that a semi-colon is missing between "Password" and Export-RDMSession.

PS C:\Windows\system32> $sessions = get-rdmsession; $password = read-host -assecurestring "Password" Export-RDMSession -Path C:\Session_Backup\MyFilename.html -Sessions $sessions -ExportType "HTML" -Password $password

Best regards,



Érica Poirier

signaturesignature

Clock3 yrs

It was a TYPO. I corrected it and was running without any issues.


$sessions = get-rdmsession; $password = read-host -assecurestring "Password" Export-RDMSession -Path $filename -Sessions $sessions -ExportType "HTML" -Password $password

But the above command is not taking the complete backup, it is taking just the session group, username, domain, and password. I need a command to take complete backup such as app settings, templates, icons, etc.


Please let me know.

Clock3 yrs

Hi Erica,

Fixed it with the below command, but It is not exporting Templates. I tried a lot to get the solution to export templates (shared) but no fix so far.


$enddate = (Get-Date).tostring("yyyyMMdd")
$filenameXML = 'C:\RDM_Backup\' + $enddate + '_RDMSessionBackup.xml'
$sessions = get-rdmsession; $password = read-host -assecurestring "Password" Export-RDMSession -Path $filenameXML -Sessions $sessions -ExportType "XML" -IncludeCredentials -Password $password

I was reading the KB on RDM and found that below details holds the TEMPLATES backup.


The configuration file can be located in different folders depending on certain conditions:

Case
Configuration file location
Installed under "Program Files" or "Program Files (x86)"
"%LocalAppData%\Devolutions\RemoteDesktopManager"
Application running on Terminal Server
"%AppData%\Devolutions\RemoteDesktopManager". This is the roaming profile and avoids multi-user conflicts.
Other
Installation folder


Please let me know If there is any solution to backup Shared Templates.
Ref.: https://forum.devolutions.net/topic2779-folder-location-for-local-templates.aspx

Thanks,

Clock3 yrs

Hello,

The templates are not exported with the RDM CmdLet Export-RDMSession.

You have to use the Get-RDMTemplate and save the content in a XML file.

Here is an example to export the shared templates into an XML file. Please adapt "C:\SharedTemplates.xml" with the correct path and file name.

$templates = Get-RDMTemplate | where {$_.Source -eq "Shared"}
$templates | Export-Clixml "C:\SharedTemplates.xml"

Best regards,



Érica Poirier

signaturesignature

Clock3 yrs

Thanks for your help Erica smile

#Script will backup all the DVLS session and Shared templates


$enddate = (Get-Date).tostring("yyyyMMdd")
$filename = 'C:\RDM_Backup\' + $enddate + '_RDMSessionBackup.xml'


#forHTML
#$filename = 'C:\RDM_Backup\' + $enddate + '_RDMSessionBackup.html'


$TemplateBackup = 'C:\RDM_Backup\' + $enddate + '_RDMSharedTemplateBackup.xml'

$password = "P@$$W0rd"
$password = $password | ConvertTo-SecureString -Force -AsPlainText

#html
#$sessions = get-rdmsession; $password = read-host -assecurestring "Password" Export-RDMSession -Path 'C:\RDM_Backup\'$filename -Sessions $sessions -ExportType "HTML" -Password $password

#xml
$sessions = get-rdmsession; Export-RDMSession -Path $filename -Sessions $sessions -ExportType "XML" -IncludeCredentials -Password $password


#Templates backup
$templates = Get-RDMTemplate | where {$_.Source -eq "Shared"}
$templates | Export-Clixml $TemplateBackup

Schedule the script to run weekly. Let me know If anything else apart from SQL DB needs to be backed-up

Clock3 yrs