Terminals-Origin / Terminals

Terminals is a secure, multi tab terminal services/remote desktop client. It uses Terminal Services ActiveX Client (mstscax.dll). The project started from the need of controlling multiple connections simultaneously. It is a complete replacement for the mstsc.exe (Terminal Services) client. This is official source moved from Codeplex.
Other
1.25k stars 235 forks source link

Powershell Import Error #207

Open johnbljr opened 5 years ago

johnbljr commented 5 years ago

I am trying to test the powershell script to create the import file from here: https://github.com/Terminals-Origin/Terminals/blob/master/Docs/Powershell-script-to-create-import-file.md

I was having trouble after I modified the script with my server information, so I decided to just try the script without any modifications and I am still getting an error.

The error I am getting is as follows:

At line:41 char:18

  • [Parameter()](Parameter())String$savePath,
  • ~ Parameter declarations are a comma-separated list of variable names with optional initializer expressions.

At line:41 char:18

  • [Parameter()](Parameter())String$savePath,
  • ~ Missing ')' in function parameter list.

At line:46 char:53

  • ... em.XML.XMLDocument](System.XML.XMLDocument)$xmlDoc=New-Object System. ...
  • 
    Unexpected token '$xmlDoc=New-Object' in expression or statement.

At line:49 char:51

  • ... Element](System.XML.XMLElement)$xmlRoot=$xmlDoc.CreateElement("favori ...
  • 
    Unexpected token '$xmlRoot=$xmlDoc.CreateElement' in expression or statement.

At line:57 char:55

  • ... LElement](System.XML.XMLElement)$xmlFav=$xmlDoc.CreateElement("favori ...
  • 
    Unexpected token '$xmlFav=$xmlDoc.CreateElement' in expression or statement.

At line:73 char:49

At line:78 char:1

  • }
  • ~ Unexpected token '}' in expression or statement.

At line:85 char:15

  • [Parameter()](Parameter())String$name, # Connec ...
  • ~ Parameter declarations are a comma-separated list of variable names with optional initializer expressions.

At line:85 char:15

  • [Parameter()](Parameter())String$name, # Connec ...
  • ~ Missing ')' in function parameter list.

At line:104 char:1

  • }
  • ~ Unexpected token '}' in expression or statement. At :line:41 char:18
  • [Parameter()]( <<<< Parameter())String$savePath,

The original unmodified PowerShell script is as follows:

####################################### #

Powershell script to create an import file for Terminals

https://terminals.codeplex.com/

#

Script created by: Niels van de Coevering

Date: 05/31/2014

# #######################################

Set path to save the terminals XML file

$xmlSavePath = "C:\TEMP\terminals.xml";

Create array for favorites

$favCollection = @();

##############

Add your own code here to add your own favorites to the array collection

##############

Examples:

Note: The named credential should be available in the credential manager in Terminals

$favCollection += New-Favorite -name "Server1" -serverName "server1.domain.local" -tags "group1,group2" -notes "my notes" -credential "Domain admin" $favCollection += New-Favorite -name "Server2" -serverName "server2.domain.local" -tags "group1" -notes "my notes" -credential "Domain admin" $favCollection += New-Favorite -name "Server3" -serverName "server3.domain.local" -tags "group2" -notes "my notes" -credential "Domain admin"

##############

Call function to create Terminals XML document with generated favorite object array

Create-XmlDocument -savePath $xmlSavePath -favorites $favCollection

#########################################################################################################################

Function to create and save Terminals XML document.

function Create-XmlDocument (

[Parameter()](Parameter())String$savePath, [Parameter()](Parameter())Object$favorites ) {

Create a new XML file

System.XML.XMLDocument$xmlDoc=New-Object System.XML.XMLDocument; $xmlDoc.CreateXmlDeclaration("1.0","UTF-8",$null);

Add root node

System.XML.XMLElement$xmlRoot=$xmlDoc.CreateElement("favorites");

Append as child to document

$xmlDoc.appendChild($xmlRoot);

Loop for each favorite in the array

foreach($fav in $favorites) {

Create new favorite element and add the child property elements

System.XML.XMLElement$xmlFav=$xmlDoc.CreateElement("favorite"); $xmlFav.appendChild($xmlDoc.CreateElement("protocol")).AppendChild($xmlDoc.CreateTextNode($fav.Protocol)); $xmlFav.appendChild($xmlDoc.CreateElement("port")).AppendChild($xmlDoc.CreateTextNode($fav.Port)); $xmlFav.appendChild($xmlDoc.CreateElement("name")).AppendChild($xmlDoc.CreateTextNode($fav.Name)); $xmlFav.appendChild($xmlDoc.CreateElement("serverName")).AppendChild($xmlDoc.CreateTextNode($fav.ServerName)); $xmlFav.appendChild($xmlDoc.CreateElement("tags")).AppendChild($xmlDoc.CreateTextNode($fav.Tags)); $xmlFav.appendChild($xmlDoc.CreateElement("notes")).AppendChild($xmlDoc.CreateTextNode($fav.Notes)); $xmlFav.appendChild($xmlDoc.CreateElement("credential")).AppendChild($xmlDoc.CreateTextNode($fav.Credential)); $xmlFav.appendChild($xmlDoc.CreateElement("bitmapPeristence")).AppendChild($xmlDoc.CreateTextNode($fav.BitmapPeristence)); $xmlFav.appendChild($xmlDoc.CreateElement("url")).AppendChild($xmlDoc.CreateTextNode($fav.Url));

Appand favorite element to the root element

$xmlRoot.appendChild($xmlFav); }

Save File

System.IO.TextWriter$sw = New-Object System.IO.StreamWriter($savePath, Boolean::true, System.Text.EnCoding::UTF8); $xmlDoc.Save($sw); $sw.Flush(); $sw.Close(); $sw.Dispose(); }

Function to create a new favorite object.

function New-Favorite (

[Parameter()](Parameter())String$name, # Connection name [Parameter()](Parameter())String$serverName, # Computer name (FQDN) to connect to [Parameter()](Parameter())String$tags, # Name of groups favorite belongs to, seperated by a comma [Parameter()](Parameter())String$notes, # Extra note for favorite [Parameter()](Parameter())String$credential # Name of saved managed credential ) { $fav = New-Object PSObject; $fav | Add-Member -MemberType NoteProperty -Name Name -Value $name; $fav | Add-Member -MemberType NoteProperty -Name ServerName -Value $serverName; $fav | Add-Member -MemberType NoteProperty -Name Protocol -Value "RDP"; $fav | Add-Member -MemberType NoteProperty -Name Port -Value "3389"; $fav | Add-Member -MemberType NoteProperty -Name Tags -Value $tags; $fav | Add-Member -MemberType NoteProperty -Name Notes -Value $notes; $fav | Add-Member -MemberType NoteProperty -Name Credential -Value $credential; $fav | Add-Member -MemberType NoteProperty -Name BitmapPeristence -Value "RDP"; $fav | Add-Member -MemberType ScriptProperty -Name Url -Value {"rdp://$($this.ServerName):3389/"};

return $fav; }

Any help you can give on this would be great. This is a great tool and I have hundreds of server that I need to import and doing it manually is not something that I want to do.

Thanks

John

blk2 commented 4 years ago

So i'm not a programmer but there were some error, i was trying the script like you. This work:

#######################################
#
# Powershell script to create an import file for Terminals
# https://terminals.codeplex.com/
#
# Script created by: Niels van de Coevering
# Date: 05/31/2014
#
#######################################

# Set path to save the terminals XML file
$xmlSavePath = "C:\TEMP\terminals.xml";

# Create array for favorites
$favCollection = @();

#########################################################################################################################

###
# Function to create and save Terminals XML document.
###
function Create-XmlDocument
(
    [Parameter()][String]$savePath,
    [Parameter()][Object]$favorites
)
{
    # Create a new XML file
    [System.XML.XMLDocument]$xmlDoc=New-Object System.XML.XMLDocument;
    $xmlDoc.CreateXmlDeclaration("1.0","UTF-8",$null);
    # Add root node
    [System.XML.XMLElement]$xmlRoot=$xmlDoc.CreateElement("favorites");
    # Append as child to document
    $xmlDoc.appendChild($xmlRoot);

    # Loop for each favorite in the array
    foreach($fav in $favorites)
    {
        # Create new favorite element and add the child property elements
        [System.XML.XMLElement]$xmlFav=$xmlDoc.CreateElement("favorite");
        $xmlFav.appendChild($xmlDoc.CreateElement("protocol")).AppendChild($xmlDoc.CreateTextNode($fav.Protocol));
        $xmlFav.appendChild($xmlDoc.CreateElement("port")).AppendChild($xmlDoc.CreateTextNode($fav.Port));
        $xmlFav.appendChild($xmlDoc.CreateElement("name")).AppendChild($xmlDoc.CreateTextNode($fav.Name));
        $xmlFav.appendChild($xmlDoc.CreateElement("serverName")).AppendChild($xmlDoc.CreateTextNode($fav.ServerName));
        $xmlFav.appendChild($xmlDoc.CreateElement("tags")).AppendChild($xmlDoc.CreateTextNode($fav.Tags));
        $xmlFav.appendChild($xmlDoc.CreateElement("notes")).AppendChild($xmlDoc.CreateTextNode($fav.Notes));
        $xmlFav.appendChild($xmlDoc.CreateElement("credential")).AppendChild($xmlDoc.CreateTextNode($fav.Credential));
        $xmlFav.appendChild($xmlDoc.CreateElement("bitmapPeristence")).AppendChild($xmlDoc.CreateTextNode($fav.BitmapPeristence));
        $xmlFav.appendChild($xmlDoc.CreateElement("url")).AppendChild($xmlDoc.CreateTextNode($fav.Url));

        # Appand favorite element to the root element
        $xmlRoot.appendChild($xmlFav);
    }

    # Save File
    [System.IO.TextWriter]$sw = New-Object System.IO.StreamWriter($savePath, [Boolean]::true, [System.Text.EnCoding]::UTF8);
    $xmlDoc.Save($sw);
    $sw.Flush();
    $sw.Close();
    $sw.Dispose();
}

###
# Function to create a new favorite object.
###
function New-Favorite
(
    [Parameter()][String]$name,         # Connection name
    [Parameter()][String]$serverName,   # Computer name (FQDN) to connect to
    [Parameter()][String]$tags,         # Name of groups favorite belongs to, seperated by a comma
    [Parameter()][String]$notes,        # Extra note for favorite
    [Parameter()][String]$credential    # Name of saved managed credential
)
{
    $fav = New-Object PSObject;
    $fav | Add-Member -MemberType NoteProperty -Name Name -Value $name;
    $fav | Add-Member -MemberType NoteProperty -Name ServerName -Value $serverName;
    $fav | Add-Member -MemberType NoteProperty -Name Protocol -Value "RDP";
    $fav | Add-Member -MemberType NoteProperty -Name Port -Value "3389";
    $fav | Add-Member -MemberType NoteProperty -Name Tags -Value $tags;
    $fav | Add-Member -MemberType NoteProperty -Name Notes -Value $notes;
    $fav | Add-Member -MemberType NoteProperty -Name Credential -Value $credential;
    $fav | Add-Member -MemberType NoteProperty -Name BitmapPeristence -Value "RDP";
    $fav | Add-Member -MemberType ScriptProperty -Name Url -Value {"rdp://$($this.ServerName):3389/"};

    return $fav;
}

##############
# Add your own code here to add your own favorites to the array collection
##############

# Examples:
# Note: The named credential should be available in the credential manager in Terminals
$favCollection += New-Favorite -name "Server1" -serverName "server1.domain.local" -tags "group1,group2" -notes "my notes" -credential "Domain admin"
$favCollection += New-Favorite -name "Server2" -serverName "server2.domain.local" -tags "group1" -notes "my notes" -credential "Domain admin"
$favCollection += New-Favorite -name "Server3" -serverName "server3.domain.local" -tags "group2" -notes "my notes" -credential "Domain admin"

##############

# Call function to create Terminals XML document with generated favorite object array
Create-XmlDocument -savePath $xmlSavePath -favorites $favCollection