Opening multiple rdp sessions with powershell












0















I'm trying to get multiple RDP session opening using a Powershell Script, i'm opening the sessions for the first time, to check if everything is ok and apply the Redirect Folder Stategy.



Here is the Powershell script i'm using (copied from a forum and modified a bit):



# Comma separated list: Computer,User,Password
$listRaw = Get-Content -Path C:FolderScriptRDP.txt

# Parse CSV list
$list = $listRaw | ConvertFrom-CSV -Delimiter ','

# Iterate targets
foreach ($target in $list) {
Write-Host "Connecting to $($target.Computer) as $($target.User)"

# Creating credential from username and password
$SecurePassword = $target.Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $target.User, $SecurePassword

# Creating remote session to that computer
# Using given credentials
$session = New-PSSession -ComputerName $target.Computer -Credential $Credentials
}


I'm getting this error :



C:FolderScriptrdp.ps1:17 : 16
+ ... $session = New-PSSession -ComputerName $target.Computer -Credential ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : ServerNotTrusted,PSSessionOpenFailed


And saying that somehow the server does not belong to Trusted Hosts, but i'm using the script on the Remote Desktop Server itself... I dont understand how it cannot trust itself...



I'm sorry as my knowledge in powershell is limited, i wanted to try it out instead of opening each session manually, which can be boring... I may have made an obvious mistake, but i couldnt find answers looking up for this error... And i don't know what else to look for...



Thanks for any help provided !



Cheers



Jean.



PS: Please feel free to report any grammar mistakes, english is not a language i am fluent in...










share|improve this question




















  • 2





    New-PSSession doesn't use RDP - it is a non-interactive console session and has no GUI.

    – James C.
    Nov 22 '18 at 10:17













  • Have a look at Connect-Mstsc

    – Theo
    Nov 22 '18 at 10:35











  • Possible solution: stackoverflow.com/a/11795149/2208505

    – James C.
    Nov 22 '18 at 10:38


















0















I'm trying to get multiple RDP session opening using a Powershell Script, i'm opening the sessions for the first time, to check if everything is ok and apply the Redirect Folder Stategy.



Here is the Powershell script i'm using (copied from a forum and modified a bit):



# Comma separated list: Computer,User,Password
$listRaw = Get-Content -Path C:FolderScriptRDP.txt

# Parse CSV list
$list = $listRaw | ConvertFrom-CSV -Delimiter ','

# Iterate targets
foreach ($target in $list) {
Write-Host "Connecting to $($target.Computer) as $($target.User)"

# Creating credential from username and password
$SecurePassword = $target.Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $target.User, $SecurePassword

# Creating remote session to that computer
# Using given credentials
$session = New-PSSession -ComputerName $target.Computer -Credential $Credentials
}


I'm getting this error :



C:FolderScriptrdp.ps1:17 : 16
+ ... $session = New-PSSession -ComputerName $target.Computer -Credential ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : ServerNotTrusted,PSSessionOpenFailed


And saying that somehow the server does not belong to Trusted Hosts, but i'm using the script on the Remote Desktop Server itself... I dont understand how it cannot trust itself...



I'm sorry as my knowledge in powershell is limited, i wanted to try it out instead of opening each session manually, which can be boring... I may have made an obvious mistake, but i couldnt find answers looking up for this error... And i don't know what else to look for...



Thanks for any help provided !



Cheers



Jean.



PS: Please feel free to report any grammar mistakes, english is not a language i am fluent in...










share|improve this question




















  • 2





    New-PSSession doesn't use RDP - it is a non-interactive console session and has no GUI.

    – James C.
    Nov 22 '18 at 10:17













  • Have a look at Connect-Mstsc

    – Theo
    Nov 22 '18 at 10:35











  • Possible solution: stackoverflow.com/a/11795149/2208505

    – James C.
    Nov 22 '18 at 10:38
















0












0








0








I'm trying to get multiple RDP session opening using a Powershell Script, i'm opening the sessions for the first time, to check if everything is ok and apply the Redirect Folder Stategy.



Here is the Powershell script i'm using (copied from a forum and modified a bit):



# Comma separated list: Computer,User,Password
$listRaw = Get-Content -Path C:FolderScriptRDP.txt

# Parse CSV list
$list = $listRaw | ConvertFrom-CSV -Delimiter ','

# Iterate targets
foreach ($target in $list) {
Write-Host "Connecting to $($target.Computer) as $($target.User)"

# Creating credential from username and password
$SecurePassword = $target.Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $target.User, $SecurePassword

# Creating remote session to that computer
# Using given credentials
$session = New-PSSession -ComputerName $target.Computer -Credential $Credentials
}


I'm getting this error :



C:FolderScriptrdp.ps1:17 : 16
+ ... $session = New-PSSession -ComputerName $target.Computer -Credential ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : ServerNotTrusted,PSSessionOpenFailed


And saying that somehow the server does not belong to Trusted Hosts, but i'm using the script on the Remote Desktop Server itself... I dont understand how it cannot trust itself...



I'm sorry as my knowledge in powershell is limited, i wanted to try it out instead of opening each session manually, which can be boring... I may have made an obvious mistake, but i couldnt find answers looking up for this error... And i don't know what else to look for...



Thanks for any help provided !



Cheers



Jean.



PS: Please feel free to report any grammar mistakes, english is not a language i am fluent in...










share|improve this question
















I'm trying to get multiple RDP session opening using a Powershell Script, i'm opening the sessions for the first time, to check if everything is ok and apply the Redirect Folder Stategy.



Here is the Powershell script i'm using (copied from a forum and modified a bit):



# Comma separated list: Computer,User,Password
$listRaw = Get-Content -Path C:FolderScriptRDP.txt

# Parse CSV list
$list = $listRaw | ConvertFrom-CSV -Delimiter ','

# Iterate targets
foreach ($target in $list) {
Write-Host "Connecting to $($target.Computer) as $($target.User)"

# Creating credential from username and password
$SecurePassword = $target.Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $target.User, $SecurePassword

# Creating remote session to that computer
# Using given credentials
$session = New-PSSession -ComputerName $target.Computer -Credential $Credentials
}


I'm getting this error :



C:FolderScriptrdp.ps1:17 : 16
+ ... $session = New-PSSession -ComputerName $target.Computer -Credential ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : ServerNotTrusted,PSSessionOpenFailed


And saying that somehow the server does not belong to Trusted Hosts, but i'm using the script on the Remote Desktop Server itself... I dont understand how it cannot trust itself...



I'm sorry as my knowledge in powershell is limited, i wanted to try it out instead of opening each session manually, which can be boring... I may have made an obvious mistake, but i couldnt find answers looking up for this error... And i don't know what else to look for...



Thanks for any help provided !



Cheers



Jean.



PS: Please feel free to report any grammar mistakes, english is not a language i am fluent in...







powershell rdp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 10:08







Jean Werkling

















asked Nov 22 '18 at 10:03









Jean WerklingJean Werkling

11




11








  • 2





    New-PSSession doesn't use RDP - it is a non-interactive console session and has no GUI.

    – James C.
    Nov 22 '18 at 10:17













  • Have a look at Connect-Mstsc

    – Theo
    Nov 22 '18 at 10:35











  • Possible solution: stackoverflow.com/a/11795149/2208505

    – James C.
    Nov 22 '18 at 10:38
















  • 2





    New-PSSession doesn't use RDP - it is a non-interactive console session and has no GUI.

    – James C.
    Nov 22 '18 at 10:17













  • Have a look at Connect-Mstsc

    – Theo
    Nov 22 '18 at 10:35











  • Possible solution: stackoverflow.com/a/11795149/2208505

    – James C.
    Nov 22 '18 at 10:38










2




2





New-PSSession doesn't use RDP - it is a non-interactive console session and has no GUI.

– James C.
Nov 22 '18 at 10:17







New-PSSession doesn't use RDP - it is a non-interactive console session and has no GUI.

– James C.
Nov 22 '18 at 10:17















Have a look at Connect-Mstsc

– Theo
Nov 22 '18 at 10:35





Have a look at Connect-Mstsc

– Theo
Nov 22 '18 at 10:35













Possible solution: stackoverflow.com/a/11795149/2208505

– James C.
Nov 22 '18 at 10:38







Possible solution: stackoverflow.com/a/11795149/2208505

– James C.
Nov 22 '18 at 10:38














1 Answer
1






active

oldest

votes


















0














Thanks for those advices, i looked into Connect-Mstsc and modified my script , i'll add some timer and i'm trying to close the session using the script, i'll share once its done!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428388%2fopening-multiple-rdp-sessions-with-powershell%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Thanks for those advices, i looked into Connect-Mstsc and modified my script , i'll add some timer and i'm trying to close the session using the script, i'll share once its done!






    share|improve this answer




























      0














      Thanks for those advices, i looked into Connect-Mstsc and modified my script , i'll add some timer and i'm trying to close the session using the script, i'll share once its done!






      share|improve this answer


























        0












        0








        0







        Thanks for those advices, i looked into Connect-Mstsc and modified my script , i'll add some timer and i'm trying to close the session using the script, i'll share once its done!






        share|improve this answer













        Thanks for those advices, i looked into Connect-Mstsc and modified my script , i'll add some timer and i'm trying to close the session using the script, i'll share once its done!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 13:24









        Jean WerklingJean Werkling

        11




        11
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428388%2fopening-multiple-rdp-sessions-with-powershell%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            ts Property 'filter' does not exist on type '{}'

            mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window