Wednesday, December 31, 2014

Powershell script to wakeup all sites in the SharePoint farm

$ErrorActionPreference = "Stop"

function Wakeup-Site{
          [Parameter(Mandatory = $true)]
          [String] $Url
     $request = [System.Net.HttpWebRequest] [System.Net.WebRequest]::Create($Url)
     $request.UseDefaultCredentials = $true
     $request.Method = "GET"
     $request.Accept = "text/html"
     $request.Timeout = 120000 #2 minutes

     Write-Host "Waking up site at $Url"
          # Get the response of $request
          $response = [System.Net.HttpWebResponse] $request.GetResponse()
     catch [Net.WebException]
    Write-Warning $_.Exception.Message
          if ($response)
              Remove-Variable ResponseObject

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq$null){
     Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPWebApplication |%{`
     $_.Sites |% { Wakeup-Site $_.Url}

Tuesday, December 30, 2014

Code online with Monaco in VS online

One of the most interesting and new features of Visual studio online is “Monaco”, the online code editor. With Monaco, you get a free, lightweight online code editor that is accessible from any device or platform and allows you to perform almost any tasks that can be done from a VS IDE.
To access Monaco follow the steps given below.
  • Open the Azure management portal
  • Click on websites and choose your website, which you want to edit using Monaco

  • Scroll down to the till you find the extensions tile on the website configurations section.
  • Click on the extensions and choose to add the visual studio online extension

  • After adding the extension, browse to see the code on the portal

  • On the let navigation panel, choose the Git icon to clone the vs online repository from the Git repository

  • Start editing the code from the browser.
  • After editing you can see the Git notifications for the changed files.

  • Click on this icon and commit the changes
  • Publish the changes and access the website to see your changes live!!!!

Sunday, December 28, 2014

DevOps world with visual studio online - Part 1

With visual studio online, you can easily host your code in the cloud, access it anywhere and support a variety of development platform. You can easily setup the cloud infrastructure using VS online in a couple of minutes without having to setup the server infrastructure. It also allows you to choose the version control system to host the files (Centralized – TFS or Distributed – Git), manage the project in the cloud by planning and tracking work items with fully integrated tools for agile planning and portfolio management.
To create a project and create a master branch in Git, you can create a new repository at a file location either by using the Git Bash or Git Extensions as given below.

Once the repository is created, you can now go ahead and create a project in visual studio at the location. You can also choose to host the site on cloud if needed and test the application.

After creating the project, next step is to add the files to the repository. You can use the git add command to add the files to the repository before committing it. Its also good to add a .gitignore file to the repository to mention the details of the files that you don’t want to include in the repository.
If you check the status of your repository at this point. It should look something like:

Once the git ignore file is created, you can add and commit the files to the master branch using the "git add ." and "git commit -m "my commit message"" commands
After commit your repository structure should look like

Once you have your master repository created in your local machine, you can now setup a remote git repository by using the command.
git remote -add origin "your vs online project url here"
To create a VS online account, you can either use the Azure management portal or use the Visual studio online website. I've used my Azure portal to manage my VS online account.
After successful creation of the account, you can create a new project in VS online and use the version control of your choice as given below.

To push the local repository contents to this remote repository, you need to use the git remote command and then push the contents to the remote repository.

Once published, the source code can be viewed from your VS online profile.

Next we’ll see, how to branch this, create builds, tests and deploy to Azure all using VS online.

Friday, December 26, 2014

DSC - Extending to Azure virtual machines

Being a fan of PowerShell DSC, and have benefited by the ease of use, I wanted to test the extensions on my Azure infrastructure. I have y VM configured with the Azure PowerShell SDK and can use this for the DSC setup. The next step is to create an authentication for the subscription by using the Azure AD.

To create an authentication method and manage your subscription using the Azure AD, follow the below given steps.
  • Use the Add-AzureAccount cmdlet and login to the portal to select a subscription. If you have multiple subscriptions, then you can use the Get-AzureSubscription cmdlet to view all your subscriptions and choose one. If you have a single subscription, the Add-AzureAccount cmdlet chooses the default subscription and uses it.
Add-AzureAccount –Credential (Get-Credential)
  • Later if you want to choose another subscription, you can use the Select-AzureSubscription cmdlet.
  • After authentication, Azure saves your credentials and closes the dialog window.
  • Once you have the account and authentication setup completed, you can create and work on the configurations.
  • To check whether DSC extension is available on the VM, you can use the Get-Command cmdlet to check whether the DSC modules are available as given below.

Create and push configurations on the Azure VM’s

You can create the configurations denoting the desired state for the VM by adding the resource configurations and save it to a config file. In the below sample, I’ve used the Registry resource to add a key to the registry for saving the settings for my application.

Configuration MyAppConfig{
    Node localhost{
        Registry MyAppSetting{
            Key = "HKEY_LOCAL_MACHINE\SOFTWARE\MySite"
            ValueName = "AllowedFunctions"
            ValueData = "READ:CONTRIBUTE"

When it comes to save a configuration on Azure, its bit different from the on premise machines. For Windows Azure, you need to publish the configuration to a storage container on the cloud services. The default storage container for DSC is windows-powershell-dsc container. You can provide another storage container by using the –ContainerName parameter for the Publish-AzureVMDscConfiguration cmdlet.
You can use the get-help command and check the options for the Publish-AzureVMDscConfiguration cmdlet for more customizations.

Before publishing the configuration, you need to create a storage context and use that to publish the configuration to. The storage context can be created by using the New-AzureStorageContext cmdlet. Once the context is created you can publish the configuration to the container created in the context using the Publish-AzureVMDscConfiguration as given below.

As you can see from the screenshot, the configuration is archived and stored on the storage container mentioned in the storage context created.

Next step is to enact to the configuration using the Set-AzureVMDscConfiguration cmdlet. You can use the cmdlet as given below.

Once the configuration is applied, you can see the VM updated with the changes