Search

Scripts


$user = [Environment]::username



$a = new-object -comobject wscript.shell

$b = $a.popup("Hi $user . Welcome to Server Status check System",1,'Welcome')




function Invoke-SQLcmd

{

param(

$ServerInstance,

$Database,

$User,

$pw,

$Query

)



$Conn=New-Object System.Data.SQLClient.SQLConnection "Server=$ServerInstance;Database=$Database;Integrated Security=true";

$Conn.Open();

$DataCmd = New-Object System.Data.SqlClient.SqlCommand;

$DataCmd.CommandText = $Query;

$DataCmd.Connection = $Conn;

$DAadapter = New-Object System.Data.SqlClient.SqlDataAdapter;

$DAadapter.SelectCommand = $DataCmd;

$DTable = New-Object System.Data.DataTable;

$DAadapter.Fill($DTable)|Out-Null;

$Conn.Close();

$Conn.Dispose();

$DTable;

}






function sendmail()


{

param($EmailFrom,$EmailTo,$Subject,$SMTPServer,$port,$Username,$pass,$attachments)


$loc=$LocTB.Text

$mailconfigloc=$loc+'\mailconfig.xml'

[xml]$myXML = Get-Content $mailconfigloc

$EmailFrom=$myXML.mailconfig.from

$EmailTo=$myXML.mailconfig.to

$SMTPServer=$myXML.mailconfig.smtp

$port=$myXML.mailconfig.port

$Subject=$myXML.mailconfig.sub

$Username=$myXML.mailconfig.uname

$pass=$myXML.mailconfig.pwd


Write-Host '$pass'$pass

$Password = "$pass" |ConvertTo-SecureString

$Credentials = New-Object System.Management.Automation.PSCredential ($Username,$Password)


Send-MailMessage -From $EmailFrom -to $EmailTo -Body 'Mail from ServerCheckTool' -Subject $Subject -UseSsl -SmtpServer $SMTPServer -Port $port -Credential $Credentials -Attachments $attachments

}



function mailform()

{

param($location)


function sendmail()


{

param($EmailFrom,$EmailTo,$Subject,$SMTPServer,$port,$Username,$pass)



$Password = "$pass" |ConvertTo-SecureString

$Credentials = New-Object System.Management.Automation.PSCredential ($Username,$Password)

Send-MailMessage -From $EmailFrom -to $EmailTo -Body 'Mail from ServerCheckTool' -Subject $Subject -UseSsl -SmtpServer $SMTPServer -Port $port -Credential $Credentials


}


# Create a GUI Form

$Mailform = New-Object System.Windows.Forms.Form

$Mailform.Text = “Mail configuration Page”

$Mailform.Size = New-Object System.Drawing.Size(500,700)

$Mailform.StartPosition = “CenterScreen”



# Add a text box to the Location

$FromTB = New-Object System.Windows.Forms.TextBox

$FromTB.Location = New-Object System.Drawing.Size(150,50)

$FromTB.Size = New-Object System.Drawing.Size(200,20)

$Mailform.Controls.Add($FromTB)



# Add a text box to the Location

$FromLabel = New-Object System.Windows.Forms.Label

$FromLabel.Location = New-Object System.Drawing.Size(50,50)

$FromLabel.Size = New-Object System.Drawing.Size(200,20)

$FromLabel.Text='From email'

$Mailform.Controls.Add($FromLabel)


# Add a text box to the Location

$ToTB = New-Object System.Windows.Forms.TextBox

$ToTB.Location = New-Object System.Drawing.Size(150,100)

$ToTB.Size = New-Object System.Drawing.Size(200,20)

$Mailform.Controls.Add($ToTB)



# Add a text box to the Location

$ToLabel = New-Object System.Windows.Forms.Label

$ToLabel.Location = New-Object System.Drawing.Size(50,100)

$ToLabel.Size = New-Object System.Drawing.Size(200,20)

$ToLabel.Text='To email'

$Mailform.Controls.Add($ToLabel)


# Add a text box SMTP the Location

$SMTPTB = New-Object System.Windows.Forms.TextBox

$SMTPTB.Location = New-Object System.Drawing.Size(150,150)

$SMTPTB.Size = New-Object System.Drawing.Size(200,20)

$Mailform.Controls.Add($SMTPTB)



# Add a text box SMTP the Location

$SMTPLabel = New-Object System.Windows.Forms.Label

$SMTPLabel.Location = New-Object System.Drawing.Size(50,150)

$SMTPLabel.Size = New-Object System.Drawing.Size(200,20)

$SMTPLabel.Text='SMTP '

$Mailform.Controls.Add($SMTPLabel)


# Add a text box Subject the Location

$SubjectTB = New-Object System.Windows.Forms.TextBox

$SubjectTB.Location = New-Object System.Drawing.Size(150,200)

$SubjectTB.Size = New-Object System.Drawing.Size(200,20)

$Mailform.Controls.Add($SubjectTB)



# Add a text box Subject the Location

$SubjectLabel = New-Object System.Windows.Forms.Label

$SubjectLabel.Location = New-Object System.Drawing.Size(50,200)

$SubjectLabel.Size = New-Object System.Drawing.Size(200,20)

$SubjectLabel.Text='Subject '

$Mailform.Controls.Add($SubjectLabel)


# Add a text box port the Location

$portTB = New-Object System.Windows.Forms.TextBox

$portTB.Location = New-Object System.Drawing.Size(150,250)

$portTB.Size = New-Object System.Drawing.Size(200,20)

$Mailform.Controls.Add($portTB)



# Add a text box port the Location