1

i got some problem while preparing some useful script based on PS.

I try to make script which will collect data from Active Directory and Exchange (users/mailboxes), then this data will be processed in further part of script (in some function for example)

function toProcess($userObj, $mailboxObj)
{
  echo $userObj.enabled #the output is null
}

$users = get-adusers -Filter * -properties *
foreach($user in $users)
{
  $guid = $user.objectGuid.toString()
  if($user.mail -ne $null)
  {
    $mailbox = get-mailbox $guid | select-object *
    if($mailbox -ne $null)
    {
       toProcess($user, $mailbox)
    }       
  }
}

When there is assigned only one parameter ($user) to the onProcess(), function executes correctly and display status of account. When i assign two objects, values becomes null. What's wrong?

I use powershell 2.0

0

1 Answer 1

3

When calling PowerShell functions, arguments are separated by spaces, and parentheses are not needed.

Your function call should look like this.

toProcess $user $mailbox

By placing a comma between the variables, you were creating a single argument that is an array of objects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.