Monday, 1 February 2021

Power shell script to start, stop and restart windows services.

 With the help you below power shell script you check windows service's status and can restart, stop etc. even on remote servers.


 

[string]$computerName

 

## Create a log file

$LogFile = "E:\Logs\logs_"+(Get-Date).ToString('yyyy-MM-dd')+".txt"

## Count: 3

[string[]]$computerNames ="ServerName1", "ServerName2", "ServerName3"

try {

 #Function that logs a message to a text file

function LogWrite

{   param([string]$Message)

    ((Get-Date).ToString() + " - " + $Message) >> $LogFile;

}

Write-Host "Execution started"

LogWrite -Message "Execution started";

  ForEach ( $computerName in $computerNames ) {

    Write-Host "++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Magenta

    try {

     #get a service to check current status

    $svc = get-service -Name "ServiceName" -computername $computerName

      #check if service’s current status is stopped if yes then start it

     if ( $svc.Status -eq "Stopped") {

          (Get-Service -Name "ServiceName" -Computername $computerName).Start();

           Write-Host $computerName -NoNewline

         Write-Host ": the service has started successfully"

         LogWrite -Message "$computerName : the service has started successfully"

         }

         else{

           Write-Host $computerName -NoNewline

           Write-Host ": the service is already up and running"

           LogWrite -Message "$computerName : the service is already up and running"

            }

     }  

        catch {

        LogWrite -Message "$computerName : service reset failed- $_"

        Write-Host ": service start failed"

        Write-Host "Error : $_"

         }

     }

 Write-Host "Execution finished"

 LogWrite -Message "Execution finished"    

 }

    catch {

        LogWrite -Message "$computerName : service reset failed- $_"

        Write-Host ": service start failed"

        Write-Host "Error : $_"

         }

 

 

Thursday, 28 January 2021

Azure boards- a work items work flow with continuous integration (CI) an example.

 

 

1.1 Open a Defect/Bug

Create a work item type of Issue/Bug and assign to developer as shown in below screen shot.

 



 

1.2 Work Item Progress

Work items created can be seen in Work Items, Backlog or in Sprint under Boards section. Developer can start working on work items assigned to him/her by linking them to an existing branch or creating a new branch to get the latest source code from master branch.

Once the latest code pushed to developer’s branch, he/she can work in order to fix the bug, add new or modify existing code. On completion code can be reviewed by another person and approved. Once the changes reviewed and approved, then make it Complete which will merge and commit the latest change to master branch.


1.2.1 Create New Branch

Create a new branch from master to get the latest source code and start working on it in order to complete the assigned Work Item.


1.2.2 Deploy to Dev Stage

Developer can deploy the source code/configuration to a stage (Dev/Testing) where he/she can perform some tests to ensure that the defect has fixed and no new bug introduced. 

a.       To deploy your code/configuration to a stage where you want to test your code click on “Set up build”


b.      Choose app type under “configure you pipeline” and then azure subscription (Probably Collaudo subscription). In my case it is “Free Trial”.


c.       Select your app under azure subscription (if there is no app in that case, go to azure portal and create your app before setting up this build and deployment).

 

 

d.      Review you pipeline YAML file to ensure the correctness of your deployment and click on “Save and run” to start deployment.




e.      Deployment succeeded to Dev stage (below is result screen). Now a new version is available for testing.

 


1.2.3 Create a Pull Request

Once you tested you work in Dev stage then create a pull request to make you code available to be reviewed & approved by other team member in order to merge it with master branch.

 

1.2.4 Code/configuration Change, Review and Approval

Below screen shot shows, description about the code changes made and reviewed.

 


1.2.5 Merge your branch with Master

Post code reviewed and approved click on “complete” to open a page shown in below screen shot. Check the box as your choice and click on “complete merge”


1.3 Track Work Item History

Open a work item from azure boards to see development and deployment history. Click on the links to see details.

a.       Image 1



b.      Image 2