none
Powershell Management Agent (Soren Granfeldt), missing anchor component on export RRS feed

  • Question

  • Hi All,

    I am using the Powershell MA from Soren to provision users to Skype for Business through a webservice. (Using the version currently available on the psma.codeplex.com website). Also I am using the FIM 2010 R2 Sp1 version (build 4.1.3721.0).

    The web service is a REST web service.

    I only have to export users to this web service, I do not have to import any users from this MA.

    I have therefore created a schema.ps1 file, with an anchor and the fields required by the webservice.

    The other files import.ps1 and password.ps1 are empty.

    I am doing Delta exports or PSCustomObjects (Simple objects). When I export the user they are correctly sent to the webservice. (I see adds in my console). However I also receive a missing-anchor-component from the MA. 

    I a sending back the info from the web service in a hash table however the anchor is not provisioned and I am unclear on how to set it.

    The web service provisions an SQL database. And the anchor of my schema is set to an auto-incremented field in the SQL database.

    Thanks for you help.

    Sylvan

    Tuesday, June 7, 2016 9:18 AM

Answers

  • Hi Guys!

    Found the solution. Just forgot to add the anchor attribute value to the export hash table as follows:

    $obj.Add("<name of anchorid attribute>", <datasource value>)

    Hope this helpes cheers,

    Sylvan

    • Marked as answer by Zoltar00 Wednesday, June 8, 2016 3:11 PM
    Wednesday, June 8, 2016 3:11 PM

All replies

  • Hi Guys!

    Found the solution. Just forgot to add the anchor attribute value to the export hash table as follows:

    $obj.Add("<name of anchorid attribute>", <datasource value>)

    Hope this helpes cheers,

    Sylvan

    • Marked as answer by Zoltar00 Wednesday, June 8, 2016 3:11 PM
    Wednesday, June 8, 2016 3:11 PM
  • Can someone please let me know about the correct syntax for the Anchor?

    $obj.Add("<name of anchorid attribute>", <datasource value>)

    In the schema file the Anchor Attribute is written like "Anchor-MyAttribute" do I need to use this?

    $obj.Add("Anchor-MyAttribute", "myAnchorValue")

    or do I only need to use the Attributename "MyAttribute"?

    $obj.Add("MyAttribute", "myAnchorValue")

    I tried both with no success. The examples on the codeplex Website do not have any export code where the Anchor is generated during provisioning.

    Can anybody please give an working example? I allways get a error message in the Sync Engine "Anchor attribute missing".

    Thanks

    Chris


    Thursday, November 17, 2016 3:58 PM
  • Hi Chris,

    Here is what I have in my schema.ps1 file:

    $obj = New-Object -Type PSCustomObject
    $obj | Add-Member -Type NoteProperty -Name "Anchor-PhoneUserID|String" -Value "xxx"
    $obj | Add-Member -Type NoteProperty -Name "objectClass|String" -Value "user"
    $obj | Add-Member -Type NoteProperty -Name "EmployeeID|String" -Value "1"
    $obj | Add-Member -Type NoteProperty -Name "Login|String" -Value "xxx"
    $obj | Add-Member -Type NoteProperty -Name "Site|String" -Value "xxx"
    $obj | Add-Member -Type NoteProperty -Name "CostCenter|String" -Value "xxx"
    $obj | Add-Member -Type NoteProperty -Name "FirstName|String" -Value "xxx"
    $obj | Add-Member -Type NoteProperty -Name "LastName|String" -Value "xxx"
    $obj | Add-Member -Type NoteProperty -Name "SIPAddress|String" -Value "sip:loginname@domain.com"
    $obj | Add-Member -Type NoteProperty -Name "LineManagerLogin|String" -Value "xxx"
    $obj | Add-Member -Type NoteProperty -Name "EmployeeEndDate|String" -Value "2016-05-17T10:57:34.271631+02:00"
    $obj | Add-Member -Type NoteProperty -Name "DisplayName|String" -Value "xxx xxx"
    $obj


    In my export file I have:

    PARAM
    (
      $Username,
      $Password,
      $ExportType
    )

    BEGIN

    {
      #Get URL and server properties

    $Servername = 'URL of the webservice'

    }

    PROCESS
    {
      #Initialize Parameters
      $ErrorName = "success"
      $ErrorDetail = $null

      $DebugFilePath = "C:\Temp\Debug-export.txt"

      if(!(Test-Path $DebugFilePath))
      {
        $DebugFile = New-Item -Path $DebugFilePath -ItemType File
      }
      else
      {
        $DebugFile = Get-Item -Path $DebugFilePath
      }

      $_ | Out-File $DebugFile
      $Identifier = $_."[Identifier]"
      $DN = $_."[DN]"
      $anchor = $_."[Anchor]"
      $ObjectModificationType = $_."[ObjectModificationType]"
      $ChangedAttributeNames = $_."[ChangedAttributeNames]"
      $ObjectType = $_."[ObjectType]"
      $CostCenter = $_.CostCenter
      $DisplayName = $_.DisplayName
      $EmployeeEndDate = $_.EmployeeEndDate
      $EmployeeID = $_.EmployeeID
      $FirstName = $_.FirstName
      $LastName = $_.LastName
      $Login = $_.Login
      $SIPAddress = $_.SIPAddress
      $LineManagerUserLoginID = $_.LineManagerLogin
      $Site = $_.Site
      $_."[Anchor]"=$EmployeeID

      if ($_."[ObjectModificationType]" -eq 'Add')
      {
        #Create Body of the web request

        $body = @{
          EmployeeID = $EmployeeID
          Login = $Login
          Site = $Site
          CostCenter = $CostCenter
          FirstName = $FirstName
          LastName = $LastName
          SIPAddress = $SIPAddress
          LineManagerLogin = $LineManagerUserLoginID
          EmployeeEndDate = $EmployeeEndDate
          DisplayName = $DisplayName
        }

        $body | Out-File $DebugFile -Append

    $body.ToString()

        $reader = $null
        Try
        {
          Invoke-RestMethod -Method Post -URI $URLCreate -UseDefaultCredentials -Body $body -TimeoutSec 0
        }
        Catch
        {
          Write-EventLog -LogName Application -Source "bbb" -EventId 3001 -EntryType Error -Message ("Creation of user failed!  " + $_.Exception.ToString())

          # If it is an HTTP-500, extract the body of the response to get the precise message sent by Skype.
          $resp = $_.Exception.Response
          $msg = ""
          if ([int]$resp.StatusCode -eq 500)
          {
            $reader = New-Object System.IO.StreamReader($resp.GetResponseStream())
            $reader.BaseStream.Position = 0
            $reader.DiscardBufferedData()
            $msg = $reader.ReadToEnd()
          }

          $ErrorName = "Creation of user Failed!"
          $ErrorDetail = "Error when trying to create user: " + $msg + $_.Exception.ToString()
        }
        finally
        {
          if ($null -ne $reader)
          {
            $reader.Close()
          }
        }

        #Return the result to the MA
        $obj = @{}
        $obj.Add("[Identifier]",$Identifier)
        $obj.Add("[ErrorName]",$ErrorName)
        $obj.Add("PhoneUserID",$DN)
        if($ErrorDetail){$obj.Add("[ErrorDetail]",$ErrorDetail)}

        $obj | Out-File $DebugFile -Append
        $obj
      }

      if ($_."[ObjectModificationType]" -eq 'Delete')
      {
        $body = @{
            Login =  $DN
        }

        $body | Out-File $DebugFile -Append

        $reader = $null
        Try
        {
            Invoke-RestMethod -Method Post -URI $URLDelete -UseDefaultCredentials -Body $body -TimeoutSec 0
        }
        Catch
        {

            # If it is an HTTP-500, extract the body of the response to get the precise message sent by Skype.
            $resp = $_.Exception.Response
            $msg = ""
            if ([int]$resp.StatusCode -eq 500)
            {
                $reader = New-Object System.IO.StreamReader($resp.GetResponseStream())
                $reader.BaseStream.Position = 0
                $reader.DiscardBufferedData()
                $msg = $reader.ReadToEnd()
            }

            # "Deletion of user failed!" | Out-File $DebugFile -Append
            $ErrorName = "Deletion of user Failed!"
            $ErrorDetail = "Error when trying to delete user: " + $msg + $_.Exception.ToString()
        }
        finally
        {
          if ($null -ne $reader)
          {
            $reader.Close()
          }
        }

        #Return the result to the MA
        $obj = @{}
        $obj.Add("[Identifier]",$Identifier)
        $obj.Add("[ErrorName]",$ErrorName)
        if($ErrorDetail){$obj.Add("[ErrorDetail]",$ErrorDetail)}

        $obj | Out-File $DebugFile -Append
        $obj
      }

      if ($_."[ObjectModificationType]" -eq 'Replace')
      {
        if ([String]::IsNullOrEmpty($LineManagerUserLoginID)){
          $LineManagerUserLoginID = ""
        }

        #Create Body of the web request

          $body = @{
          EmployeeID = $EmployeeID
          Login = $Login
          Site = $Site
          CostCenter = $CostCenter
          SIPAddress = $SIPAddress
          LineManagerLogin = $LineManagerUserLoginID
          EmployeeEndDate = $EmployeeEndDate
          DisplayName = $DisplayName
        }

        $body | Out-File $DebugFile -Append

        $reader = $null
        Try
        {
          Invoke-RestMethod -Method Post -URI $URLCreate -UseDefaultCredentials -Body $body -TimeoutSec 0
        }
        Catch
        {
              # If it is an HTTP-500, extract the body of the response to get the precise message sent by Skype.
          $resp = $_.Exception.Response
          $msg = ""
          if ([int]$resp.StatusCode -eq 500)
          {
              $reader = New-Object System.IO.StreamReader($resp.GetResponseStream())
              $reader.BaseStream.Position = 0
              $reader.DiscardBufferedData()
              $msg = $reader.ReadToEnd()
          }
          #"Modification of user failed!" | Out-File $DebugFile -Append
          $ErrorName = "Modification of user Failed!"
          $ErrorDetail = "Error when trying to modify user: " + $msg + $_.Exception.ToString()
        }
        finally
        {
          if ($null -ne $reader)
          {
            $reader.Close()
          }
        }

        #Return the result to the MA
        $obj = @{}
        $obj.Add("[Identifier]",$Identifier)
        $obj.Add("[ErrorName]",$ErrorName)
        $obj.Add("PhoneUserID",$DN)
        if($ErrorDetail){$obj.Add("[ErrorDetail]",$ErrorDetail)}

        $obj | Out-File $DebugFile -Append
        $obj
      }
    }

    END
    {
      #Writing close tag in debugfile
      Write-EventLog -LogName Application -Source "bbb" -EventId 3001 -EntryType Information -Message "Ending Export"
      #"Ending Export : " + (Get-Date) | Out-File $DebugFile -Append
    }

    In the Powershell connector make sure that "Export simple objectsw" is checked on the Global Parameters tab

    Hope this helps

     Sylvan

    Friday, November 18, 2016 1:02 PM