locked
The term 'Get-ADObject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again RRS feed

  • Question

  • User265753822 posted

    What is missing?

    My Code:

    public class ActiveDirectoryManager
    {
    private const string CommonNameProperty = "CN";
    private const string ServiceProperty = "extensionAttribute11";
    private const string AccountNameProperty = "sAMAccountName";
    private const string DistinguishedNameProperty = "DistinguishedName";
    private const string DisplaynameProperty = "displayName";

    /// <summary>
    /// Gets the functional mailboxes.
    /// </summary>
    /// <returns></returns>
    public IList<FunctionalMailbox> GetFunctionalMailboxes()
    {
    IList<FunctionalMailbox> functionalMailboxes = new List<FunctionalMailbox>();

    InitialSessionState iss = InitialSessionState.CreateDefault();
    iss.ImportPSModule(new[] { "activedirectory" });

    using (Runspace myRunSpace = RunspaceFactory.CreateRunspace(iss))
    {
    myRunSpace.Open();

    Pipeline pipeLine = myRunSpace.CreatePipeline();
    var getMailboxesCommand = new Command("Get-ADObject");
    getMailboxesCommand.Parameters.Add("SearchBase", "OU=resource mailboxes,OU=exchange,OU=allusers,OU=isis,DC=ces-cdr,DC=eu,DC=int");
    getMailboxesCommand.Parameters.Add("Filter", "objectclass -eq \"user\"");
    //getMailboxesCommand.Parameters.Add("MSExchHideFromAddressLists", "FALSE");
    getMailboxesCommand.Parameters.Add("Properties", new[] { AccountNameProperty, CommonNameProperty, DisplaynameProperty,
    "mail", "created", "description","protocolSettings", "publicDelegates","accountExpires", "msexchhidefromaddresslists" });

    pipeLine.Commands.Add(getMailboxesCommand);
    Collection<PSObject> mailboxesTemp = pipeLine.Invoke();
    Collection<PSObject> mailboxes = new Collection<PSObject>();
    pipeLine.Dispose();
    mailboxesTemp.ToList().ForEach(m =>
    {
    if (m.Properties["msexchhidefromaddresslists"].Value != null && m.Properties["msexchhidefromaddresslists"].Value as bool? == true)
    {
    }
    else
    {
    mailboxes.Add(m);
    }
    });

    Friday, May 27, 2016 8:26 AM

All replies

  • User-166373564 posted

    HI CRogado,

    var getMailboxesCommand = new Command("Get-ADObject");

    The Get-ADObject cmdlet gets an Active Directory object or performs a search to get multiple objects.

    According to the error message, it seems that you don't use getMailboxesCommand.Parameters.Add() method properly, please check parameters in getMailboxesCommand.Parameters.Add(), and whether they are available.

    Have a good day.

    Angie

    Monday, May 30, 2016 7:34 AM