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

Parents Reply Children
  • 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

  • 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