Friday 26 August 2011

Exchange 2010: Setting “Send As” permissions

Unlike user mailboxes, setting “Send As” permission can only be performed from Powershell for a distribution list. The following script will prompt you for the user and group and then set the send as permission. It will then display what the result was.

param ([string]$User = $(Read-Host -prompt "User"), [string]$Group = $(Read-Host -prompt "Group") )

Add-ADPermission -Identity "mydomain.local/$Group" -User "$User" -ExtendedRights "Send As"

Get-AdPermission -Identity "mydomain.local/$Group" | where-object {$_.extendedrights -like 'send-as'} | select user,extendedrights

 


Remember to replace “mydomain.local” with your domain name. I normally specify the group name as the full path to the group, including the AD containers to make sure I get the correct one. You can change that to –Identity $group and just specify the group name if you want to.


The following reverses the process:

param ([string]$User = $(Read-Host -prompt "User"), [string]$Group = $(Read-Host -prompt "Group") )

Remove-ADPermission -Identity "mydomain.local/$Group" -User "$User" -ExtendedRights "Send As" -Confirm:$False

Get-AdPermission -Identity "mydomain.local/$Group" | where-object {$_.extendedrights -like 'send-as'} | select user,extendedrights

South African postal codes

Since the demise of Dotnet.org.za, I haven’t had a blog. So I decided to start again. So lets start with something simple that I had to do today.

It sound like it should be simple to get an electronic list of postal codes for South Africa to import into your app, but its surprisingly difficult. I decided to write a PowerShell script to retrieve it from SA Web. They have a page for each alphabet letter that contains the suburbs starting with that letter. The script downloads each of the 26 pages and parses each page for the list of suburbs and their codes.

I decided to use the InternetExplorer.Application COM object that allows me to access the HTML DOM.

$alph=@()
97..122|%{$alph+=[char]$_}
$urls=@()
$alph | % {$urls+="http://www.saweb.co.za/pcodes/"+$_+".html"}
$ie= new-object -com InternetExplorer.Application
$ie.visible = $true
$codes = @()
$urls | % {
$ie.Navigate($_);
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$doc = $ie.Document;
$doc.getElementsByTagName("P") | % {$codes += $_.innerText }
}
$ie.Quit()
$results = @()
$regex = [regex]"^(?<suburb>[\w\s]+)\s-\s(?<code>\d+)\s-.*$"
$codes | % {
$regex.Matches($_) | %{
if($_.Success -eq $True) {
$suburb = $_.Groups[1].Value
$code = $_.Groups[2].Value.PadLeft(4, '0')
$results += New-Object Object | Add-Member NoteProperty Suburb $suburb -PassThru | Add-Member NoteProperty Code $code -PassThru
}
}
}
$results| Export-Csv "postalcodes.csv"


The results are exported as a CSV.