Powershell to create new A Record and MX record into DNS

Powershell to Add A record and MX record into DNS. Add all the values which are given in <>

$ServerName = <DNS ServerName>

$MXrec = [WMIClass]”\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_MXType”
$server = “<DNSservername>”
$OwnerName = “<domain.Example>”
$ContainerName “<domain.Example>”
$RecordClass = $Null
$TTL = $Null
$Preference = 10
$MailExchange = “mail.domain.Example”
$$MXrec.CreateInstanceFromPropertyData($ServerName, $ContainerName,’
$OwnerName, $RecordClass, $TTL, $Preference, $MailExchange

$Arec = [WmiClass]”\\$ServerName\root\MicrosoftDNS:MicrosoftDNS_AType”
$server = “<DNSservername>”
$zone = “<zoneName>”
$name = “ArecordServerAddress”
$class = 1
$ttl = 3600
$address = “IPAddress”
$Arec.CreateInstanceFromPropertydata($server, $zone, $name, $class,’
$ttl, $address)

Powershell to Ping Given Rage of IP Address and Get the Status

Below Powershell helps to ping given set of ip address and get the result status and also provides the status of number of machines which are rechable

$ping = New-Object System.Net.NetworkInformation.Ping
$i = 0
1..255 | foreach { $ip = “192.168.1.$_”
$Res = $ping.send($ip)
if ($Res.Status -eq “Success”)
{
$result = $ip + ” = Success”
Write-Host $result
$i++
}

$Hosts = [string]$i + ” Hosts is pingable”

Write-Host $Hosts

Powershell check if Remote Machine Required Port is opened or Not

Need to make sure that PortQry is downloaded from the microsoft site and use below powershell script to check the same

http://www.microsoft.com/downloads/details.aspx?FamilyID=89811747-C74B-4638-A2D5-AC828BDC6983&displaylang=en

$Servername = Read-Host “Enter the Servername”
$PortNumber = Read-Host “Enter the Port Number”
$K = .\PortQry.exe -n $Servername -e $PortNumber -p TCP
$L = $K -Match “LIS?”
 If($L -ne $null)
{
$res = $servername + ” has ” + $PortNumbe + “Opened”
Write-Host $res

}
Else
{
$res = $servername + ” has ” + $PortNumbe + “Closed”
Write-Host $res
}

Powershell to send email with delivery notification enabled

Powershell to send email with delivery notification enabled. Once mail is delivered to the recipient mailbox and delivery notification mail will be sent to the sender mailbox. Below powershell help you to atchive the same

$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.Headers.Add(“Disposition-Notification-To”, “from@domainname.com”)
$msg.DeliveryNotificationOptions = “OnSuccess”
$msg.From = “from@domainname.com”
$msg.To.Add(”to@domainname.com”)
$msg.Subject = “Make the Delivery Recipt Work Please”
$msg.Body = “In a perfect world this email will generate a delivery receipt”
$msg.Attachments.Add($att)
$smtp.Send($msg)

Powershell to Settup ManagedFolderAssistantSchedule in all Exchange 2007 Mailbox Servers

The managed folder assistant is a Microsoft Exchange Mailbox Assistant that creates managed folders in users’ mailboxes and applies managed content settings to them. When the managed folder assistant is running, it processes all of the mailboxes on a server. If the managed folder assistant does not finish processing the mailboxes on the server during the time that you have scheduled, it automatically resumes processing where it left off the next time it runs. There is one managed folder assistant for each server

Get-ExchangeServer | Where { $_.AdminDisplayVersion.ToString().SubString(0, 10) -eq “Version 8.” `

-and $_.ServerRole -eq “Mailbox” } |

ForEach { Set-MailboxServer -Identity $_.Identity `

-ManagedFolderAssistantSchedule “Sun.1:00 AM-Sun.3:00 AM”, `

“Mon.1:00 AM-Mon.3:00 AM”, “Tue.1:00 AM-Tue.3:00 AM”, `

“Wed.1:00 AM-Wed.3:00 AM”, “Thu.1:00 AM-Thu.3:00 AM”, `

“Fri.1:00 AM-Fri.3:00 AM”, “Sat.1:00 AM-Sat.3:00 AM” }

http://technet.microsoft.com/en-us/library/bb123958.aspx

Restricting Exchange 2007 users to force outlook Cached mode

Outlook clients are used to connect to the Exchange 2007 to access email. Non – Cached Mode clients can generate a significant amount of disk I/O traffic and affect the performance of the server. Forcing all clients to use Cached Mode can Improve the  performance

Below powershell forces to apply the same for all the users

Get-Mailbox | Set-CASMailbox -MAPIBlockOutlookNonCachedMode $true

Below power shell helps to apply for the Individual users

Get-mail username | Set-CASMailbox -MAPIBlockOutlookNonCachedMode $true

Powershell to Get Exchange mailbox Database and Public Backup Status Report

Below power shell help you to get backup status of all the Exchange Database in Exchange 2007 Servers

Get-MailboxDatabase `
| where {$_.Recovery -eq $False } `
| Select-Object -Property Server, StorageGroupName, Name , LastFullBackup, LastIncrementalBackup, BackupInProgess `
| Sort-Object -Property Server, StorageGroupName, Name `
| Format-Table -AutoSize

Get-PublicFolderDatabase `
| Select-Object -Property Server, Storagegroupname, Name , LastFullBackup, LastIncrementalBackup, BackupInProgess `
| Sort-Object -Property Server, StorageGroupName, Name `
| Format-Table -AutoSize

PowerShell script will not start due to execution policy settings

PROBLEM

When you try to execute a PowerShell script the following error occurs:

File C:\scripts\myscript.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see ” get-help about_signing” for more details.

At line:1 char:23

+ c:\scripts\myscript.ps1 <<<<

CAUSE

By default the PowerShell execution policy is set to restricted, which does not allow the PowerShell Scripts to be run. There are 4 possible execution policies in PowerShell:

  • Restricted – the default setting, doesn’t allow any scripts to run.
  • AllSigned – only runs scripts which are signed by a trusted digital certificate
  • RemoteSigned – runs local scripts without requiring them to be trusted. Scripts downloaded from the Internet  must be trusted before they can run.
  • Unrestricted  – allows all scripts to run, even untrusted ones.

SOLUTION:

Use the Set-ExecutionPolicy command to “unlock” you work environment. For example if you are using a lab or learning environment you can issue the following command :

Set-ExecutionPolicy Unrestricted

IMPORTANT: This setting should not be used in a production environment because it could potentially allow scripts downloaded from internet or planted by viruses to be executed.  For a production use AllSigned or eventually Remote Signed policies

http://www.exchangemaster.net/index.php?option=com_content&task=view&id=65&Itemid=57