Posts

Showing posts with the label powershell

Steps to Create Windows Service

Image
What is Windows Service? Windows service is a computer program that enables you to create and run executable applications as a background process. Its start status can be made as manual or automatic, in automatic the services will start automatically as soon as computer boots. It is very easy to install the windows service, all we need to do is just simply run the Utility program called “InstallUtil.exe” providing the path for the service executable file which we will see how to create. In this demo we will create a windows service which executes powershell and batch file to display system information through browser. Pre-requisites: You need to place batch and powershell scripts on the designated path (Mentioned in ServiceScheduler.cs file) to make this example work properly. You can find the required files under Artifacts title in this blog. STEP 1: Open Visual Studio and from menu open New Project à select the below project and rename it to DemoWindowServ...

Use PowerShell to send mail via Outlook along with SQL result csv as attachment

Image
Introduction In this post we will create a simple utility to perform these tasks:  Execute a SQL script stored as .sql file in a local directory. Save the result set as .csv. Use outlook application configured on the local machine to send the .csv as an attachment to email recipients.  We will be using PowerShell script. Lets prepare the .sql script. For this utility purpose we will make use of a very simple query. Below is the code for the .ps1 which will perform the tasks we mentioned above. $global:toMailList         = "toEmail@domain.com" ; $global:ccMailList          = "cc Email1@domain.com ; ccEmail2@domain.com " ; $global:MailSubject       = "PS outlook Test Email" ; $global:MailBody           = "Sent using Powershell via Outlook Client" ; $global:SQLScriptPath = "C:\...\SQLInputFile.sql" ; $global:Attachment       = "C:\...\TestOut...