none
get-user cmdlet returns different values for 'OriginatingServer' property when executed on windows powershell prompt and when executed from a c# application RRS feed

  • Question

  • Hi All,

    We have a c# app for mail enabling AD user. i.e we make use of 'Enable-Mailbox -Identity <user> -DomainController -<dc_name>'.

    Since Exchange is in a multi domain topology, we are using -DomainController parameter with Enable-Mailbox.

    Now we dont know the user's DC, so we do 'Get-User -ReadFromDomainController -IgnoreDefaultScope -Filter {UserPrincipalName -eq '<my_user>'}' and get 'OriginatingServer' property, hoping 'OriginatingServer' is the user's DC if we read from only domain controller.

    Howerver, when the same command is executed from c# app, gets incorrect value for 'OriginatingServer' but when run on windows powershell returns correct DC.

    Is there something I am missing? Is this not the right way to get user's DC? What is the correct way of doing this?

    please help. Thanks!


    /M

    Wednesday, October 24, 2012 8:29 AM

All replies

  • Hi,
    Im not a scripter, but I was wondering..."What happends if you run Set-ADServerSettings -ViewEntireForest $True instead of Get-User etc etc and leave the domaincontroller parameter out?

    Martina Miskovic

    Wednesday, October 24, 2012 8:35 AM
  • Thanks Martina, Yes,we do Set-ADServerSettings -ViewEntireForest:$true

    Also we can leave DomainController out, but if we try to enable Ad user too soon (before replication occurs) we do get error... I will explain the scenario...

    1> We have a c# app1 which uses ADSI to manage only AD accounts.

    2> We have second c# app2 only to manage exchange accounts.

    So, lets app1 creates a AD user and before replication even completes, if app2 fires command for enabling mailbox (we don't have control over this), wont we get error ?

    It is this for reason, we want to pass -Domaincontroller to enable-mailbox.

    Is my understanding correct?Is there better/correct way to do this?

    I can provide more details about the scenario, please ask. thanks again.


    /M

    Wednesday, October 24, 2012 8:41 AM
  • So, lets app1 creates a AD user and before replication even completes, if app2 fires command for enabling mailbox (we don't have control over this), wont we get error ?


    /M


    Hi,
    I wish I had an answer to that, but I don't, sorry!

    Martina Miskovic

    Wednesday, October 24, 2012 8:47 AM
  • Ok :(

    Thanks Martina for your replies. But one thing still troubles me is that... if I execute "Get-User -ReadFromDomainController -IgnoreDefaultScope -Filter {UserPrincipalName -eq '' -or DistinguishedName -eq ''} | Select OriginatingServer" On windows powershell prompt (remotely connected to exchange server 2010), 'OriginatingServer' shows correct DC.

    But, the same I do from my c# app I get different value :(

    I make use of classes in namespaces "System.Management.Automation.Runspaces" like Command, CommandParameter and in System.Management.Automation like Powershell etc...Any thing am I missing?


    /M

    Wednesday, October 24, 2012 8:54 AM