SQL – List Primary key and Concatenate composite Keys into a single row separed by comma

The following query lists all the Primary keys of all the table. 

OP has requested to list all PK and composite PKs and concatenate all it’s composite PK column values into a single row separated by comma hence this post.

 
SELECT TAB.TABLE_NAME,COL.COLUMN_NAME  
FROM 
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS TAB,  
    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE COL  
WHERE  
    COL.CONSTRAINT_NAME = TAB.CONSTRAINT_NAME 
    AND COL.TABLE_NAME = TAB.TABLE_NAME 
    AND CONSTRAINT_TYPE = 'PRIMARY KEY' 
 
 
 
 In the above screenshot  the invoices and PK_TEST table has composite PK’s. Query to get the Composite PKs in a single row separated by comma
 
SELECT TABLENAME, 
       LEFT(COL,LEN(COL)-1) AS COLUMN_NAME 
FROM 
( 
        SELECT DISTINCT TAB.TABLE_NAME TABLENAME, 
            ( 
            SELECT COL.COLUMN_NAME +','  AS [text()] 
            FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE COL  
            WHERE  
                COL.CONSTRAINT_NAME = TAB.CONSTRAINT_NAME AND COL.TABLE_NAME = TAB.TABLE_NAME AND CONSTRAINT_TYPE = 'PRIMARY KEY' 
             FOR XML PATH ('') 
            ) COL 
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS TAB 
 )T 
 where T.COL is NOT NULL 
 

 

 

Posted in SQL | Tagged , , , | 1 Comment

USING SQL & POWERSHELL – Different Methods to List Databases WITH Recovery Models

USING POWERSHELL TO LIST SQLSERVER USER DATABASES WITH RECOVERY MODELS

One of op requested to list all the user defined databases where it has been configured with simple recovery model across ‘N’ servers.There are many ways to achieve the requirement. 

You can query sys.databases with sqlcmd utility to list all the details

SQL
select name,recovery_model_desc from sys.databases where database_id > 4 and recovery_model_desc='SIMPLE'
SQL
Master..xp_cmdshell 'for /f %j in (c :\servers.txt ) do sqlcmd -S %j  
-Q "select name,recovery_model_desc from sys.databases where database_id > 4 and recovery_model_desc=''SIMPLE''"  
-E'
 Download the code: -
 

Output:-

OR

Using Powershell

The function Get-RecoveryModel has three input parameters

  1. InputFile – List contains all the servers
  2. Recoverymodel – type of the recovery model that you want to do a search
  3. Database Flag – (TRUE OR FALSE – Include or exclude system databases )
PowerShell Script
<#  
.SYNOPSIS  
    USING POWERSHELL TO LIST SQLSERVER USER DATABASES WITH SIMPLE RECOVERY 
.DESCRIPTION  
    The function call requires three parameters Inputfile, RecoveryModel(Full,simple,bulklogged) and Database flag ($TRUE=System Database,$FALSE=User Database)  
.EXAMPLE 
    1.PS:\>Get-RecoveryModel -InputFile F:\PowerSQL\Server.txt -RecoveryModel "SIMPLE" -DatabaseFlag $FALSE 
    2.PS:\>Get-RecoveryModel -InputFile F:\PowerSQL\Server.txt -RecoveryModel "FULL" -DatabaseFlag $TRUE     
.NOTES  
    Author     : Powershellsql@gmail.com 
.LINK  
    http://sqlpowershell.wordpress.com/ 
#>  
  
  
Function Get-RecoveryModel 
{ 
param( 
    $InputFile, 
    $RecoveryModel, 
    $DatabaseFlag 
) 
 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO"| Out-Null 
  
 ForEach ($instance in Get-Content $InputFile) 
{ 
       $s = New-Object ('Microsoft.SqlServer.Management.Smo.Server'$instance 
       $dbs=$s.Databases| where {$_.RecoveryModel -like "$RecoveryModel" -and  $_.IsSystemObject -eq $DatabaseFlag } 
       $dbs | select @{Name="ServerName"; Expression = {$Instance}}, Name, RecoveryModel 
} 
} 
 

Function call:-

PS:\>Get-RecoveryModel -InputFile F:\PowerSQL\Server.txt -RecoveryModel "SIMPLE" -DatabaseFlag $FALSE 
PS:\>Get-RecoveryModel -InputFile F:\PowerSQL\Server.txt -RecoveryModel "FULL" -DatabaseFlag $TRUE     
 Converting the output to HTML
$OutputFile = "F:\PowerSQL\RecoveryModel.htm" 
$ServerList = "F:\PowerSQL\Server.txt" 
 
$a = "" 
$a = $a + "BODY{background-color:peachpuff;}" 
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" 
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" 
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" 
$a = $a + "" 
 
Function Get-RecoveryModel 
{ 
param( 
    $InputFile, 
    $RecoveryModel, 
    $DatabaseFlag 
) 
 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO"| Out-Null 
  
 ForEach ($instance in Get-Content $InputFile) 
{ 
       $s = New-Object ('Microsoft.SqlServer.Management.Smo.Server'$instance 
       $dbs=$s.Databases| where {$_.RecoveryModel -like "$RecoveryModel" -and  $_.IsSystemObject -eq $DatabaseFlag } 
       $dbs | select @{Name="ServerName"; Expression = {$Instance}}, Name, RecoveryModel 
} 
} 
 
Get-RecoveryModel -InputFile $ServerList -RecoveryModel "SIMPLE" -DatabaseFlag $FALSE|ConvertTo-HTML -head $a -body "<H2>Database Recovery Model Information</H2>" | Out-File $OutputFile 
 
Output:-
 
 

Posted in Uncategorized | Leave a comment

PowerShell- Monitoring Group Of Services on Group of Servers with Alternate Credential

This post explains how to monitor a multiple services on a group of servers with alternate credentials.

This script will allow you to read a list of servers from the input file and use credentials to connect remote/DMZ servers to pull service status information for a set of specific services and send services status information to all intended recipients

Get-Service cmdlet don’t accept credentials parameter hence I’ve used win32_service win32 class which accepts the credential parameter. You need to comment or uncomment the required portion of code.

Most of the time it’s not good practice to hard code the credentials. In that case you might need encrypt the password and use the secured code in the script. You need to run the below Powershell script to pull the encrypted password to c:\SecurePassword.txt and copy code in the script.

$password = read-host -prompt "Enter your Password"  
$secure = ConvertTo-SecureString $password -force -asPlainText  
ConvertFrom-SecureString $secure |Out-File c:\SecurePassword.txt
 In the below example, Test@2013##) password is encrypted and it’s content is shown below
 

 There are some instance where you are OK to store the password in the script itself. 

Refer the below screenshot and change the code according to your requirement

 

The Get-ServiceStatusReport

  1. Credential to connect to DMZ server
  2. HTML Ouptut
  3. Email Address validation

 The Function Get-ServiceStatusReport contains five parameters

  1. ComputerList – List of Servers
  2. ServiceName – Name of Services separated by comma
  3. SMTPMail – SMTP mail address
  4. FromID – Valid Email ID
  5. ToID – Valid Email ID

 Download the code 

http://gallery.technet.microsoft.com/PowerShell-Group-Of-d0010648

Sample Call:-

Get-ServiceStatusReport -ComputerList C:\servers.txt -includeService  “Dfs”,”Dhcp” -To <pjayaram@app.com> -From <pjayaram@app.com> -SMTPMail <SMTPMail>

Output:-

 

You can also refer the below link if you want to run the script with default account

http://sqlpowershell.wordpress.com/2013/12/04/powershell-monitoring-multiple-service-on-a-group-of-servers/

 

 

PowerShell
<# 
The Function Get-ServiceStatusReport contains five parameters 
 
ComputerList – List of Servers 
ServiceName – Name of Services separated by comma 
SMTPMail – SMTP mail address 
FromID – Valid Email ID 
ToID – Valid Email ID 
 
Sample Call:- 
 
Get-ServiceStatusReport  
-ComputerList C:\servers.txt  
-includeService  "Dfs","Dhcp"  
-To <pjayaram@app.com> 
-From <pjayaram@app.com> 
-SMTPMail <SMTPMail> 
#> 
 
Function Get-ServiceStatusReport 
{ 
param( 
[String]$ComputerList,[String[]]$includeService,[String]$To,[String]$From,[string]$SMTPMail 
) 
 
$script:list = $ComputerList 
  
$ServiceFileName"c:\ServiceFileName.htm" 
 
New-Item -ItemType file $ServiceFilename -Force 
 
 
# Enter the Credentials details 
<# 
$password = read-host -prompt "Enter your Password"  
write-host "$password is password"  
$secure = ConvertTo-SecureString $password -force -asPlainText  
ConvertFrom-SecureString $secure |Out-File c:\SecurePassword.txt 
#> 
 
#Replace the $encrypted value from the contents of c:\SecurePassword.txt  
 
$encrypted = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000efa85d14f32d8648a2d335e29d3f57f6b"  
$user = "testwint"  
$password = ConvertTo-SecureString -string $encrypted  
$Credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$password 
 
<# Hard code the the Credentials details 
 
$User = “testcog” 
$Pass = ConvertTo-SecureString “testasd#%)” -AsPlainText -Force 
#contain the username and password in a variable 
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Pass 
 
#> 
 
# Function to write the HTML Header to the file 
Function writeHtmlHeader 
{ 
param($fileName$date = ( get-date ).ToString('yyyy/MM/dd'Add-Content $fileName "<html>" 
Add-Content $fileName "<head>" 
Add-Content $fileName "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>" 
Add-Content $fileName '<title>Service Status Report </title>' 
add-content $fileName '<STYLE TYPE="text/css">' 
add-content $fileName  "<!--" 
add-content $fileName  "td {" 
add-content $fileName  "font-family: Tahoma;" 
add-content $fileName  "font-size: 11px;" 
add-content $fileName  "border-top: 1px solid #999999;" 
add-content $fileName  "border-right: 1px solid #999999;" 
add-content $fileName  "border-bottom: 1px solid #999999;" 
add-content $fileName  "border-left: 1px solid #999999;" 
add-content $fileName  "padding-top: 0px;" 
add-content $fileName  "padding-right: 0px;" 
add-content $fileName  "padding-bottom: 0px;" 
add-content $fileName  "padding-left: 0px;" 
add-content $fileName  "}" 
add-content $fileName  "body {" 
add-content $fileName  "margin-left: 5px;" 
add-content $fileName  "margin-top: 5px;" 
add-content $fileName  "margin-right: 0px;" 
add-content $fileName  "margin-bottom: 10px;" 
add-content $fileName  "" 
add-content $fileName  "table {" 
add-content $fileName  "border: thin solid #000000;" 
add-content $fileName  "}" 
add-content $fileName  "-->" 
add-content $fileName  "</style>" 
Add-Content $fileName "</head>" 
Add-Content $fileName "<body>" 
 
add-content $fileName  "<table width='100%'>" 
add-content $fileName  "<tr bgcolor='#CCCCCC'>" 
add-content $fileName  "<td colspan='4' height='25' align='center'>" 
add-content $fileName  "<font face='tahoma' color='#003399' size='4'><strong>Service Stauts Report - $date</strong></font>" 
add-content $fileName  "</td>" 
add-content $fileName  "</tr>" 
add-content $fileName  "</table>" 
 
} 
 
# Function to write the HTML Header to the file 
Function writeTableHeader 
{ 
param($fileName) 
 
Add-Content $fileName "<tr bgcolor=#CCCCCC>" 
Add-Content $fileName "<td width='10%' align='center'>ServerName</td>" 
Add-Content $fileName "<td width='50%' align='center'>Service Name</td>" 
Add-Content $fileName "<td width='10%' align='center'>status</td>" 
Add-Content $fileName "</tr>" 
} 
 
Function writeHtmlFooter 
{ 
param($fileName) 
 
Add-Content $fileName "</body>" 
Add-Content $fileName "</html>" 
} 
 
Function writeDiskInfo 
{ 
param($filename,$Servername,$name,$Statusif$status -eq "Stopped") 
{ 
 Add-Content $fileName "<tr>" 
 Add-Content $fileName "<td bgcolor='#FF0000' align=left ><b>$servername</td>" 
 Add-Content $fileName "<td bgcolor='#FF0000' align=left ><b>$name</td>" 
 Add-Content $fileName "<td bgcolor='#FF0000' align=left ><b>$Status</td>" 
 Add-Content $fileName "</tr>" 
} 
else 
{ 
Add-Content $fileName "<tr>" 
 Add-Content $fileName "<td >$servername</td>" 
 Add-Content $fileName "<td >$name</td>" 
 Add-Content $fileName "<td >$Status</td>" 
Add-Content $fileName "</tr>" 
} 
 
} 
 
 
 
 
writeHtmlHeader $ServiceFileName 
 Add-Content $ServiceFileName "<table width='100%'><tbody>" 
 Add-Content $ServiceFileName "<tr bgcolor='#CCCCCC'>" 
 Add-Content $ServiceFileName "<td width='100%' align='center' colSpan=3><font face='tahoma' color='#003399' size='2'><strong> Service Details</strong></font></td>" 
 Add-Content $ServiceFileName "</tr>" 
 
 writeTableHeader $ServiceFileName 
 
 
#Change value of the following parameter as needed 
 
$InlcudeArray=@() 
 
 
#List of programs to include 
 
#$InlcudeArray = $inlcudeService 
 
Foreach($ServerName in (Get-Content $script:list)) 
{ 
$service = Get-WMIObject Win32_Service -computer $ServerName -credential $Credentials 
if ($Service -ne $NULL) 
{ 
foreach ($item in $service) 
 { 
 #$item.DisplayName 
 Foreach($include in $includeService)  
     {                        
 write-host $inlcude                                     
 if(($item.Name).Contains($include-eq $TRUE) 
    { 
    Write-Host  $item.MachineName $item.name $item.Status  
    writeDiskInfo $ServiceFileName $ServerName $item.name $item.Status  
    } 
    } 
 } 
} 
} 
     
 
Add-Content $ServiceFileName "</table>"  
 
writeHtmlFooter $ServiceFileName 
 
function Validate-IsEmail ([string]$Email) 
{ 
                 
                return $Email -match "^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$" 
} 
 
 
Function sendEmail   
{  
param($from,$to,$subject,$smtphost,$htmlFileName)   
[string]$receipients="$to" 
$body = Get-Content $htmlFileName  
$body = New-Object System.Net.Mail.MailMessage $from$receipients$subject$body  
$body.isBodyhtml = $true 
$smtpServer = $MailServer 
$smtp = new-object Net.Mail.SmtpClient($smtphost$validfrom= Validate-IsEmail $from 
if($validfrom -eq $TRUE) 
{ 
$validTo= Validate-IsEmail $to 
if($validTo -eq $TRUE) 
{ 
$smtp.Send($body) 
write-output "Email Sent!!" 
 
} 
} 
else 
{ 
write-output "Invalid entries, Try again!!" 
} 
} 
 
$date = ( get-date ).ToString('yyyy/MM/dd') 
 
sendEmail -from $From -to $to -subject "Service Status - $Date" -smtphost $SMTPMail -htmlfilename $ServiceFilename 
 
} 
Posted in Uncategorized | 1 Comment

PowerShell – Perfmon Counters into CSV File – Multiple remote servers

Introduction

This script can be used for exporting specified performance counter values from multiple remote target servers to CSV file. The challenge is to gather the specific counter information and append it to CSV file with Powershell2.0.

Performance counters

The script will pull the below mentioned counter values

  • Processor (_total)\% processor time
  • system\processor queue length
  • Memory\Available MBytes
  • Memory\% committed bytes in use
  • PhysicalDisk (*)\Current Disk Queue Length
  • PhysicalDisk (*)\Avg. Disk sec/Transfer
  • PhysicalDisk (*)\% Disk Time
  • PhysicalDisk (*)\Disk Read Bytes/sec
  • PhysicalDisk (*)\Disk Write Bytes/sec
  • Network Interface (*)\Bytes Total/sec

 Scenarios

IT Administrators may want to analyze the performance the servers with the help of perfmon counters information’s.

 Prerequisites

  • The source machine should have PowerShell 2.0 installed

Download the code:- http://gallery.technet.microsoft.com/PowerShell-Perfmon-0f013da8

Script

You can use this script in following ways:

1. Download the script.

2. Open the script file with Notepad or any other script editors (preferably Windows PowerShell ISE)

3.  Change the Input file path and Output file if required other than the default location as shown in below screenshot.

4. Counters can be selected based on your requirement by changing the below code

5. Save the file then run the script via PowerShell in “Run as administrator” mode.

 

 You can run this script manually or by scheduler task

 

How to create a scheduler task:

1. Open “Task Scheduler” (Goto START—RUN —Type Tasks and hit enter)

2. Click “Create task”

3. Pick a name, and choose “Run whether user is logged on or not”

 

Choose “Triggers” Tab, Click “New”

5. Specify option you like, and then click “OK” to create a trigger

 

Choose “Actions” tab, Click “New”

7. Copy following command to “Program/script” textbox, click C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

8Enter the path of the saved script file in “Add arguments (optionally)” textbox

As per the screenshot I saved the file under C:\Perform_script.ps1 hence I updated the add arguments text box as

C:\Perform_script.ps1; exit” 

 

Code:

 

<# 
# Script: Get-CounterStats 
# Author: Prashanth and Praveen 
# Comments: This script will collect the specific counters value from the multiple target machines/servers  
which will be used to analayze the performance of target servers. 
#> 
 
 
 
#Define Input and output filepath 
 
$servers=get-content "C:\servers.txt" 
$outfile="C:\perfmon.csv" 
 
################################################################################################################ 
 
 
################################################################################################################ 
 
 
#Actual script starts here  
 
function Global:Convert-HString {       
[CmdletBinding()]             
 Param              
   ( 
    [Parameter(Mandatory=$false, 
               ValueFromPipeline=$true, 
               ValueFromPipelineByPropertyName=$true)] 
    [String]$HString 
   )#End Param 
 
Begin  
{ 
    Write-Verbose "Converting Here-String to Array" 
}#Begin 
Process  
{ 
    $HString -split "`n" | ForEach-Object { 
     
        $ComputerName = $_.trim() 
        if ($ComputerName -notmatch "#") 
            { 
                $ComputerName 
            }     
         
         
        } 
}#Process 
End  
{ 
    # Nothing to do here. 
}#End 
 
}#Convert-HString 
 
 
#Function to have the customized output in CSV format 
function Export-CsvFile { 
[CmdletBinding(DefaultParameterSetName='Delimiter', 
  SupportsShouldProcess=$true, ConfirmImpact='Medium')] 
param( 
[Parameter(Mandatory=$true, ValueFromPipeline=$true, 
           ValueFromPipelineByPropertyName=$true)] 
[System.Management.Automation.PSObject] 
${InputObject}, 
 
[Parameter(Mandatory=$true, Position=0)] 
[Alias('PSPath')] 
[System.String] 
${Path}, 
 
#region -Append  
[Switch${Append}, 
#endregion  
 
[Switch${Force}, 
 
[Switch${NoClobber}, 
 
[ValidateSet('Unicode','UTF7','UTF8','ASCII','UTF32','BigEndianUnicode','Default','OEM')] 
[System.String] 
${Encoding}, 
 
[Parameter(ParameterSetName='Delimiter', Position=1)] 
[ValidateNotNull()] 
[System.Char] 
${Delimiter}, 
 
[Parameter(ParameterSetName='UseCulture')] 
[Switch${UseCulture}, 
 
[Alias('NTI')] 
[Switch${NoTypeInformation}) 
 
begin 
{ 
# This variable will tell us whether we actually need to append 
# to existing file 
$AppendMode = $false 
 
 try { 
  $outBuffer = $null 
  if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) 
  { 
      $PSBoundParameters['OutBuffer'] = 1 
  } 
  $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Export-Csv', 
    [System.Management.Automation.CommandTypes]::Cmdlet) 
         
         
                #String variable to become the target command line 
                $scriptCmdPipeline = '' 
 
                # Add new parameter handling 
                #region Dmitry: Process and remove the Append parameter if it is present 
                if ($Append) { 
   
                                $PSBoundParameters.Remove('Append'| Out-Null 
     
  if ($Path) { 
   if (Test-Path $Path) {         
    # Need to construct new command line 
    $AppendMode = $true 
     
    if ($Encoding.Length -eq 0) { 
     # ASCII is default encoding for Export-CSV 
     $Encoding = 'ASCII' 
    } 
     
    # For Append we use ConvertTo-CSV instead of Export 
    $scriptCmdPipeline +'ConvertTo-Csv -NoTypeInformation ' 
     
    # Inherit other CSV convertion parameters 
    if ( $UseCulture ) { 
     $scriptCmdPipeline +' -UseCulture ' 
    } 
    if ( $Delimiter ) { 
     $scriptCmdPipeline +" -Delimiter '$Delimiter' " 
    }  
     
    # Skip the first line (the one with the property names)  
    $scriptCmdPipeline +' | Foreach-Object {$start=$true}' 
    $scriptCmdPipeline +'{if ($start) {$start=$false} else {$_}} ' 
     
    # Add file output 
    $scriptCmdPipeline +" | Out-File -FilePath '$Path' -Encoding '$Encoding' -Append " 
     
    if ($Force) { 
     $scriptCmdPipeline +' -Force' 
    } 
 
    if ($NoClobber) { 
     $scriptCmdPipeline +' -NoClobber' 
    }    
   } 
  } 
}  
   
 
   
 $scriptCmd = {& $wrappedCmd @PSBoundParameters } 
 
 if ( $AppendMode ) { 
  # redefine command line 
  $scriptCmd = $ExecutionContext.InvokeCommand.NewScriptBlock( 
      $scriptCmdPipeline 
    ) 
} else { 
  # execute Export-CSV as we got it because 
  # either -Append is missing or file does not exist 
  $scriptCmd = $ExecutionContext.InvokeCommand.NewScriptBlock( 
      [string]$scriptCmd 
    ) 
} 
 
# standard pipeline initialization 
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) 
$steppablePipeline.Begin($PSCmdlet) 
 
 } catch { 
   throw 
} 
     
} 
 
process 
{ 
  try { 
      $steppablePipeline.Process($_) 
  } catch { 
      throw 
  } 
} 
 
end 
{ 
  try { 
      $steppablePipeline.End() 
  } catch { 
      throw 
  } 
} 
 
} 
 
#Performance counters declaration 
 
function Get-CounterStats {  
param  
    (  
    [String]$ComputerName = $ENV:ComputerName 
     
    )  
 
$Object =@() 
 
 
$Counter = @"  
Processor(_total)\% processor time  
system\processor queue length 
Memory\Available MBytes  
Memory\% committed bytes in use 
PhysicalDisk(*)\Current Disk Queue Length  
PhysicalDisk(*)\Avg. Disk sec/Transfer  
PhysicalDisk(*)\% Disk Time  
PhysicalDisk(*)\Disk Read Bytes/sec  
PhysicalDisk(*)\Disk Write Bytes/sec  
Network Interface(*)\Bytes Total/sec  
"@  
 
        (Get-Counter -ComputerName $ComputerName -Counter (Convert-HString -HString $Counter)).counterSamples |   
        ForEach-Object {  
        $path = $_.path  
        New-Object PSObject -Property @{ 
        computerName=$ComputerName; 
        Counter        = ($path  -split "\\")[-2,-1] -join "-" ; 
        Item        = $_.InstanceName ; 
        Value = [Math]::Round($_.CookedValue,2)  
        datetime=(Get-Date -format "yyyy-MM-d hh:mm:ss") 
        }  
         
        } 
      
    
}  
 
#Collecting counter information for target servers 
 
foreach($server in $Servers) 
{ 
$d=Get-CounterStats -ComputerName $server |Select-Object computerName,Counter,Item,Value,datetime 
$d |Export-CsvFile $outfile  -Append -NoTypeInformation 
 
} 
 
#End of Script
 

Output:-


 

 

 

 

Posted in Uncategorized | 3 Comments

PowerShell – OS Inventory and Disk Info – Consolidated Excel File – EMAIL

This script is used to discover all the server information and captures disk drive utilization details. The drive details are aggregated based on the status of free space. The aggregated data is pictorially represented using pie chart. The excel sheet is then send to intended users.

The script requires input file where all the servers are listed. You can also populate the server list by quering AD. The script will try to communicate all the servers which are listed in the input file to get the required information

Script Server Inventory on sheet1 and Disk Information on sheet2
Directory It checks for the directory C:\Scripts\ and create a one if it doesn’t exists.
Source File GetAllOsDrSrvInfo.PS1
Input File E:\Scripts\InputServer.txt
Output Excel sheet as an attachment
Email Notification Yes
Recipients More than one recipients can be separated by comma
SMTPMail SMTP address
Functionality Discovery all the server information and consolidate the data  in a excel sheet

Change the first few lines of colored code as per your requirement and change the alert threshold in the bottom of the code

#### Spreadsheet Location and email sending details

 $DirectoryToSaveTo = “c:\”

 $date=Get-Date -format “yyyy-MM-d”

 $Filename=”serverinfo-$($date)”

 $FromEmail=”<ToEmail>”

 $ToEmail=”<FromEmail>”

 $SMTPMail=”<SMTP MAIL>”

 ###InputLocation

 $Computers = Get-Content “c:\server.txt”

###################

The code is tested on Powershell 2.0 onwards

Download the code : – OS and DiskInfo

 Code:-

  
#### Spreadsheet Location 
 $DirectoryToSaveTo = "c:\" 
 $date=Get-Date -format "yyyy-MM-d" 
 $Filename="serverinfo-$($date)" 
 $FromEmail="<ToEmail>" 
 $ToEmail="<FromEmail>" 
 $SMTPMail="<SMTP MAIL>" 
  
 ###InputLocation 
 $Computers = Get-Content "c:\server.txt" 
  
  
# before we do anything else, are we likely to be able to save the file? 
# if the directory doesn't exist, then create it 
if (!(Test-Path -path "$DirectoryToSaveTo")) #create it if not existing 
  { 
  New-Item "$DirectoryToSaveTo" -type directory | out-null 
  } 
   
 
 
#Create a new Excel object using COM  
$Excel = New-Object -ComObject Excel.Application 
$Excel.visible = $True 
$Excel = $Excel.Workbooks.Add() 
$Sheet = $Excel.Worksheets.Item(1) 
 
$sheet.Name = 'Server Inventory' 
#Create a Title for the first worksheet 
$row = 1 
$Column = 1 
$Sheet.Cells.Item($row,$column)= 'Server Inventory' 
 
$range = $Sheet.Range("a1","s2"$range.Merge() | Out-Null 
$range.VerticalAlignment = -4160 
 
#Give it a nice Style so it stands out 
$range.Style = 'Title' 
 
#Increment row for next set of data 
$row++;$row++ 
 
#Save the initial row so it can be used later to create a border 
#Counter variable for rows 
$intRow = $row 
$xlOpenXMLWorkbook=[int]51 
 
#Read thru the contents of the SQL_Servers.txt file 
 
$Sheet.Cells.Item($intRow,1)  ="Name" 
$Sheet.Cells.Item($intRow,2)  ="status" 
$Sheet.Cells.Item($intRow,3)  ="OS" 
$Sheet.Cells.Item($intRow,4)  ="Domain Role" 
$Sheet.Cells.Item($intRow,5)  ="ProcessorName" 
$Sheet.Cells.Item($intRow,6)  ="Manufacturer" 
$Sheet.Cells.Item($intRow,7)  ="Model" 
$Sheet.Cells.Item($intRow,8)  ="SystemType" 
$Sheet.Cells.Item($intRow,9)  ="Last Boot Time" 
$Sheet.Cells.Item($intRow,10) ="Bios Version" 
$Sheet.Cells.Item($intRow,11) ="CPU Info" 
$Sheet.Cells.Item($intRow,12) ="NoOfProcessors" 
$Sheet.Cells.Item($intRow,13) ="Total Physical Memory" 
$Sheet.Cells.Item($intRow,14) ="Total Free Physical Memory" 
$Sheet.Cells.Item($intRow,15) ="Total Virtual Memory" 
$Sheet.Cells.Item($intRow,16) ="Total Free Virtual Memory" 
$Sheet.Cells.Item($intRow,17) ="Disk Info" 
$Sheet.Cells.Item($intRow,18) ="FQDN" 
$Sheet.Cells.Item($intRow,19) ="IPAddress" 
 
for ($col = 1; $col –le 19; $col++) 
     { 
          $Sheet.Cells.Item($intRow,$col).Font.Bold = $True 
          $Sheet.Cells.Item($intRow,$col).Interior.ColorIndex = 48 
          $Sheet.Cells.Item($intRow,$col).Font.ColorIndex = 34 
     } 
 
$intRow++ 
 
 
Function GetStatusCode 
{  
    Param([int] $StatusCode)   
    switch($StatusCode) 
    { 
        0         {"Success"} 
        11001   {"Buffer Too Small"} 
        11002   {"Destination Net Unreachable"} 
        11003   {"Destination Host Unreachable"} 
        11004   {"Destination Protocol Unreachable"} 
        11005   {"Destination Port Unreachable"} 
        11006   {"No Resources"} 
        11007   {"Bad Option"} 
        11008   {"Hardware Error"} 
        11009   {"Packet Too Big"} 
        11010   {"Request Timed Out"} 
        11011   {"Bad Request"} 
        11012   {"Bad Route"} 
        11013   {"TimeToLive Expired Transit"} 
        11014   {"TimeToLive Expired Reassembly"} 
        11015   {"Parameter Problem"} 
        11016   {"Source Quench"} 
        11017   {"Option Too Big"} 
        11018   {"Bad Destination"} 
        11032   {"Negotiating IPSEC"} 
        11050   {"General Failure"} 
        default {"Failed"} 
    } 
} 
 
 
Function GetUpTime 
{ 
    param([string] $LastBootTime) 
    $Uptime = (Get-Date- [System.Management.ManagementDateTimeconverter]::ToDateTime($LastBootTime) 
    "Days: $($Uptime.Days); Hours: $($Uptime.Hours); Minutes: $($Uptime.Minutes); Seconds: $($Uptime.Seconds)"  
} 
 
     
     
 
 
 
foreach ($Computer in $Computers) 
 { 
 
 TRY { 
 $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer 
 $Bios = Get-WmiObject -Class Win32_BIOS -ComputerName $Computer 
 $sheetS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer 
 $sheetPU = Get-WmiObject -Class Win32_Processor -ComputerName $Computer 
 $drives = Get-WmiObject -ComputerName $Computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} 
 $pingStatus = Get-WmiObject -Query "Select * from win32_PingStatus where Address='$Computer'" 
 $IPAddress=(Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}).ipaddress 
 $FQDN=[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name 
 $OSRunning = $OS.caption + " " + $OS.OSArchitecture + " SP " + $OS.ServicePackMajorVersion 
 $NoOfProcessors=$sheetS.numberofProcessors 
 $name=$SheetPU|select name -First 1 
 $Manufacturer=$sheetS.Manufacturer 
 $Model=$sheetS.Model 
 $systemType=$sheetS.SystemType 
 $ProcessorName=$SheetPU|select name -First 1 
 $DomainRole = $sheetS.DomainRole 
 $TotalAvailMemory = $OS.totalvisiblememorysize/1kb 
 $TotalVirtualMemory = $OS.totalvirtualmemorysize/1kb 
 $TotalFreeMemory = $OS.FreePhysicalMemory/1kb 
 $TotalFreeVirtualMemory = $OS.FreeVirtualMemory/1kb 
 $TotalMem = "{0:N2}" -$TotalAvailMemory 
 $TotalVirt = "{0:N2}" -$TotalVirtualMemory 
 $FreeMem = "{0:N2}" -$TotalFreeMemory 
 $FreeVirtMem = "{0:N2}" -$TotalFreeVirtualMemory 
 $date = Get-Date 
 $uptime = $OS.ConvertToDateTime($OS.lastbootuptime) 
 $BiosVersion = $Bios.Manufacturer + " " + $Bios.SMBIOSBIOSVERSION + " " + $Bios.ConvertToDateTime($Bios.Releasedate) 
 $sheetPUInfo = $name.Name + " & has " + $sheetPU.NumberOfCores + " Cores & the FSB is " + $sheetPU.ExtClock + " Mhz" 
 $sheetPULOAD = $sheetPU.LoadPercentage 
  
 if($pingStatus.StatusCode -eq 0) 
    { 
        $Status = GetStatusCode( $pingStatus.StatusCode ) 
    } 
else 
    { 
    $Status = GetStatusCode( $pingStatus.StatusCode ) 
       } 
     
     
 if (($DomainRole -eq "0"-or ($DomainRole -eq "1")) 
 { 
 $Role = "Work Station" 
 } 
 elseif (($DomainRole -eq "2"-or ($DomainRole -eq "3")) 
 { 
 $Role = "Member Server" 
 } 
 elseif (($DomainRole -eq "4"-or ($DomainRole -eq "5")) 
 { 
 $Role = "Domain Controller" 
 } 
 else 
 { 
 $Role = "Unknown" 
 } 
 } 
 CATCH 
 { 
 $pcnotfound = "true" 
 } 
 #### Pump Data to Excel 
 if ($pcnotfound -eq "true") 
 { 
 $sheet.Cells.Item($intRow, 1) = "$($computer) Not Found " 
 } 
 else 
 { 
 $sheet.Cells.Item($intRow, 1) = $computer 
 $sheet.Cells.Item($intRow, 2) = $status 
 $sheet.Cells.Item($intRow, 3) = $OSRunning 
 $sheet.Cells.Item($intRow, 4) = $Role 
 $sheet.Cells.Item($intRow, 5) = $name.name 
 $Sheet.Cells.Item($intRow, 6) = $Manufacturer 
 $Sheet.Cells.Item($intRow, 7) = $Model 
 $Sheet.Cells.Item($intRow, 8) = $SystemType 
 $sheet.Cells.Item($intRow, 9) = $uptime 
 $sheet.Cells.Item($intRow, 10)= $BiosVersion 
 $sheet.Cells.Item($intRow, 11)= $sheetPUInfo 
 $sheet.Cells.Item($intRow, 12)=$NoOfProcessors 
 $sheet.Cells.Item($intRow, 13)= "$TotalMem MB" 
 $sheet.Cells.Item($intRow, 14)= "$FreeMem MB" 
 $sheet.Cells.Item($intRow, 15)= "$TotalVirt MB" 
 $sheet.Cells.Item($intRow, 16)= "$FreeVirtMem MB" 
 $sheet.Cells.Item($intRow, 19)=$IPAddress 
 $sheet.Cells.Item($intRow, 18)=$FQDN 
 
  
$driveStr = "" 
 foreach($drive in $drives) 
 { 
 $size1 = $drive.size / 1GB 
 $size = "{0:N2}" -$size1 
 $free1 = $drive.freespace / 1GB 
 $free = "{0:N2}" -$free1 
 $freea = $free1 / $size1 * 100 
 $freeb = "{0:N2}" -$freea 
 $ID = $drive.DeviceID 
 $driveStr +"$ID = Total Space: $size GB / Free Space: $free GB / Free (Percent): $freeb % ` " 
 } 
 $sheet.Cells.Item($intRow, 17) = $driveStr 
 } 
 
  
$intRow = $intRow + 1 
 $pcnotfound = "false" 
 } 
 
$erroractionpreference = “SilentlyContinue”  
 
$Sheet.UsedRange.EntireColumn.AutoFit() 
########################################333 
 
$Sheet = $Excel.Worksheets.Item(2) 
$sheet.Name = 'DiskSpace' 
$Sheet.Activate() | Out-Null 
 
#Create a Title for the first worksheet 
$row = 1 
$Column = 1 
$Sheet.Cells.Item($row,$column)= 'Disk Space Information' 
 
$range = $Sheet.Range("a1","h2"$range.Merge() | Out-Null 
$range.VerticalAlignment = -4160 
 
#Give it a nice Style so it stands out 
$range.Style = 'Title' 
 
#Increment row for next set of data 
$row++;$row++ 
 
#Save the initial row so it can be used later to create a border 
$initalRow = $row 
 
#Create a header for Disk Space Report; set each cell to Bold and add a background color 
$Sheet.Cells.Item($row,$column)= 'Computername' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
$Column++ 
$Sheet.Cells.Item($row,$column)= 'DeviceID' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
$Column++ 
$Sheet.Cells.Item($row,$column)= 'VolumeName' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
$Column++ 
$Sheet.Cells.Item($row,$column)= 'TotalSizeGB' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
$Column++ 
$Sheet.Cells.Item($row,$column)= 'UsedSpaceGB' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
$Column++ 
$Sheet.Cells.Item($row,$column)= 'FreeSpaceGB' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
$Column++ 
$Sheet.Cells.Item($row,$column)= '%Free' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
$Column++ 
$Sheet.Cells.Item($row,$column)= 'State' 
$Sheet.Cells.Item($row,$column).Interior.ColorIndex =48 
$Sheet.Cells.Item($row,$column).Font.Bold=$True 
 
#Set up a header filter 
$headerRange = $Sheet.Range("a3","h3"$headerRange.AutoFilter() | Out-Null 
 
#Increment Row and reset Column back to first column 
$row++ 
$Column = 1 
$critical=0 
$warning=0 
$good=0 
 
#Get the drives and filter out CD/DVD drives 
foreach ($computer in $Computers) 
 { 
$diskDrives = Get-WmiObject win32_LogicalDisk -Filter "DriveType='3'" -ComputerName $computer 
 
#Process each disk in the collection and write to spreadsheet 
ForEach ($disk in $diskDrives) { 
    $Sheet.Cells.Item($row,1)= $disk.__Server 
    $Sheet.Cells.Item($row,2)= $disk.DeviceID 
    $Sheet.Cells.Item($row,3)= $disk.VolumeName 
    $Sheet.Cells.Item($row,4)= [math]::Round(($disk.Size /1GB),2) 
    $Sheet.Cells.Item($row,5)= [math]::Round((($disk.Size - $disk.FreeSpace)/1GB),2) 
    $Sheet.Cells.Item($row,6)= [math]::Round(($disk.FreeSpace / 1GB),2) 
    $Sheet.Cells.Item($row,7)= ("{0:P}" -f ($disk.FreeSpace / $disk.Size))   
    
    #Determine if disk needs to be flagged for warning or critical alert 
    If ($disk.FreeSpace -lt 5GB -AND ("{0:P}" -f ($disk.FreeSpace / $disk.Size))  -lt 40) { 
        $Sheet.Cells.Item($row,8) = "Critical" 
        $critical++ 
        #Check to see if space is near empty and use appropriate background colors 
        $range = $Sheet.Range(("A{0}"  -$row),("H{0}"  -$row)) 
        $range.Select() | Out-Null     
        #Critical threshold          
        $range.Interior.ColorIndex = 3 
    } ElseIf ($disk.FreeSpace -lt 10GB -AND ("{0:P}" -f ($disk.FreeSpace / $disk.Size)) -lt 60) { 
        $Sheet.Cells.Item($row,8) = "Warning" 
        $range = $Sheet.Range(("A{0}"  -$row),("H{0}"  -$row)) 
        $range.Select() | Out-Null         
        $warning++ 
        $range.Interior.ColorIndex = 6 
    } Else { 
        $Sheet.Cells.Item($row,8) = "Good" 
        $good++ 
    } 
 
     $row++ 
} 
} 
 
#Add a border for data cells 
$row-- 
$dataRange = $Sheet.Range(("A{0}"  -$initalRow),("H{0}"  -$row)) 
7..12 | ForEach { 
    $dataRange.Borders.Item($_).LineStyle = 1 
    $dataRange.Borders.Item($_).Weight = 2 
} 
 
#Auto fit everything so it looks better 
 
$usedRange = $Sheet.UsedRange                                                             
$usedRange.EntireColumn.AutoFit() | Out-Null 
 
$critical 
$warning 
$good 
 
$sheet = $excel.Worksheets.Item(2)  
  
$row++;$row++ 
 
$beginChartRow = $Row 
 
$Sheet.Cells.Item($row,$Column) = 'Critical' 
$Column++ 
$Sheet.Cells.Item($row,$Column) = 'Warning' 
$Column++ 
$Sheet.Cells.Item($row,$Column) = 'Good' 
$Column = 1 
$row++ 
#Critical formula 
$Sheet.Cells.Item($row,$Column)=$critical 
$Column++ 
#Warning formula 
$Sheet.Cells.Item($row,$Column)=$warning 
$Column++ 
#Good formula 
$Sheet.Cells.Item($row,$Column)= $good 
 
$endChartRow = $row 
 
$chartRange = $Sheet.Range(("A{0}" -$beginChartRow),("C{0}" -$endChartRow)) 
 
##Add a chart to the workbook 
#Open a sheet for charts 
$temp = $sheet.Charts.Add() 
$temp.Delete() 
$chart = $sheet.Shapes.AddChart().Chart 
$sheet.Activate() 
 
#Configure the chart 
##Use a 3D Pie Chart 
$chart.ChartType = 70 
$chart.Elevation = 40 
#Give it some color 
$sheet.Shapes.Item("Chart 1").Fill.ForeColor.TintAndShade = .34 
$sheet.Shapes.Item("Chart 1").Fill.ForeColor.ObjectThemeColor = 5 
$sheet.Shapes.Item("Chart 1").Fill.BackColor.TintAndShade = .765 
$sheet.Shapes.Item("Chart 1").Fill.ForeColor.ObjectThemeColor = 5 
 
$sheet.Shapes.Item("Chart 1").Fill.TwoColorGradient(1,1) 
 
#Set the location of the chart 
$sheet.Shapes.Item("Chart 1").Placement = 3 
$sheet.Shapes.Item("Chart 1").Top = 30 
$sheet.Shapes.Item("Chart 1").Left = 600 
 
$chart.SetSourceData($chartRange$chart.HasTitle = $True 
 
$chart.ApplyLayout(6,69) 
$chart.ChartTitle.Text = "Disk Space Report" 
$chart.ChartStyle = 26 
$chart.PlotVisibleOnly = $False 
$chart.SeriesCollection(1).DataLabels().ShowValue = $True 
$chart.SeriesCollection(1).DataLabels().Separator = ("{0}" -f [char]10) 
 
$chart.SeriesCollection(1).DataLabels().Position = 2 
#Critical 
$chart.SeriesCollection(1).Points(1).Format.Fill.ForeColor.RGB = 255 
#Warning 
$chart.SeriesCollection(1).Points(2).Format.Fill.ForeColor.RGB = 65535 
#Good 
$chart.SeriesCollection(1).Points(3).Format.Fill.ForeColor.RGB = 5287936 
 
#Hide the data 
$chartRange.EntireRow.Hidden = $True 
 
$sheet.Name = 'DiskInformation' 
 
 
 
 
$filename = "$DirectoryToSaveTo$filename.xlsx" 
if (test-path $filename ) { rm $filename } #delete the file if it already exists 
$Sheet.UsedRange.EntireColumn.AutoFit() 
$Excel.SaveAs($filename$xlOpenXMLWorkbook#save as an XML Workbook (xslx) 
$Excel.Saved = $True 
$Excel.Close() 
$Excel.DisplayAlerts = $False 
$Excel.quit() 
 
 
Function sendEmail([string]$emailFrom, [string]$emailTo, [string]$subject,[string]$body,[string]$smtpServer,[string]$filePath) 
{ 
#initate message 
$email = New-Object System.Net.Mail.MailMessage  
$email.From = $emailFrom 
$email.To.Add($emailTo$email.Subject = $subject 
$email.Body = $body 
# initiate email attachment  
$emailAttach = New-Object System.Net.Mail.Attachment $filePath 
$email.Attachments.Add($emailAttach)  
#initiate sending email  
$smtp = new-object Net.Mail.SmtpClient($smtpServer$smtp.Send($email) 
} 
 
#Call Function  
 
$message = @"  
Hi Team, 
 
The Discovery of Windows Server and Disk Space information for all the listed instances. 
 
Autogenerated Email!!! Please do not reply. 
 
Thank you,  
XYZ.com 
 
"@         
$date=get-date 
 
sendEmail -emailFrom $fromEmail -emailTo $ToEmail -subject "Windows Server Inventory & Disk Details -$($date)" -body $message -smtpServer $SMTPMail -filePath $filename 
 
 Sheet1 – Server Information
Sheet 2 – Disk Information – No of critical, warning and good state representation of drives

Email-Output-

 Reference

http://learn-powershell.net/2012/12/24/powershell-and-excel-adding-a-chart-and-header-filter-to-a-report/

Posted in Uncategorized | Tagged , , , , , | Leave a comment

SQL – List All Tables, Space Usage Info & Other Details

One of the OP requested in the forum to find all table details of any database. The details which includes Number of Rows,table size, index size etc:-. Even I frequently writing queries to list all such details.

I’ve used SQLCMD mode to connect to the remote server and database to fetch all the required details.

SQLCMD can be enabled in Query Editor.

Go to SSMS Menu -> Query ->Select SQLCMD.

 Download the script :- SQL-List-All-Tables-Information

Chane the Servername and Databasename in the below script

:CONNECT <SERVERNAME> 
:SETVAR DB <DATABASENAME> 
 
USE $(DB) 
 
create table #TableSize ( 
    Name varchar(255), 
    [rowsint, 
    reserved varchar(255), 
    data varchar(255), 
    index_size varchar(255), 
    unused varchar(255)) 
create table #ConvertedSizes ( 
    Name varchar(255), 
    [rowsint, 
    reservedKb int, 
    dataKb int, 
    reservedIndexSize int, 
    reservedUnused int) 
 
EXEC sp_MSforeachtable @command1="insert into #TableSize 
EXEC sp_spaceused '?'insert into #ConvertedSizes (Name, [rows], reservedKb, dataKb, reservedIndexSize, reservedUnused) 
select name, [rows],  
SUBSTRING(reserved0LEN(reserved)-2),  
SUBSTRING(data0LEN(data)-2),  
SUBSTRING(index_size0LEN(index_size)-2),  
SUBSTRING(unused0LEN(unused)-2from #TableSize 
 
select * from #ConvertedSizes 
order by reservedKb desc 
 
drop table #TableSize 
drop table #ConvertedSizes
Output:-

Posted in Uncategorized | Tagged , , , , , | Leave a comment

PowerShell-Input-Validation Scripts

Input values are validated using various mechanisms.  let’s start by examining how you would validate input parameters in Windows PowerShell 2.0

The Inputs are validated for the below mentioned functionality

  1. PostalCode
  2. PhoneNumber
  3. EmailID
  4. IP 
  5. FileName

Download the scripts from the below link

http://gallery.technet.microsoft.com/PowerShell-Input-Validation-30ebaa51

To validate PostalCode – 99999

Function Validate-PostalCode 
{ 
 Param([Parameter(Mandatory=$true,HelpMessage="Enter a valid Postal Code xxx-xxx-xxxx")][ValidatePattern("[0-9][0-9][0-9][0-9]")]$PostalCode) 
 Write-host "The Pin Code $PostalCode is valid" 
} 
 

To Validate phone number –  999-999-9999

Function validate-PhoneNumber 
{ 
 Param([ValidatePattern("\d{3}-\d{3}-\d{4}")]$phoneNumber) 
  Write-host "The phone number $phoneNumber is valid" 
} 
 
validate-PhoneNumber -Phonenumber 999-999-9999
 To Validate email address
 
function Validate-Email ([string]$Email) 
{ 
  return $Email -match "^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$" 
}  
 
 To Validate IP Range – 255.255.255.255 
 
function Validate-IPAddress ([string]$IP) 
 { 
 if($IP -match "(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})" -and -not ([int[]]$matches[1..4] -gt 255)) 
 { 
   Write-host "The $IP IP is valid" 
 } 
 }
 To Validate the filename for ########_???_?.jpg 
 
function Validate-Filename 
{ 
Param([ValidatePattern("^\d{8}_[a-zA-Z]{3,4}_[a-zA-Z]{1}\.jpg"]$filename) 
Write-host "The filename $filename is valid" 
} 
 
You can also refer the below link for more information
 
 
Posted in Uncategorized | Tagged , , , , , | Leave a comment

SQL – Find encrypted objects using sql_modules or Powershell

sys.sql_modules catalog view which got introduced from SQL 2005 onwards. The sql_modules which includes the objects of type P, RF, V, TR, FN, IF, TF, and R have an associated SQL module.

 SQL

SELECT 
sm.object_id, 
OBJECT_NAME(sm.object_id) AS object_name, 
o.type, o.type_desc, 
sm.definition, 
CAST(CASE WHEN sm.definition IS NULL THEN 1 ELSE 0 END AS bit) AS [IsEncrypted] 
FROM sys.sql_modules AS sm 
JOIN sys.objects AS o ON sm.object_id = o.object_id 
ORDER BY o.type;
sql_modules to list only stored procedures then you can join with sys.procedures
SQL
SELECT SP.*, 
CASE  
WHEN SM.definition IS NULL THEN 'Encyrpted' END AS IsEncrypted 
FROM sys.procedures AS SP     
LEFT JOIN sys.sql_modules AS SM    ON SP.object_id = SM.object_id 
 PowerShell :-

Change the Servername and DBName in the below code. Execute the below code from PowerShell-ISE

$server = "<ServerName>" 
$database = "<DBName>" 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null 
$srv = New-Object "Microsoft.SqlServer.Management.SMO.Server" $server 
$db = New-Object ("Microsoft.SqlServer.Management.SMO.Database") 
 
# Get the database and Its objects 
$db = $srv.Databases[$database] 
$storedProcs = $db.StoredProcedures | Where-object {$_.IsEncrypted} 
$storedProcs|select name
 Download the code: -

Posted in Uncategorized | Tagged , | Leave a comment

First Birthday to My Blog

Today is the First year anniversary of my blog. After thinking a lot and going through many un-imaginable resource available over the internet and reading blogs of many wonderful brains made me think about creating a blog.

When I wrote my first post a year ago I wondered and asked myself many times what I’m going to tell you all.  I refused myself many times. At lost I made it and completed first year. Later I started enjoying in what I’m doing. It’s great to share what I do, but mostly I enjoy the feedback I get from you all.  This is really invaluable.  It tells me what works and what doesn’t and many times inputs and advice’s is truly priceless.

 Thanks everyone for contributing to the world of knowledge. I truly admire everyone.

 Happy Learning!!!!!!!!!!!

 Thanks!!

Posted in Uncategorized | Tagged | Leave a comment

PowerShell GUI Tool – Network Ping – Version 2

The first version of the tool was developed by Amandhally and it can be found in the below path. Thanks for sharing.

http://www.amandhally.net/2012/08/08/powershell-based-network-range-pinging-application-network-pinger-ajit-2/

In my version of the tool, I’ve re-used his template and modified in such a way that the output is HTML formatted with server Names displayed in the result area.

You can download the second version of the tool by clicking the below link

http://gallery.technet.microsoft.com/PowerShell-GUI-Tool-f03b7523

This script requires

  • Staring IP- Adddress
  • Ending IP-Address
  • Hit RUN button
  • The output in the result box

You can also send email from the below portion of window

Output-

PowerShell Code:-

<#=================================  
# Generated On: 04/02/2014   
# Generated By: Prashanth Jayaram   
# Version     : 1.1   
# Desc        : Network Ping  
#=================================  
#>  
 
Function Network_Pinger 
{ 
function OnApplicationLoad { 
    #Note: This function is not called in Projects 
    #Note: This function runs before the form is created 
    #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path 
    #Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList) 
    #Important: Form controls cannot be accessed in this function 
    #TODO: Add snapins and custom code to validate the application load 
    $PingReport = "C:\pingstatus.htm" 
    New-Item -ItemType file $PingReport -Force 
    return $true #return true for success or false for failure 
} 
 
function OnApplicationExit { 
    #Note: This function is not called in Projects 
    #Note: This function runs after the form is closed 
    #TODO: Add custom code to clean up and unload snapins when the application exits 
     
    $script:ExitCode = 0 #Set the exit code for the Packager 
     
} 
 
#endregion Application Functions 
 
#---------------------------------------------- 
# Generated Form Function 
#---------------------------------------------- 
function Call-PIng_Network_Community_v2_pff { 
 
    #---------------------------------------------- 
    #region Import the Assemblies 
    #---------------------------------------------- 
    [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") 
    [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") 
    [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") 
    [void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") 
    [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") 
    [void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") 
    [void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") 
    [void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") 
    #endregion Import Assemblies 
 
    #---------------------------------------------- 
    #region Generated Form Objects 
    #---------------------------------------------- 
    [System.Windows.Forms.Application]::EnableVisualStyles() 
    $formPowershellNetworkPin = New-Object 'System.Windows.Forms.Form' 
    $labelOutput = New-Object 'System.Windows.Forms.Label' 
    $labelCreatedByAmanDhallyW = New-Object 'System.Windows.Forms.Label' 
    $labelSubject = New-Object 'System.Windows.Forms.Label' 
    $labelFrom = New-Object 'System.Windows.Forms.Label' 
    $label1 = New-Object 'System.Windows.Forms.Label' 
    $labelSMTPServer = New-Object 'System.Windows.Forms.Label' 
    $textbox9 = New-Object 'System.Windows.Forms.TextBox' 
    $textbox8 = New-Object 'System.Windows.Forms.TextBox' 
    $textbox7 = New-Object 'System.Windows.Forms.TextBox' 
    $textbox6 = New-Object 'System.Windows.Forms.TextBox' 
    $buttonEMailOutput = New-Object 'System.Windows.Forms.Button' 
    $richtextbox1 = New-Object 'System.Windows.Forms.RichTextBox' 
    $buttonRun = New-Object 'System.Windows.Forms.Button' 
    $textbox5 = New-Object 'System.Windows.Forms.TextBox' 
    $labelTo = New-Object 'System.Windows.Forms.Label' 
    $textbox4 = New-Object 'System.Windows.Forms.TextBox' 
    $textbox3 = New-Object 'System.Windows.Forms.TextBox' 
    $textbox2 = New-Object 'System.Windows.Forms.TextBox' 
    $textbox1 = New-Object 'System.Windows.Forms.TextBox' 
    $labelIPAddressRange = New-Object 'System.Windows.Forms.Label' 
    $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' 
    #endregion Generated Form Objects 
 
         
     
     
     
     
    $formPowershellNetworkPin_Load={ 
        #TODO: Initialize Form Controls here 
         
    } 
     
    $textbox1.MaxLength=3 
    $textbox2.MaxLength=3 
    $textbox3.MaxLength=3 
    $textbox4.MaxLength=3 
    $textbox5.MaxLength=3 
     
function Get-ComputerNameByIP { 
    param( 
        $IPAddress = $null 
    ) 
    BEGIN { 
    } 
    PROCESS { 
        if ($IPAddress -and $_) { 
            throw 'Please use either pipeline or input parameter' 
            break 
        } elseif ($IPAddress) { 
            ([System.Net.Dns]::GetHostbyAddress($IPAddress)).HostName 
        } elseif ($_) { 
            [System.Net.Dns]::GetHostbyAddress($_).HostName 
        } else { 
            $IPAddress = Read-Host "Please supply the IP Address" 
            [System.Net.Dns]::GetHostbyAddress($IPAddress).HostName 
        } 
    } 
    END { 
    } 
} 
 
 
     
    $buttonRun_Click={ 
         
        #TODO: Place custom script here 
        $richtextbox1.Clear() 
$PingReport = "C:\pingstatus.htm" 
#$script:list = "c:\computer.txt" 
 
 
New-Item -ItemType file $PingReport -Force 
 
# Getting the freespace info using WMI 
#Get-WmiObject win32_logicaldisk  | Where-Object {$_.drivetype -eq 3 -OR $_.drivetype -eq 2 } | format-table DeviceID, VolumeName,status,Size,FreeSpace | Out-File FreeSpace.txt 
# Function to write the HTML Header to the file 
Function writeHtmlHeader 
{ 
param($fileName$date = ( get-date ).ToString('yyyy/MM/dd'Add-Content $fileName "<html>" 
Add-Content $fileName "<head>" 
Add-Content $fileName "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>" 
Add-Content $fileName '<title>IP Scanner Report</title>' 
add-content $fileName '<STYLE TYPE="text/css">' 
add-content $fileName  "<!--" 
add-content $fileName  "td {" 
add-content $fileName  "font-family: Tahoma;" 
add-content $fileName  "font-size: 11px;" 
add-content $fileName  "border-top: 1px solid #999999;" 
add-content $fileName  "border-right: 1px solid #999999;" 
add-content $fileName  "border-bottom: 1px solid #999999;" 
add-content $fileName  "border-left: 1px solid #999999;" 
add-content $fileName  "padding-top: 0px;" 
add-content $fileName  "padding-right: 0px;" 
add-content $fileName  "padding-bottom: 0px;" 
add-content $fileName  "padding-left: 0px;" 
add-content $fileName  "}" 
add-content $fileName  "body {" 
add-content $fileName  "margin-left: 5px;" 
add-content $fileName  "margin-top: 5px;" 
add-content $fileName  "margin-right: 0px;" 
add-content $fileName  "margin-bottom: 10px;" 
add-content $fileName  "" 
add-content $fileName  "table {" 
add-content $fileName  "border: thin solid #000000;" 
add-content $fileName  "}" 
add-content $fileName  "-->" 
add-content $fileName  "</style>" 
Add-Content $fileName "</head>" 
Add-Content $fileName "<body>" 
 
add-content $fileName  "<table width='100%'>" 
add-content $fileName  "<tr bgcolor='#CCCCCC'>" 
add-content $fileName  "<td colspan='2' height='25' align='center'>" 
add-content $fileName  "<font face='tahoma' color='#003399' size='4'><strong>IP Scanner Report - $date</strong></font>" 
add-content $fileName  "</td>" 
add-content $fileName  "</tr>" 
add-content $fileName  "</table>" 
 
} 
 
# Function to write the HTML Header to the file 
Function writeTableHeader 
{ 
param($fileName) 
 
Add-Content $fileName "<tr bgcolor=#CCCCCC>" 
Add-Content $fileName "<td width='10%' align='center'>Name</td>" 
Add-Content $fileName "<td width='50%' align='center'>Status Label</td>" 
Add-Content $fileName "</tr>" 
} 
 
Function writeHtmlFooter 
{ 
param($fileName) 
 
Add-Content $fileName "</body>" 
Add-Content $fileName "</html>" 
} 
 
Function writeDiskInfo 
{ 
param($fileName,$name,$statusif ($status -eq $TRUE) 
{ 
Add-Content $fileName "<tr>" 
Add-Content $fileName "<td>$Name</td>" 
Add-Content $fileName "<td>Is alive and Pinging</td>" 
} 
else 
{ 
Add-Content $fileName "<tr>" 
Add-Content $fileName "<td>$Name</td>" 
Add-Content $fileName "<td bgcolor='#FF0000'>Seems dead and not Pinging</td>" 
Add-Content $fileName "</tr>" 
} 
 
} 
 
 
writeHtmlHeader $PingReport 
 
Add-Content $PingReport "<table width='100%'><tbody>" 
Add-Content $PingReport "<tr bgcolor='#CCCCCC'>" 
Add-Content $PingReport "<td width='100%' align='center' colSpan=2><font face='tahoma' color='#003399' size='2'><strong> IP and Host Status </strong></font></td>" 
Add-Content $PingReport "</tr>" 
 
        $result = @() 
        $startip = $textbox1.Text + "." + $textbox2.Text +  "." + $textbox3.Text + "." + $textbox4.Text 
        $ip = $textbox5.Text  
         
        foreach ($i in $startip) {  
        $last = $i.Split(".") 
        [int]$lastip = $last[3] 
        while ( $lastip -le $ip ) {  
        $result +=  $textbox1.Text + "." + $textbox2.Text +  "." + $textbox3.Text + "." +  $lastip++ } }     
         
        foreach ( $computer in $result ) { 
        if (test-Connection -ComputerName $computer -Count 1 -Quiet ) { 
            $Name= Get-ComputerNameByIP -IPAddress $computer 
               $richtextbox1.Text +"$computer -> $Name is alive and Pinging."  
            $richtextbox1.Text +"`n" 
            writeDiskInfo $PingReport "$computer -> $Name" $TRUE 
            $formPowershellNetworkPin.Refresh()                 
            } else     {  
             
            $richtextbox1.Text +=  " $computer -> seems dead and not Pinging."  
            $richtextbox1.Text +"`n"     
            writeDiskInfo $PingReport $computer $FALSE 
            $formPowershellNetworkPin.Refresh()     
             
            } 
         
 
     } 
      Add-Content $PingReport "</table>"  
     
    } 
     
   ##writeHtmlFooter $PingReport  
     
     
    $buttonClear_Click={ 
        #TODO: Place custom script here 
         
    } 
     
Function sendEmail   
{  
param($from,$to,$subject,$smtphost,$htmlFileName)   
[string]$receipients="$to" 
$body = Get-Content $htmlFileName  
$body = New-Object System.Net.Mail.MailMessage $from$receipients$subject$body  
$body.isBodyhtml = $true 
$smtpServer = $MailServer 
$smtp = new-object Net.Mail.SmtpClient($smtphost$smtp.Send($body) 
} 
 
#Call Function  
#sendEmail -from $From -to $to -subject "System Report : $computers" -smtphost $SMTPMail -htmlfilename c:\report.html 
 
 
     
    $buttonEMailOutput_Click={ 
        #TODO: Place custom script here 
        $smtp = $textbox6.Text 
        $to =   $textbox7.Text 
        $from = $textbox8.Text 
        $sub =  $textbox9.Text 
        $body = $richtextbox1.Text 
        sendEmail -from $From -to $to -subject $sub -smtphost $smtp -htmlfilename c:\pingstatus.htm 
        if($?) 
        { 
        [void][System.Windows.Forms.MessageBox]::Show("Email Sent") 
        } 
         
 
    } 
     
    $labelSMTPServer_Click={ 
        #TODO: Place custom script here 
         
    } 
     
    # --End User Generated Script-- 
    #---------------------------------------------- 
    #region Generated Events 
    #---------------------------------------------- 
     
    $Form_StateCorrection_Load= 
    { 
        #Correct the initial state of the form to prevent the .Net maximized form issue 
        $formPowershellNetworkPin.WindowState = $InitialFormWindowState 
    } 
     
    $Form_Cleanup_FormClosed= 
    { 
        #Remove all event handlers from the controls 
        try 
        { 
            $labelSMTPServer.remove_Click($labelSMTPServer_Click) 
            $buttonEMailOutput.remove_Click($buttonEMailOutput_Click) 
            $buttonRun.remove_Click($buttonRun_Click) 
            $formPowershellNetworkPin.remove_Load($formPowershellNetworkPin_Load) 
            $formPowershellNetworkPin.remove_Load($Form_StateCorrection_Load) 
            $formPowershellNetworkPin.remove_FormClosed($Form_Cleanup_FormClosed) 
        } 
        catch [Exception] 
        { } 
    } 
    #endregion Generated Events 
 
    #---------------------------------------------- 
    #region Generated Form Code 
    #---------------------------------------------- 
    # 
    # formPowershellNetworkPin 
    # 
    $formPowershellNetworkPin.Controls.Add($labelOutput) 
    $formPowershellNetworkPin.Controls.Add($labelCreatedByAmanDhallyW) 
    $formPowershellNetworkPin.Controls.Add($labelSubject) 
    $formPowershellNetworkPin.Controls.Add($labelFrom) 
    $formPowershellNetworkPin.Controls.Add($label1) 
    $formPowershellNetworkPin.Controls.Add($labelSMTPServer) 
    $formPowershellNetworkPin.Controls.Add($textbox9) 
    $formPowershellNetworkPin.Controls.Add($textbox8) 
    $formPowershellNetworkPin.Controls.Add($textbox7) 
    $formPowershellNetworkPin.Controls.Add($textbox6) 
    $formPowershellNetworkPin.Controls.Add($buttonEMailOutput) 
    $formPowershellNetworkPin.Controls.Add($richtextbox1) 
    $formPowershellNetworkPin.Controls.Add($buttonRun) 
    $formPowershellNetworkPin.Controls.Add($textbox5) 
    $formPowershellNetworkPin.Controls.Add($labelTo) 
    $formPowershellNetworkPin.Controls.Add($textbox4) 
    $formPowershellNetworkPin.Controls.Add($textbox3) 
    $formPowershellNetworkPin.Controls.Add($textbox2) 
    $formPowershellNetworkPin.Controls.Add($textbox1) 
    $formPowershellNetworkPin.Controls.Add($labelIPAddressRange) 
    $formPowershellNetworkPin.ClientSize = '463, 326' 
    $formPowershellNetworkPin.FormBorderStyle = 'Fixed3D' 
    $formPowershellNetworkPin.Name = "formPowershellNetworkPin" 
    $formPowershellNetworkPin.Opacity = 0.95 
    $formPowershellNetworkPin.StartPosition = 'CenterScreen' 
    $formPowershellNetworkPin.Text = "Powershell IP Scanner" 
    $formPowershellNetworkPin.add_Load($formPowershellNetworkPin_Load) 
    # 
    # labelOutput 
    # 
    $labelOutput.Location = '12, 44' 
    $labelOutput.Name = "labelOutput" 
    $labelOutput.Size = '65, 16' 
    $labelOutput.TabIndex = 21 
    $labelOutput.Text = "Output |" 
    # 
 
    # 
    # labelSubject 
    # 
    $labelSubject.Location = '163, 237' 
    $labelSubject.Name = "labelSubject" 
    $labelSubject.Size = '100, 20' 
    $labelSubject.TabIndex = 18 
    $labelSubject.Text = "Subject" 
    # 
    # labelFrom 
    # 
    $labelFrom.Location = '17, 238' 
    $labelFrom.Name = "labelFrom" 
    $labelFrom.Size = '100, 19' 
    $labelFrom.TabIndex = 17 
    $labelFrom.Text = "From" 
    # 
    # label1 
    # 
    $label1.Location = '163, 188' 
    $label1.Name = "label1" 
    $label1.Size = '92, 23' 
    $label1.TabIndex = 16 
    $label1.Text = "To" 
    # 
    # labelSMTPServer 
    # 
    $labelSMTPServer.Location = '17, 188' 
    $labelSMTPServer.Name = "labelSMTPServer" 
    $labelSMTPServer.Size = '150, 23' 
    $labelSMTPServer.TabIndex = 15 
    $labelSMTPServer.Text = "SMTP Server" 
    $labelSMTPServer.add_Click($labelSMTPServer_Click) 
    # 
    # textbox9 
    # 
    $textbox9.Location = '163, 260' 
    $textbox9.Name = "textbox9" 
    $textbox9.Size = '150, 20' 
    $textbox9.TabIndex = 14 
    # 
    # textbox8 
    # 
    $textbox8.Location = '12, 260' 
    $textbox8.Name = "textbox8" 
    $textbox8.Size = '150, 20' 
    $textbox8.TabIndex = 13 
    # 
    # textbox7 
    # 
    $textbox7.Location = '163, 214' 
    $textbox7.Name = "textbox7" 
    $textbox7.Size = '150, 20' 
    $textbox7.TabIndex = 12 
    # 
    # textbox6 
    # 
    $textbox6.Location = '12, 214' 
    $textbox6.Name = "textbox6" 
    $textbox6.Size = '150, 20' 
    $textbox6.TabIndex = 11 
    # 
    # buttonEMailOutput 
    # 
    $buttonEMailOutput.Location = '337, 214' 
    $buttonEMailOutput.Name = "buttonEMailOutput" 
    $buttonEMailOutput.Size = '65, 65' 
    $buttonEMailOutput.TabIndex = 16 
    $buttonEMailOutput.Text = "E-Mail Output" 
    $buttonEMailOutput.UseVisualStyleBackColor = $True 
    $buttonEMailOutput.add_Click($buttonEMailOutput_Click) 
    # 
    # richtextbox1 
    # 
    $richtextbox1.Location = '12, 63' 
    $richtextbox1.Name = "richtextbox1" 
    $richtextbox1.Size = '427, 101' 
    $richtextbox1.TabIndex = 8 
    $richtextbox1.Text = "" 
    # 
    # buttonRun 
    # 
    $buttonRun.Location = '350, 20' 
    $buttonRun.Name = "buttonRun" 
    $buttonRun.Size = '55, 23' 
    $buttonRun.TabIndex = 7 
    $buttonRun.Text = "Run" 
    $buttonRun.UseVisualStyleBackColor = $True 
    $buttonRun.add_Click($buttonRun_Click) 
    # 
    # textbox5 
    # 
    $textbox5.Location = '303, 21' 
    $textbox5.Name = "textbox5" 
    $textbox5.Size = '28, 20' 
    $textbox5.TabIndex = 6 
    # 
    # labelTo 
    # 
    $labelTo.Location = '263, 23' 
    $labelTo.Name = "labelTo" 
    $labelTo.Size = '100, 23' 
    $labelTo.TabIndex = 5 
    $labelTo.Text = "-- to --" 
    # 
    # textbox4 
    # 
    $textbox4.Location = '228, 21' 
    $textbox4.Name = "textbox4" 
    $textbox4.Size = '27, 20' 
    $textbox4.TabIndex = 4 
    # 
    # textbox3 
    # 
    $textbox3.Location = '192, 21' 
    $textbox3.Name = "textbox3" 
    $textbox3.Size = '27, 20' 
    $textbox3.TabIndex = 3 
    # 
    # textbox2 
    # 
    $textbox2.Location = '157, 21' 
    $textbox2.Name = "textbox2" 
    $textbox2.Size = '27, 20' 
    $textbox2.TabIndex = 2 
    # 
    # textbox1 
    # 
    $textbox1.Location = '123, 21' 
    $textbox1.Name = "textbox1" 
    $textbox1.Size = '27, 20' 
    $textbox1.TabIndex = 1 
    # 
    # labelIPAddressRange 
    # 
    $labelIPAddressRange.Location = '15, 21' 
    $labelIPAddressRange.Name = "labelIPAddressRange" 
    $labelIPAddressRange.Size = '112, 23' 
    $labelIPAddressRange.TabIndex = 0 
    $labelIPAddressRange.Text = "IP-Address Range :" 
    #endregion Generated Form Code 
 
    #---------------------------------------------- 
 
    #Save the initial state of the form 
    $InitialFormWindowState = $formPowershellNetworkPin.WindowState 
    #Init the OnLoad event to correct the initial state of the form 
    $formPowershellNetworkPin.add_Load($Form_StateCorrection_Load) 
    #Clean up the control events 
    $formPowershellNetworkPin.add_FormClosed($Form_Cleanup_FormClosed) 
    #Show the Form 
    return $formPowershellNetworkPin.ShowDialog() 
 
} #End Function 
 
#Call OnApplicationLoad to initialize 
if((OnApplicationLoad) -eq $true) 
{ 
    #Call the form 
    Call-PIng_Network_Community_v2_pff | Out-Null 
    #Perform cleanup 
    OnApplicationExit 
} 
}  
     
Network_Pinger     
Posted in Uncategorized | Tagged , , | Leave a comment