Editing an RDP session with Notepad and Powershell

0

This worked for me:

ls "~\desktop\CMR Desktop.rdp" -recurse | %{ (gc $_ ) -replace "session bpp:i:32", "session bpp:i:24" | set-content $_.FullName -force }

Instead of the -replace switch, which one do I use to add or insert new lines to the config file?

Such as:

ls "~\desktop\CMR Desktop.rdp" -recurse | %{
     (gc $_ ) -insert "set audioqualitymode:1:2" |
     set-content $_.FullName -force
}

The -insert or -add doesn't work.

James

Posted 2018-12-14T15:02:12.100

Reputation: 38

Okay with this article https://superuser.com/questions/446211/change-to-home-directory-in-powershell?newreg=22b2fcebb4cf4bfaba791fbe904507b4 i got the error to go away but it doesn't change the displayconectionbar:i:1 to a 0

– James – 2018-12-14T15:08:07.267

1

What are you asking? Please edit the question to make it more clear... in it's current state this question is likely to be closed...

– Attie – 2018-12-14T15:16:49.147

Answers

0

Recurse and looping is redundant as there are no sub folders under a file:

ls "~\desktop\CMR Desktop.rdp" | %{ "set audioqualitymode:1:2" | Out-File $_.FullName -append }

or even easier:

"set audioqualitymode:1:2" | Out-File (ls "~\desktop\CMR Desktop.rdp") -append

You need to use append. Set-Content or using Out-File without the append parameter will completely overwrite the file with JUST the text in the quotes.

thepip3r

Posted 2018-12-14T15:02:12.100

Reputation: 281

It did add the content i wanted but i put looks like this s e t a u d i o q u a l i t y m o d e : 1 : 2 I don't know if that will work. It has a lot of spaces – James – 2018-12-14T16:44:05.260

Is there another way or how can i take out the spaces? – James – 2018-12-14T17:05:01.787

Add, '-encoding ASCII' after the -append. the file your're editing apparently expects unicode. – thepip3r – 2018-12-14T17:07:08.903

I think you mean this and it worked. ls "~\desktop\CMR Desktop.rdp" | %{ "set audioqualitymode:1:2" | Out-File $_.FullName -append -encoding ASCII} Awesome TNX – James – 2018-12-14T17:11:04.213