How to connect to ARS v8 from PowerShell?

I have the following function in PowerShell:

Function Get-ARSServers {

$searchRoot = "CN=Enterprise Directory Manager,CN=Aelita,CN=System,$([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry() | Select-Object -ExpandProperty DistinguishedName)"


Get-QADObject -SearchRoot $searchRoot -Type serviceConnectionPoint | SELECT-object -ExpandProperty Name | Where-object { $_.indexOf(":17228") -gt 0 } | Select-object @{name='serverName';expression={$_.split(":")[0]}} | select-object -ExpandProperty serverName

}

This is then called via this code:

$QARSServerFQDN = Get-ARSServers | Select-Object -First 1
Connect-QADService -Service $QARSServerFQDN -Proxy

However, I get an error and I'm not sure why:

Get-QADObject : The pipeline has been stopped.
At C:\ARS Scripts\lzcreation.ps1:267 char:5
+ Get-QADObject -SearchRoot $searchRoot -Type serviceConnectionPo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-QADObject], PipelineStoppedException
+ FullyQualifiedErrorId : ActiveRoles.ManagementShell.Powershell.Cmdlets.GetGenericObjectCmdlet

  • Same error - as written

    try replacing
    $QARSServerFQDN = Get-ARSServers | Select-Object -First 1

    with

    $QARSServerFQDN = (Get-ARSServers)[0]

  • I get this now:
    Connect-QADService :
    The remote endpoint does not exist or could not be located.
    At C:\ARS Scripts\lzcreation.ps1:360 char:9
    + Connect-QADService -Service $QARSServerFQDN -Proxy
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Connect-QADService], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,ActiveRoles.ManagementShell.Commands.ConnectCmdlet

  • Interesting - your script worked for me with the change suggested.
    when you run get-arsservers - are you getting back a list of ARS host FQDN's ?

  • In the lab there is only one server, but yes I am.

    I left the function the same and changed the code to complete a write-host of the variable:
    #Get the currently active ARS server
    $QARSServerFQDN = (Get-ARSServers)[0]
    #Connect to Active Roles Server
    write-host $QARSServerFQDN
    Connect-QADService -Service $QARSServerFQDN -Proxy

    This produced the following:
    A
    Connect-QADService :
    The remote endpoint does not exist or could not be located.
    At C:\ARS Scripts\temporarycode.ps1:13 char:9
    + Connect-QADService -Service $QARSServerFQDN -Proxy
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Connect-QADService], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,ActiveRoles.ManagementShell.Commands.ConnectCmdlet

    As you can see the write-host only contains the letter A.

  • I've narrowed it down to the [0], if I remove them it works fine.  I suspect the [0] only works if there is more than one, but doesn't work when there is only one.

  • Where there's only one server returned, the [0] translates to "give me first character of the string".

    Here's my code that works whether you get back one server or more.

    $Root = "CN=Enterprise Directory Manager,CN=Aelita,CN=System,DC=companyd,DC=local"

    $Servers = @(get-qadobject -SearchRoot $Root | select -ExpandProperty name | where {$_ -like '*2*'}) # The 2 brings back those items containing the port number

    $MyARServer = $Servers[0]

    The secret sauce is converting the returned list to an array with the @() so you can index into the first element

  • For anyone who may need this in the future, the correct code looks like this:

    Function Get-ARSServers {

    $searchRoot = "CN=Enterprise Directory Manager,CN=Aelita,CN=System,$([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry() | Select-Object -ExpandProperty DistinguishedName)"
    Get-QADObject -SearchRoot $searchRoot -Type serviceConnectionPoint | SELECT-object -ExpandProperty Name | Where-object { $_.indexOf(":17228") -gt 0 } | Select-object @{name='serverName';expression={$_.split(":")[0]}} | select-object -ExpandProperty serverName

    }


    #Get the currently active ARS server
    $QARSServerFQDN = (Get-ARSServers) | select-object -First 1
    #Connect to Active Roles Server
    Connect-QADService -Service $QARSServerFQDN -Proxy

  • The $MyARServer line should read:

    $MyARServer = $($Servers[0].Split(':')).split(':')[0]  # Select the first server returned and truncate the port number (using the split)

    So... all together:

    $Root = "CN=Enterprise Directory Manager,CN=Aelita,CN=System,DC=companyd,DC=local"

    $Servers = @(get-qadobject -SearchRoot $Root | select -ExpandProperty name | where {$_ -like '*2*'}) # The 2 brings back those items containing the port number

    $MyARServer = $($Servers[0].Split(':')).split(':')[0]   # Select the first server returned and truncate the port number (using the split)

    (I don't like to munge all my code together as I am used "teaching" people) Slight smile

  • My bad:

    $MyARServer = $($Servers[0].Split(':'))[0]  # Select the first server returned and truncate the port number (using the split)

    Connect-QADService -proxy -Service $MyARServer

  • Two things:

    1) The Active Roles Administration Service FQDN is stored separately on the serviceBindingInformation attribute of the Service Connection Point, so you just need to get that value instead of all of the string manipulation on the name:

    Function Get-ARSServers {

    $searchRoot = "CN=Enterprise Directory Manager,CN=Aelita,CN=System,$([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry() | Select-Object -ExpandProperty DistinguishedName)"


    (Get-QADObject -SearchRoot $searchRoot -Type serviceConnectionPoint -IncludedProperties serviceBindingInformation | SELECT-object serviceBindingInformation).serviceBindingInformation

    }

    #Get the currently active ARS server
    $QARSServerFQDN = (Get-ARSServers) | select-object -First 1
    #Connect to Active Roles Server
    Connect-QADService -Service $QARSServerFQDN -Proxy

    2) This functionality is built into the Connect-QADService cmdlet. If you just use -Proxy without specifying -Service, then the service connection points will be read and the first one will be connected to:

    Connect-QADService -Proxy