Deleting mails/meetings in a mailbox

When you have an application mailbox that automatically send meeting request to people, so many items could be really heavy.

Here is a little tips to delete all previous meeting automatically (due to a scheduled task) :

#Calculating J-1 date
$ddate=get-date -uformat %m/%d/%Y
$ddate=$ddate.AddDays(-1)
#Adding rights on the mailbox (do it Once)
Get-Mailbox “application.mailbox” | Add-MailboxPermission -User $localu -AccessRights Fullaccess -InheritanceType all
#Deleting old meeting/mails
Get-Mailbox “application.mailbox” | Export-Mailbox -EndDate $ddate -DeleteContent

That could be really… really usefull !

SQL Requests & Powershell

It could be really hard to find something interesting on the web when we encountered a trouble in Powershell.

After a long search, I found it ! So, let’s share..

A request in SQL using powershell can be send using .Net Frameword.

You should have in mind that SQL request through powershell are exactly the same like standard SQL requests !

Here is an example with a simple Select :

$conec = “server=;database=;Integrated Security=sspi”
$cmd = “SELECT FROM WHERE ”
$da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $conec)
$dt = new-object System.Data.DataTable
$da.fill($dt)

The “Integrated Security” allow to use Windows Authentication, so the account used to launch the powershell script should have rights on the Database !

The SQL request’s results are contained into the “$dt” variable.

So… Let’s “play” now !