Exchange 2007 Whitespace

I found this webblog

http://unlockpowershell.wordpress.com/2010/01/27/exchange-2007-mailbox-database-reporting-script/

that would find the freespace and white space for an exchange 2007 server. The powershell script as written was giving me minor errors which when finally corrected yeilded a very nice report for exchange administrators.

one of the errors to note :
Exception calling “Add” with “2” argument(s): “Key cannot be null. Parameter name: key”
At C:\Scripts\whitespacescript.ps1:29 char:45
+ $freespace | ForEach-Object {$whiteSpace.Add( < <<< $_.DB,$_.FreeMB)}

When reading the Application log and getting all the 1221 events, you may have more than one 1221 event per storage group. If the specified key already exists in the Hashtable, setting the Item property overwrites the old value. In contrast, the Add method does not modify existing elements. Which is why the exception is generated.

The other problem I encountered, after the values were entered into the hashtable, once it exited the function, the key would still be in the hashtable, but the value associated with key was empty. Once I reorginized the script so there was not function, it ran without problems.

$date = ( get-date ).ToString(‘MM-dd-yyyy’)
$AllServers = @()
foreach ($server in Get-MailboxServer)
{

# Convert Dates to WMI CIM dates
$tc = [System.Management.ManagementDateTimeconverter]
$Start =$tc::ToDmtfDateTime( (Get-Date).AddDays(-1).Date )
$End =$tc::ToDmtfDateTime( (Get-Date).Date)

#Create a hash Table to hold the freespace information
$hashWS = @{}
#Clear the hash Table just in case
$hashWS.Clear()
# Create two claculated properties for InsertionStrings values
$DB = @{Name=”DB”;Expression={$_.InsertionStrings[1]}}
$FreeMB = @{Name=”FreeMB”;Expression={[int]$_.InsertionStrings[0]}}

$whitespace = Get-WMIObject Win32_NTLogEvent -ComputerName $server -Filter “LogFile=’Application’ AND EventCode=1221 AND TimeWritten>=’$Start’ AND TimeWritten< =’$End'” | Select-Object $DB,$FreeMB
foreach ($objectItem in $whitespace)
{
$hashWS.Add($objectItem.DB,$objectItem.FreeMB)
}

foreach ($objItem in Get-MailboxDatabase -server $server)
{
$edbfilepath = $objItem.edbfilepath
$path = “`\`\” + $server + “`\” + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + “$”+ $objItem.EdbFilePath.PathName.Remove(0,2)
$dbsize = Get-ChildItem $path
$dbpath = $EdbFilePath.PathName.Remove(0,2).remove($EdbFilePath.PathName.length-6)
$mailboxpath = “$server$dbpath”
$size = get-wmiobject -computername $server win32_logicaldisk |where-object {$_.deviceid -eq $objItem.EdbFilePath.DriveName} |select-object deviceID, Freespace, Size
$freespace = ($size.freespace / 1GB)
$total = ($size.size / 1GB)
$PercentFree = “{0:n2}” -f ($freespace / $total *100)
$mailboxcount = Get-MailboxStatistics -database “$mailboxpath” |Where {$_.DisconnectDate -eq $null -and $_.ObjectClass -eq ‘Mailbox’} |measure-object
$disconnectedmailboxcount = Get-MailboxStatistics -database “$mailboxpath” |Where {$_.DisconnectDate -ne $null} |measure-object

$ReturnedObj = New-Object PSObject
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Server\StorageGroup\Database” -Value $objItem.Identity

$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Total Size (GB)” -Value (“{0:n2}” -f ($total))
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Used Space (GB)” -Value (“{0:n2}” -f ($dbsize.Length/1024MB))
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Free Space (GB)” -Value (“{0:n2}” -f ($freespace))
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Percent Disk Free” -Value $percentfree
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “User Mailbox Count” -Value $mailboxcount.count

$dbasename = $objItem.Identity.parent.name +”\” + $objItem.Identity.name
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “White Space (GB)” -Value (“{0:n2}” -f ($hashWS[$dbasename]/1024))

$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Total Free (GB)” -Value (“{0:n2}” -f ($freespace + $hashWS[$dbasename]/1024))
$TotalPercent = ($freespace + $hashWS[$dbasename]/1024) / $total *100
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Total Percent Free” -Value (“{0:n2}” -f ($TotalPercent))
$AllServers += $ReturnedObj
}
}
#$AllServers |Export-Csv E:\MailboxDatabaseSizeReport.csv -NoTypeInformation
$body = “Mailbox Whitespace report for $date ”
$bodydetail = $allservers |sort-object “Server\StorageGroup\Database” |convertto-html
$body = $body + $bodydetail
Send-MailMessage -To “ExchangeAdministrators@mysite.com” -Body $body -Subject “Mailbox Database Size Report” -SmtpServer “smtpserver.mysite.com” -BodyAsHtml:$true -From “ExchageEmailDatabaseSizeReport@mysite.com”

Posted in Powershell | Leave a comment

User Database Retention Default

In Exchange 2007, to enable the recovery dumpster, the user database retention default has to be checked. If its unchecked, you are allowed to specify a time (other than the default of 14 days.) but when you do uncheck it, the recovery dumpster is no longer available.

So the below code will check to see who has the retention default unchecked.

$date = ( get-date ).ToString(‘MM-dd-yyyy’)
$AllServers = @()
#Create a hash Table to hold the freespace information
$hashUDRD = @{}
#Clear the hash Table just in case
$hashUDRD.Clear()
$stream = [System.IO.StreamWriter] ‘C:\Retention.txt’
$mailboxRET = Get-Mailbox -ResultSize 3000 | sort-object UseDatabaseRetentionDefaults| Select displayName,UseDatabaseRetentionDefaults
foreach ($objectItem in $mailboxRET)
{
$IsItSet = $objectItem.UseDatabaseRetentionDefaults
if (-not $IsItSet) {
#if ($IsItSet) {
$s = $objectItem.displayName+”,”+$objectItem.UseDatabaseRetentionDefaults
$stream.WriteLine($s)
}
}
$stream.close()
If ((Get-Content “C:\Retention.txt”) -eq $Null)
{
Remove-Item ‘C:\Retention.txt’
exit
}
$info = get-content ‘C:\Retention.txt’
foreach ($i in $info) {
$item = $i.split(“,”)
$ReturnedObj = New-Object PSObject
$LName = $item[0]
$TFName = $item[1]
$FName = $TFName.TrimStart(” “)
$username = $Lname+”, “+$FName
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “User Name” -Value $username
$ReturnedObj | Add-Member -MemberType NoteProperty -Name “Database Retention Defaults” -Value $item[2]
$AllServers += $ReturnedObj
}
Remove-Item ‘C:\Retention.txt’
#$AllServers |Export-Csv E:\PSOutput\RetentionDefaultReport.csv -NoTypeInformation
$body = “Database Retention Defaults report for $date


$bodydetail = $AllServers |sort-object “User Name” |convertto-html
$body = $body + $bodydetail
Send-MailMessage -To “Administrators@mysite.com” -Body $body -Subject “Retention Defaults Report” -SmtpServer “smptserver.mysite.com” -BodyAsHtml:$true -From “ExchageRetentionReport@mysite.com”

Posted in Powershell | Leave a comment

How To Load And Run Unsigned Drivers In 64 Bit Windows 7

How To Load And Run Unsigned Drivers In 64 Bit Windows 7

I found that Windows 7 makes not only loading unsigned drivers difficult, BUT even if they do load, they wont work. So this method is broken into two parts. The first parts deals with actually loading the unsigned drivers, The second deals with getting them to be accepted and working.

LOADING UNSIGNED DRIVERS

This for some can be straight forward. At boot up hit F8 and select the option in the menu for unsigned drivers. This will allow you to load the drivers. Another way to allow loading of unsigned drivers is

1. Open Windows 7
2. Press Win+R keys together to open the run dialog box and type – gpedit.msc
3. Expand the folders in order <User Configuration> – <Administrative Templates> – <System> – <Driver Installation>.
4. On the right you will see a icon <Code Signing for Device Drivers> , double click that
5. Click <enable> button at the top, and <Ignor > at the bottom to ignor any signature check.
6. hit apply, ok and close everything
7. Reboot

Now the computer will load any drivers anytime.

This solves loading the driver. But Windows 7 would still not allow the drivers loaded to run.

RUNNING LOADED UNSIGNED DRIVERS

There is a neat program that will allow the unsigned drivers to work. Basically its a method that allows testers to test drivers without going thru the dramas of getting a signature from Microsoft. The program can be found by doing a good search for ”Driver Signature Enforcement Overrider 1.3b” or “dseo13b.exe”, or download it from the developers website

The load instructions are simple. As usual TURN OFF UAC.

1. Run dseo13b.exe program
2. click “enable test mode”. This allows 64 bit Windows 7 to be used for testing drivers
3. reboot, and you will see a faint test mode print in the corner (can be turned of by selecting dont show watermark)
4. Now open Device Manager and find the location of the unsigned drivers that wont work, by expanding Properties and Driver Details. Your looking for something like C:\Windows\System32\drivers\xxxxxxx.sys
4. Run dseo13b.exe program again
5. This time select “sign a system file” and put in the location of the file you found in Device Manager
6. Repeat for all files in question then close.
7. Reboot

If all goes well, you now have your unsigned drivers working and all is well.

 

 

Posted in Computers | Leave a comment