Wednesday, April 19, 2017

PowerShell : BizTalk Error Send Email Alert.ps1

# biboyatienza - 13Jan.2017 15:59
# To Run => powershell -ExecutionPolicy Bypass -File "C:\BizTalk_Dropzone\PowerShellScripts\BizTalk Error Send Email Alert.ps1"
# biboyatienza - 19.April.2017 15:20 GMT+8 => Added detailed error:
##############################################################################
$SQLServer = "The_Server" #use Server\Instance for named SQL instances!
$SQLDBName = "IntegrationDb"
$SqlQuery = "EXEC [dbo].[usp_BizTalk_GetSuspended]"

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd

$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)

$SqlConnection.Close()

$DataSet.Tables[0]

foreach ($row in $DataSet.Tables[0].Rows)
{
    $ApplicationName = $row[0].ToString().Trim()
    $DateSuspended = $row[1].ToString().Trim()
    $Adapter = $row[2].ToString().Trim()
    $URI = $row[3].ToString().Trim()
    $ErrorDescription = $row[4].ToString().Trim()
    $Status = $row[5].ToString().Trim()

    # Email sending:
    $From = "NoReply <no_reply@biboyatienza.com>"
    $To = "admin@biboyatienza.com", "DBA <dba@biboyatienza.com>"
    $Bcc = "biboyatienza@gmail.com"
    $Subject = "Biztalk Error : " + $ApplicationName
    $Body = "Hi BizTalk Admin(s), `r`n`r`n"
    $Body = $Body + "Application Name: " + $ApplicationName + "`r`n"
    $Body = $Body + "Date Suspended: " + $DateSuspended + "`r`n"
    $Body = $Body + "Adapter: " + $Adapter + "`r`n"
    $Body = $Body + "URI: " + $URI + "`r`n"
    $Body = $Body + "Error Description: " + $ErrorDescription + "`r`n"
    $Body = $Body + "Status: " + $Status + "`r`n"
    $Body = $Body + "`r`n`r`n`r`n br,`r`n biboy atienza"
    $SMTPServer = "mail.biboyatienza.com"
    $SMTPPort = "25"
    Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
    -Body $Body -SmtpServer $SMTPServer -port $SMTPPort
}
##############################################################################

Thursday, April 6, 2017

Introducing my new laptop at home

The Lenovo n22 n3050;


https://www.cnet.com/products/lenovo-n22-80s6-11-6-celeron-n3050-4-gb-ram-32-gb-ssd/specs/

Though it is equipped with windows 10 pro 64 bit, I still need to wipe it out and install a fresh new Ubuntu 16.04 LTS. I want to utilized it's full power. I only have 32gig disk space and Windows will surely eat it all in the long run. :(

First thing should do is to download Ubuntu installer here,



Then since I am still working on Windows environment, I need an app to create a bootable Ubuntu usb, and Rufus (Create bootable USB drives the easy way) with do that for me.



Monday, January 16, 2017

Using PowerShell to call API

Below is a sample PowerShell script that call an sms API.

# powershell -ExecutionPolicy Bypass -File "FIlename"
$yourUri = "http://gateway.yesmsfusion.no/V1/smsapi.asmx/SendSms"
Invoke-WebRequest -Uri $yourUri -Method Post -Body @{
apiKey="LJLKJL233RNL3ACLSZB3M6ZOU19K"
receipient="+639171234567"
message="Het buddy! call me when your FREE. - PowerShell"
replyPath=""
originator="Biboy"
}

Wednesday, January 11, 2017

Send email notification using PowerShell sripting when there is an Error or Warning Event

Send email notification using PowerShell scripting when there is an Error or Warning Event

1. Create a schedule task, on an Event trigger
2. Create .ps1 file that will email you
3. Enable the Schedule Task

Wednesday, November 9, 2016

C# : Create Xml files based on schema/.xsd file

- Create .xsd/schema file
- Open Visual Studio Command Prompt
- Go to the location of the schema file
- Type => xsd /classes <schema_file.xsd>
- Above command will generate a <schema_file.cs>

Wednesday, October 5, 2016

DOS Batch Command : Move 10 files out of n number of files

@echo off
REM move 250 xml files from the SOURCE folder to the DESTINATION folder.
setlocal enabledelayedexpansion
set "source=C:\BizTalk_Dropzone\zTest\Source"
set "target=C:\BizTalk_Dropzone\zTest\Destination"
set counter=0
for %%F in ("%source%\*.*") do (
 set "file=%%~nxF"
 echo move /Y "%%F" "%target%\"
 move /Y "%%F" "%target%\"
 set /a counter+=1
 if !counter! GEQ 10 goto :break
)
:break
echo Total files moved is %counter%...