I have a powershell script to log in to an RDC. This script introduces the credentials and everything and leaves the virtual machine's desktop ready to use.
I need this script to be executed by another virtual machine from the scheduled tasks, but when the windows task scheduler does not execute this script interactively (that is, it looks like the RDP opens and all this)
Does anyone have any idea how to fix it?
Thank you very much!
Good this is my script:
function AS400_RDP{
param (
[Parameter(Mandatory=$True, Position=0)] [string]$server
)
$server = Resolve-Path $server
[xml]$ConfigFile = Get-Content -Path $server -Encoding UTF8
$Username1 = $ConfigFile.Settings.General.USERNAME
$Password1 = $ConfigFile.Settings.General.PASSWORD
$keyfile = $ConfigFile.Settings.General.KEYFILE
$computerName1 = $ConfigFile.Settings.General.COMPUTERNAME
#Resolvemos las rutas
$KeyFile = Resolve-Path $KeyFile
#Creamos Credenciales
$Username = "$Username1"
$Password = "$Password1"
$computerName = "$computerName1"
#Creamos el objeto PSCredential
$key = Get-Content $KeyFile
$credential = New-Object -TypeName System.Management.Automation.PSCredential '
-ArgumentList $Username, ($Password | ConvertTo-SecureString -Key $key)
#Iniciamos EL RDP
Import-module .\Connect-Mstsc.ps1
Connect-Mstsc -ComputerName $computerName -Credential $credential -w 1024 -h 768
}
AS400_RDP -server C:\Ruta\archivo\XML\CON_DATOS\CONEXION.xml
The other script that matters is this: link
In the XML I pass the ip of the server, the user, the encrypted key, and the path of the .key file to decrypt it