1

I'm trying to open saved RDP session from my "download" folder.

The following command works. However, I would like it to open *.RDP session files which were saved within 1 minute and delete anything older than 2 minutes.

$RDPFile = "$env:USERPROFILE\downloads\Office.rdp"
Invoke-Expression "mstsc.exe /h:850 /w:1000 '$RDPFile'"
1

1 Answer 1

1

The logic should be something like this. Please change the placeholders accordingly:

$path= "Drive:your\path"
$d = [datetime](Get-ItemProperty -Path $path -Name LastWriteTime).lastwritetime
if( (((Get-Date)-$d).TotalMinutes) -le 1)
{
Invoke-Expression "mstsc.exe /h:850 /w:1000 '$RDPFile'"
}
else
{
Remove-Item $path\*.rdp -Force
}

Note: I have not checked the Invoke part since you have already mentioned its working.

Hope it helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. This was very helpful
@Maaran: Accepting the answer would be appreciable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.