Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Disable mailbox in a script

$
0
0

Ok, I have been working on this for days and days, please help.

What I am trying to accomplish is to disable mailboxes that are older then 30 days with a certain name.  All works well except for the disabling of the mailbox thats older than 30 days.

Output after the scripts runs 

Cannot bind argument to parameter 'Identity' because it is null.
+ CategoryInfo : InvalidData: (:) [Disable-Mailbox], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Disable-Mailbox

 

<snip from Script>

# Loop through mail accounts
foreach($account in $autorespondersOlderthan30){
 # Get creation date
 $createdDate = Get-mailbox -resultsize unlimited $account.Name | Select-Object whenmailboxCreated 
   
 # If older than limit, disable
 if($createdDate.whenCreated -lt $limit){
  # Disable accounts
  Disable-Mailbox -Identity $account.Name -Confirm:$False
  $accountsDisabled += $account.Name
       

Thanks!

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles