Powershell to check check user Security Permission using Dscals

Powershell to check if  set of users for security security permission. Below script helps to check if users has Account Operators listed in security permission

$csv = Import-csv -path "D:\Krishna\dsacls\user.csv"foreach($line in $csv){$input = "\\Servername\" + $line.DN$K = .\dsacls.exe $input$i = 1foreach ($service in $K){$Status = $service -like "Allow BUILTIN\Account Operators*"if ($status -eq $true){i= 0}}if($i -eq 1){$line.mailnickname >> dcalsresult.txt}

You can also find the copy in the below link

http://powershell.com/cs/members/smtpport25.wordpress/files/UserSecurityPermission.ps1.aspx

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 to Pull out Exchange 2007 Mount Free Disk Details

In Exchange 2007 We have may have lots of DBs which we land up in creating multiple mount points instead of Drives for each Logs and Database. Below script helps to pull out the size and free size of all the mount point of the database . Change the servername and for loop with the number of Database you have.

$K = gwmi win32_volume -computername “Servername” |where-object {$_.name -like “C:\Mountpoints\DB*”}|select name,capacity,freespace

for ($i=0; $i -le 22; $i++)
{
$name = $K[$i].name
$Capacity = [math]::truncate($K[$i].capacity/1gb)
$freespace = [math]::truncate($K[$i].freespace/1gb)
$L = $name + ” ” + $Capacity  + ” ” + $freespace
write-output $L
}

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
}