Friday, June 27, 2008

E-mail when passwords are going to expire

$DateTime1 = Get-Date -format "MM-dd-yyyy"
$DateTime = Get-Date -format "yyyy-MM-dd HH.mm.ss"
$PasswordExpires7Days = "PasswordExpires7Days"+"$DateTime"+".txt"

## get the Domain Policy
## for the maximum password age
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()

## get the account policy
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(objectclass=domainDNS)"
$result = $search.FindOne()

## maximum password age
$t = New-Object System.TimeSpan([System.Math]::ABS($result.properties["maxpwdage"][0]))

##get -PasswordNeverExpires
##$p = Get-QADuser -PasswordNeverExpires $false

## want all accounts where password will expire in next 7 days
## ie password was set (max password age) - 7 days ago
$d = ($t.Days)* -1 ## max password age days ago
$d1 = $d +7 ## 7 days on from max password age
Start-Transcript -path "c:\PowerShell\$PasswordExpires7Days"
Get-QADUser -IncludeAllProperties | Where {($_.PwdLastSet -gt (Get-Date).AddDays($d)) -and ($_.PwdLastSet -lt (Get-Date).AddDays($d1) -and ($_.PasswordNeverExpires -eq $false))} | Sort-Object -Property pwdLastSet -Descending | format-table Name,PwdLastSet
stop-transcript


$EmailBody1= get-content "c:\PowerShell\$PasswordExpires7Days"
$EmailBody= "c:\PowerShell\$PasswordExpires7Days"

# when done, send us an email with the log text


$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$att = new-object system.Net.Mail.Attachment($EmailBody)
$SmtpClient.Host = "sch-ca01.yourdomain.com"
$mailmessage.from = ("someone@yourdomain.com")
$mailmessage.To.add("someone@yourdomain.com")
#$mailmessage.To.add("someone@yourdomain.com,someoneelse@yourdomain.com,someoneelse@yourdomain.com")
$mailmessage.Subject = "Passwords that are going to expire " + "$DateTime1"
$mailmessage.Body = $EmailBody1
$mailmessage.Headers.Add("message-id", "<3bd50098e401463aa228377848493927-1>")
$mailmessage.Attachments.Add($att)
$smtpclient.Send($mailmessage)

Get-MailboxStatistics

Mailbox Statistics for:
MB server
Storage Group
Mailbox database

get-mailbox -Database "sch-mb02\Level 1-MB02\Level 1-MB02" |
Get-MailboxStatistics |
Where {$_.TotalItemSize -gt 400MB} |
Sort-Object -Property TotalItemSize -Descending |
Format-Table DisplayName,TotalItemSize,ItemCount,StorageLimitStatus -auto

Get-MailboxStatistics

Mailbox Statistics for 1 mb server
Get-MailboxStatistics
-Server sch-mb02 |
Where {$_.TotalItemSize -gt 900MB} |
Sort-Object -Property TotalItemSize -Descending |
Format-Table DisplayName,TotalItemSize,ItemCount,StorageLimitStatus -auto |
out-file filesize.txt

Commands to Re-Seed SCR

Commands to Re-Seed SCR

Get-StorageGroupCopyStatus -Identity:sch-mb01\Prod-mb01 -StandbyMachine:wd-mb01 |ft -auto
Suspend-StorageGroupCopy -Identity:sch-mb01\Prod-mb01 -StandbyMachine:wd-mb01 |ft -auto
update-StorageGroupCopy -Identity:sch-mb01\Prod-mb01 -StandbyMachine:wd-mb01 |ft -auto
resume-StorageGroupCopy -Identity:sch-mb01\Prod-mb01 -StandbyMachine:wd-mb01 |ft -auto

SCR Test

SCR Test

Dismount-Database sch-mb01\Prod-mb01

Restore-StorageGroupCopy sch-mb01\Prod-mb01 -StandbyMachine wd-mb01

ESEUTIL /MH M:\prod-mb01\prod-mb01.edb

ESEUTIL /R E01 /l E:\prod-mb01 /S M:\prod-mb01 /a

Move-StorageGroupPath wd-mb01\SG1PORT -SystemFolderPath "C:\Program Files\Microsoft\Exchange Server\Mailbox\sg1Port" -LogFolderPath "E:\prod-mb01" –ConfigurationOnly

Move-DatabasePath wd-mb01\SG1PORT\MBX1PORT -EdbFilePath "M:\prod-mb01\prod-mb01.edb" –ConfigurationOnly

Set-MailboxDatabase wd-mb01\SG1PORT\MBX1PORT -AllowFileRestore:$true

Mount-Database wd-mb01\SG1PORT\MBX1PORT

Get-Mailbox -Database sch-mb01\Prod-mb01\Prod-mb01 |where {$_.ObjectClass -NotMatch '(SystemAttendantMailbox|ExOleDbSystemMailbox)'}| Move-Mailbox -ConfigurationOnly -TargetDatabase wd-mb01\SG1PORT\MBX1PORT