Jump to content

Recommended Posts

Posted

Hi,

 

I wish to create a script that will hide users from the Exchange Address list that are disabled. I have pinched a script and i can seem to get it to work. I dont get any errors. Can anyone spot the problem please?

 

Thanks

 

# Add Quest / Exchange Snaps
Add-PSSnapin Quest.ActiveRoles.ADManagement # Adds Quest "qaduser" commands
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 # Adds Exchange Shell Commands

# Squelches error
$ErrorActionPreference="SilentlyContinue"

$user = get-qaduser -SearchRoot "falinge.int/Staff User Accounts" -disabled -NotMemberof "No Auto Disable" -anr "SMTP:*" -ldapfilter "(!(msExchHideFromAddressLists=*))" -sizelimit 0 | select samaccountname

foreach($name in $user){
set-mailbox -HiddenFromAddressListsEnabled $True -identity $name.samaccountname
}

# Force update of OAL Generator
Get-OfflineAddressBook | Update-OfflineAddressBook

# Pause script for 30 seconds
Start-Sleep -s 30

# Force update of OAB on CAS
Get-ClientAccessServer | Update-FileDistributionService

Posted (edited)
Assume you have the Quest powershell commands installed, probably from here PowerShell Commands (CMDLETs) for Active Directory by Quest but i've never used them.

 

They are indeed, i use them for another script.

 

Do you have your execution policy set correctly?

 

Yep it is setup ok.

 

Have you put the modules in the right place?

 

How do you mean please?

 

What errors though?

 

No errors at all.

 

Thanks

Edited by FN-GM
Posted
I don't get any errors. Can anyone spot the problem please?

Try setting the $ErrorActionPreference to 'Stop' or 'Continue' (or comment it out with a # temporarily).

 

$ErrorActionPreference="Stop"

  • Thanks 1
Posted
Thanks, it shows an error, but i keep missing it as the window closes. How do i stop the window for closing please?
Posted

Got a screenshot quickly. The problem was ScriptingAgentConfig.xml was missing from the client. I copied it from the server and it worked fine. I made a tweak to the code and this is the final code.

 

Thanks

 

# Add Quest / Exchange Snaps
Add-PSSnapin Quest.ActiveRoles.ADManagement # Adds Quest "qaduser" commands
Add-PSSnapin Microsoft.Exchange.Management.Powershell.e2010 # Adds Exchange Shell Commands

# Squelches error
# $ErrorActionPreference="SilentlyContinue"

$user = get-qaduser -SearchRoot "falinge.int/Staff User Accounts" -disabled -NotMemberof "No Auto Disable" -anr "SMTP:*" -ldapfilter "(!(msExchHideFromAddressLists=*))" -sizelimit 0 | select samaccountname

foreach($name in $user){
set-mailbox $name.samaccountname -HiddenFromAddressListsEnabled $true
}

# Force update of OAL Generator
Get-OfflineAddressBook | Update-OfflineAddressBook

# Pause script for 30 seconds
Start-Sleep -s 30

# Force update of OAB on CAS
Get-ClientAccessServer | Update-FileDistributionService

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...