Friday, August 26, 2016

DSC PowerShell - Let's start

    #---------DSC Basic PowerShell---------#

   #GET DSC Modules
   Get-DSCResource




   #Get Windows Feature
   Get-WindowsFeature




   #Find Module Over Internet
   Find-Module -name *mva*
  

   #Find and Install Module
   Find-Module -name *mva* | Install-Module
   

   #Get DSC Status
   Get-DscConfigurationStatus




   #GET DSC Local Configuration Manager
   Get-DSCLocalConfigurationManager



  #---------DSC Configuration to Update LCM properties---------#

  #DSC Configuration
  [DSCResource()]
  Configuration LCMSetUp
  {
      param()
        LocalConfigurationManager
        {        
           ActionAfterReboot = 'ContinueConfiguration'
           RebootNodeIfNeeded = $True
           ConfigurationMode = 'ApplyAndAutoCorrect'
           ConfigurationModeFrequencyMins = 240
           RefreshMode = 'PUSH'
        }   
  }

  #Generate MOF File
  LCMSetUp -Outputpath "c:\DSC\LCMSetUp"

  #Update LCM Properties
  Set-DscLocalConfigurationManager -path "c:\DSC\LCMSetUp"  -force -verbose

  #GET DSC Local Configuration Manager
  Get-DSCLocalConfigurationManager 




#---------DSC Configuration to Install Windows Feature---------#


  #DSC Configuration
  [DSCResource()]
  Configuration WindowFeatureInstall
  {
      param()

      Node localhost
      {
          WindowsFeature IISInstall
          {
               Name="Web-Server"
               Ensure="Present"
              IncludeAllSubfeature = $true
          }
        WindowsFeature SMTP
         {
            Name = "SMTP-Server"          
            Ensure = "Present"
            IncludeAllSubFeature = $true
            DependsOn = "[WindowsFeature]IISInstall"
         }
         LocalConfigurationManager
         {        
           ActionAfterReboot = 'ContinueConfiguration'
           RebootNodeIfNeeded = $True
         }
       }
  }

   #Generate MOF File
   WindowFeatureInstall -Outputpath "c:\DSC\WFInstall"

   #Intall Configuration
   Start-DSCConfiguration -path "c:\DSC\WFInstall" -ComputerName localhost -force -verbose -wait




Tuesday, August 16, 2016

How to import data into Excel from VSTS

Go To Team tab and select New List


Connect to your VSTS Server, Select Project and Query




Data will be imported into Excel based on query


VSTS 101

Visual Studio Online or Visual Studio Team Service (VSTS) is now known as Team Service is SaaS version of Team Foundation Server. More or less it's provide all the functionality which is available in TFS with some additional functionality which support Cloud based deployment.

Features I like most are
• its cross platform and support Cloud as well on-premises deployment.
• It’s a single platform where you can manage projects, teams, build, testing, release and most important reporting capabilities which give you live status so you can act upon.
• You can integrate various automation testing tools either using REST API's or it’s also provide easy integration.
• You can add template based task to your build and release definitions and if it’s not there then you can add them through marketplace.
• It support load testing across the geographies.
• As its SaaS based service you need not to bother about its availability and time to time upgrade.
• App Insight can be easily integrated with Team Services

Limitations
• Like TFS it cannot be integrated with the SharePoint.
• No SSRS like TFS. Team Services come with basic reporting capabilities. If you need rich reporting you can integrate with Power BI.

Project Management
 Project Manager can easily create/ manage the plan and keep track of current/overall status (live).
PM can easily integrate VSTS with MS Project and Excel as well.

Process
• Agile: Choose Agile when your team uses Agile planning methods, including Scrum, and track development and test activities separately.
• CMMI: Choose CMMI when your team follows more formal project methods that require a framework for process improvement.
• Scrum: Choose Scrum when your team practices Scrum. This process works great if you want to track product backlog items (PBIs) and bugs on the Kanban board, or break PBIs and bugs down into tasks on the task board.

Build/ Build Triggers
• Continuous integration (CI): Select this trigger if you want the build to run whenever someone checks in code.
• Scheduled: Select the days and times when you want to run the build.
• TFVC gated check-in: If your code is in a Team Foundation version control repository, use gated check-in to protect against breaking changes.

Testing Features/ Support in VSTS
• Load testing – on premises, in the cloud
• Continuous testing in DevOps
• Manual testing
• Exploratory testing
• User acceptance testing
• Unit testing and IDE

Team Service pricing
By default there is no charges for MSDN users along with 5 free non MSDN users. If there is more than 5 non MSDN users you need to pay the price based on the number of users.


Find and Replace using PowerShell

Below PowerShell will help you to find and replace values in your files.

$rootPath = "C:\myfolder\*.*"
$keyTofind ="UserName"
$keyToReplace  ="Ajeet"
$configFiles = Get-ChildItem -Path $rootPath -Recurse |
Foreach-Object {
    $r = ($_ | Get-Content)
        $r = $r -replace $keyToFind ,$keyToReplace
        [IO.File]::WriteAllText($_.FullName, ($r -join "`r`n"))
}

P.S. Get-Content read contents of file not folder. Please add *.* after your folder path, else you will receive Access dined error.
Use Recurse to go through all folders way under your root folder.

Thursday, August 11, 2016

ARM PowerShell to create VM with existing Static Public IP

Static public IP is same as reserved IP in Azure classic. Once you create and assi

1 Create Static Public IP
        #Add Azure Account
         Add-AzureRMAccount
        #Set Subscription Context
        Get-AzureRmSubscription -SubscriptionName 'Visual Studio Professional with MSDN'| Set-AzureRmContext
        #RG Name
        $rgName = "DemoRG"
        #Location
        $locname = "West Europe"
        #Public IP Name
        $pipname = "MyPubIP"
       #DNS Name
       $domainname ="scriptdemo"
       #IP Allocation Method
       $ipallocation ="Static"
       #Create Azure Resource Group
       New-AzureRmResourceGroup -Name $rgName -Location $locname
       #Create Public IP
      New-AzureRmPublicIpAddress -Name $pipname -ResourceGroupName $rgName -DomainNameLabel $domainname -Location $locName -AllocationMethod $ipallocation
       #List Public IP
   Get-AzureRMPublicIPAddress

2. Create VM with existing Static Public IP
   #Storage Account Name
    $stName = "testst"
   #Deployment location
    $locName = "West Europe"
    #Resource Group Name
    $rgName = "DemoRG"
    #Public IP Name
    $pipname ="MyPubIP"
    #NIC Name
    $testnic ="TestNIC"
    #VM Name
    $vmname = "web"
    #Private IP
    $ipv = "10.0.0.5"
    #VNET
    $vnetName = "DemoVNET"
   #Subscription Credentials
    $cred = Get-Credential -Message "Type the name and password of the local administrator account."
   #Get VNET
    $vnet = Get-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name $vnetName
    #Create Storage
    $storageAcc =new-AzureRmStorageAccount -ResourceGroupName $rgName -AccountName $stName -Type "Standard_RAGRS" -Location $locName
    #Get Subnet
    $subnet = $vnet.Subnets[0].Id  
     #Create NIC
    $nic = New-AzureRmNetworkInterface -Name $testnic -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -PrivateIpAddress $ipv
    #Create VM
    $vm = New-AzureRmVMConfig -VMName $vmname -VMSize "Standard_A1"
    $vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName  $vmname  -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
    $vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"
    $vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
    $osDiskUri = $storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/WindowsVMosDisk.vhd"
    $vm = Set-AzureRmVMOSDisk -VM $vm -Name "windowsvmosdisk" -VhdUri $osDiskUri -CreateOption fromImage


Friday, August 5, 2016

Azure Resource Manager Templates

Enterprises have started adoption of Cloud, whether its  Private, Public or Hybrid cloud model. To get the advantage of on-demand, Agility and DevOps, clients are now not only demanding rapid, scalable, reusable, innovative cloud base solutions for their applications but also looking for consistent, test driven Infrastructure and configuration automation solutions.

There are lot of tools available in market which support Infrastructure and Configuration ‘As-Code’ as well as follow other DevOps culture and principals’ to support these requirements.

Azure new architecture bring the concept of Azure Resource Manager and Group. Azure Resource Manager enables you to work with the resources in your solution as a group. Azure Resource groups are logical containers that are used to group resources such as virtual machines, storage accounts, databases, websites, and others that share a common life cycle.
Azure Resource Manager Templates consists of JSON and expressions which you can use to construct values for deployment.

In an Azure Resource Manager template, you can define the resources to deploy for a solution, and specify parameters as well as variables that enable you to input values for different environments. The template consists of JSON and expressions which you can use to construct values for deployment. 

Resources deployed in parallel – Define the resource which can be deployed in parallel.
Resource dependency constraints enforced- Define dependencies for the resources which can only be provisioned after one or more other resources. Example: VM, before creating a VM you must have at least a storage account and a Virtual Network. 
Storage and Virtual Network can be provisioned parallel but VM needs to wait until both are not provisioned.
Template language provides some built-in functions – this help to manipulate the strings.
By using the ARM you can
  •  Ensure Idempotency
  • Simplify Orchestration
  •  Simplify Roll-back
  • Provide Cross Resource Configuration and update support

        Azure Resource Templates are:
  • Source files, can be checked-in
  • Specifies resources and dependencies
  • Support parameterized input/output

Resource Manager provides several benefits
  •           You can deploy, manage, and monitor all of the resources for your solution as a group, rather than handling these resources individually.
  •          You can repeatedly deploy your solution throughout the development lifecycle and have confidence your resources are deployed in a consistent state.
  •          You can use declarative templates to define your deployment.
  •          You can define the dependencies between resources so they are deployed in the correct order.
  •         You can apply access control to all services in your resource group because Role-Based Access Control (RBAC) is natively integrated into the management platform.
  •         You can apply tags to resources to logically organize all of the resources in your subscription.

Tags:

Tags help you to view billing for your organization by viewing the rolled-up costs for the entire group or for a group of resources sharing the same tag.

in upcoming post, I will talk more concept about ARM template and how to create them.