Tuesday, November 16, 2010

Powershell: Update Timezone Region for Outlook.com Live@Edu Accounts

Here's a quick script to update the Timezone and Language of all your Outlook Live Accounts using remote powershell.

### -----------------------------------------------------------------
### Written by Matt Brown - 11/16/2010
###
### Powershell script requires a csv text file in the following Format:
###  > email
###  > address1@domain.com
###     > user2@domain.com
### -----------------------------------------------------------------

## Setup Vars
$ImportFile = "C:\live-email-list.csv"
$Language = "en-US"
$Timezone = "Pacific Standard Time"
$DateFormat = "M/d/yyyy"
$TimeFormat = "h:mm tt"

## get the email accounts to change
$EmailAccounts = import-csv $ImportFile
Write-Host " Accounts Found in CSV File" $EmailsToCheck.Length

if($EmailsToCheck.Length -gt 0) {
  ## Setup Outlook Session Session and modify accounts
  $LiveCred = Get-Credential
  $loop = 5
  while($loop -gt 0) {
    # this loops handles reconnect if connection to Live fails on first try.
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
    if($Session) { 
      $loop = 0
      Import-PSSession $Session
      $EmailAccounts | foreach {
        $Check = Get-MailboxRegionalConfiguration $_.email
        if($Check -ne $Timezone) {
          Write-Host $_.email
          Set-MailboxRegionalConfiguration $_.email -TimeZone $Timezone -Language $Language -DateFormat $DateFormat -TimeFormat $TimeFormat
        }
      }
    } else {
      Write-Host "Session not created... trying again"
      $loop -= 1
    }
  }
}
Remove-PSSession $Session.Id

Monday, May 31, 2010

Auto Logout after 1 hour of usage

I recently needed a script to automatically log the user out after 1 hour of computer usage. I came up with a pretty low tech solution. Set a scheduled task to activate on user login that runs a DOS bat script. The bat script sleeps for 57 minutes and then kicks off a reboot with notice. Note: It requires sleep.exe from the Windows Resource Kit tools.

@ECHO OFF
REM ##########################################################################
REM ### by Matt Brown
REM ###
REM ### This Script should be set to Run at Logon via a scheduled task
REM ### - it should be run as an admnistrator and the users that you
REM ### - want to force a logoff should be standard user accounts. 
REM ###
REM ### - Note: Requires sleep.exe from Windows Resource Kit in system32 dir
REM ##########################################################################

REM ### Sleep script for 57 Minutes (in seconds)
SLEEP 3300

REM ### Set the notice to display to the user when shutdown is initiated
SET NOTICE="Your one hour of time has expired. You will be automatically logged off in 3 Minutes"

REM ### Start a shutdown, complete in 180 seconds and give notice to users
SHUTDOWN /r /t 180 /c %NOTICE% /f

Sunday, February 28, 2010

Remove Terminated User from GAL - Powershell

Quick Powershell script to remove disabled users from the Exchange 2007 Global Address List (GAL) without deleting the account / mailbox. This uses the Quest Active Roles powershell extensions for Active Directory.
### -----------------------------------------------------------------
### Written by Matt Brown
###
### Name: Remove Terminated Employees from GAL
###
### Version: v1.0, 02/2010
###
### Info: This script Finds Disabled Users and removes them from the GAL
###
### Requires: 1. Quest Powershell extensions for AD
###
### Note: If you are using Resource Mailboxes that are disabled you
###   will want to directly specify your staff OU.
### -----------------------------------------------------------------
$mydomain = 'domain.company.com/Staff'
get-qaduser -SearchRoot $mydomain -SizeLimit 3000 -Enabled:$false | set-qaduser -objectAttributes @{showinaddressbook=@()}

Friday, February 26, 2010

Exchange 2007 Alias update - Powershell

With a recent migration from an old email system I needed to bring over aliases from the old system that would be grandfathered for those users but not new users. This Powershell script checked the accounts to see if the alias was present and if not added it to the account as an accepted Email Address.

### -----------------------------------------------------------------
### Written by Matt Brown - 01/07/2010
###
### Powershell script to update Exchange Aliases
### from ones found old email system
###
### Requires Exchange Powershell extenstions
###
### Input file should contain csv row for alias and username
### Example: username,alias
### jdoe,jon.doe
### -----------------------------------------------------------------

$thedate = Get-Date -f yyyy-MM-dd_HH-mm
$filename = $thedate + "_output.rtf"
start-transcript -path $filename

# ---------------------------
# Add Quest AD Snapin
# ---------------------------
if(-not (Get-PSSnapin | where { $_.Name -match 'quest.activeroles.admanagement' })) {
add-PSSnapin quest.activeroles.admanagement
}
if(-not (Get-PSSnapin | where { $_.Name -match 'Microsoft.Exchange.Management.PowerShell.Admin' })) {
add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
}

## Grab all the aliases in the file and group in an array by username
$MailAliases = @{}
Import-Csv "test.txt" | foreach {
$MailAliases[$_.Username] += @($_.Alias)
}

## set the domains we want to see for each alias
$Domains = @()
$Domains += "@domain.com"
$Domains += "@sub.domain.com"

## loop through the users and look for each alias
## with each domain in the current list if missing add
## it to the accepted addresses and update the user account
$x = $MailAliases.count
$length = $x
$MailAliases.keys | foreach {
# Get the user account
$User = Get-Mailuser -identity $_
$updateuser = $false
# Check each mail alias in the list
$MailAliases[$_] | foreach {
$ua = $_
$Domains | foreach {
$check = $ua + $_
$needsadd = $true
$User.EmailAddresses | foreach {
if($_.SMTPAddress -eq $check) {
# address found in list, will not be added
$needsadd = $false
}
}
if($needsadd -eq $true) {
# address wasn't found, add to accepted addresses
$User.EmailAddresses += $check
$updateuser = $true
}
}
}
if($updateuser -eq $true) {
# Now Update the User Account with new aliases
#Write-Host $User.Name
$User | Set-Mailuser
}
}
#cleanup
Stop-Transcript