Windows Azure – Exam preperation Links 70-533


Troubleshooting Scenario 5 – Internal Server Error 500 in WebRole

http://blogs.msdn.com/b/kwill/archive/2013/09/19/troubleshooting-scenario-5-

internal-server-error-500-in-webrole.aspx

Connecting Web or Worker Roles to a Simple Virtual Network in Windows Azure
http://michaelwasham.com/2012/08/06/connecting-web-or-worker-roles-to-a-simple-virtual-

network-in-windows-azure/

How to Configure Cloud Services
http://azure.microsoft.com/en-us/documentation/articles/cloud-services-how-to-configure/

Azure VM Extensions and Features
http://msdn.microsoft.com/en-us/library/azure/dn606311.aspx

Configuring Azure Virtual Machines for Optimal Storage Performance
http://blogs.msdn.com/b/mast/archive/2014/10/14/configuring-azure-virtual-machines-for-

optimal-storage-performance.aspx

Exploring Windows Azure Drives, Disks, and Images
http://blogs.msdn.com/b/windowsazurestorage/archive/2012/06/28/exploring-windows-azure-

drives-disks-and-images.aspx

Manage the availability of virtual machines
http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-manage-

availability/

Why using an Afinity Group
http://msdn.microsoft.com/en-us/library/hh973190.aspx

http://msdn.microsoft.com/en-us/library/azure/gg981929.aspx

Virtual Network FAQ
http://msdn.microsoft.com/en-us/library/azure/dn133803.aspx

How to Create a Virtual Network in Azure
http://social.technet.microsoft.com/wiki/contents/articles/17789.how-to-create-a-virtual-

network-in-azure.aspx

Connecting Windows Azure Virtual Machines with PowerShell
http://michaelwasham.com/tag/powershell/

Network Isolation Options for Machines in Windows Azure Virtual Networks
http://azure.microsoft.com/blog/2014/03/28/network-isolation-options-for-machines-in-

windows-azure-virtual-networks/

Health Endpoint Monitoring Pattern
http://msdn.microsoft.com/en-us/library/dn589789.aspx

Azure Web Sites Diansotics
http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-troubleshoot-

visual-studio/#readlogfiles

Simple Powershell scripting with Azure Powershell cmdlets
http://codebetter.com/glennblock/2012/12/26/simple-powershell-scripting-for-azure-

powershell-cmdlets/

Windows Azure Web Sites: How Application Strings and Connection Strings Work
http://azure.microsoft.com/blog/2013/07/17/windows-azure-web-sites-how-application-

strings-and-connection-strings-work/

How to Configure Websites
http://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/

Enabling Remote PowerShell for SharePoint Maintainence and Deployments


While working with higher number of servers in the farm it some times become hard to execute maintainence scripts on every server in the farm including SharePoint, SQL and OWA Servers.  I recently worked on script to enable PowerShell remoting from the working server.  The process will be the following

Step 1: Enable Delegation for Credentials

First I will Enable the Working server to do enable delegation for credentials.  This basicly allows me to execute script with any user who has access to SharePoint. 

Step 2: Copy Script Files on all SharePoint Servers

This step will allow you to copy scripts folder to all servers you have specified.  You can completly automate this step if you are executing the copy script on one of the SharePoint Servers using Get-SPServer but In the example I was running the scripts out of SharePoint Farms.  I have another blog that

Step 3: Enable Remote PowerShell

Execute the 4 lines PowerShell script that will enable PowerShell Remoting and increase the memory and shell per users.

Step 4: Test the Remote PowerShell is Working

This script will perform some basic testing if the Remote PowerShell is working.  For SharePoint Servers it will Load the SharePoint Snapin and then check the version of SharePoint Farm as well as List the content database title and description.  For Non SharePoint Server it will try to get the server name using Get-WmiObject.

The scripts are given below.

1-Enable-DeletgationforSearchServersOnToolsServer.ps1

Write-Host "==================================================================" -ForegroundColor Green
Write-Host "You may need to Restart the Tools server for changes to take effect..." -ForegroundColor Yellow
Write-Host "==================================================================" -ForegroundColor Green
$Servers = @("Server1", "Server2", "Server3", "Server4")
foreach($Server in $Servers)
{
    $FQDN = $Server + ".fullyqualitydomain.contoso.com"
    Write-Host $FQDN -ForegroundColor Yellow
    Enable-WSManCredSSP -Role client -DelegateComputer $FQDN
    Write-Host "Delegation is Completed for $Server" -ForegroundColor Green
}
Write-Host "Delegation is Completed for all servers..."
Write-Host "Run the 2nd Copy-RemoteScript script and then Restart the Tools Server..." -ForegroundColor Red

2-Copy-RemoteScriptFolderToAllServers.ps1

Write-Host "===================================================" -ForegroundColor Green
Write-Host "Copying Files to all servers" -ForegroundColor Green
Write-Host "===================================================" -ForegroundColor Green
$Servers = @("Server1", "Server2", "Server3", "Server4")
foreach($Server in $Servers)
{
    $Location = "\\$Server\e$\RemoteScripts"
    Write-Host $Location
    Robocopy.exe E:\RemoteScripts\ $Location /MIR 
}
Write-Host "Files are Copy to All serversin E:\RemoteScripts..." -ForegroundColor Green

3-Enable-RemotingOnThisServer.ps1 (Execute on All Servers one by one)

Write-Host "===================================================" -ForegroundColor Green
Write-Host "Enabling Remote PowerShell and setting WRM Memory" -ForegroundColor Green
Write-Host "===================================================" -ForegroundColor Green
Set-ExecutionPolicy -ExecutionPolicy unrestricted
winrm quickconfig
Enable-WSManCredSSP -Role server
winrm set winrm/config/winrs '@{MaxShellsPerUser="25"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="600"}'
Write-Host "Enabling Remote PowerShell and setting WRM Memory Completed.  Run the same on other servers one by one" -ForegroundColor Green

4-Test-RemotePowerShellOnAllServers.ps1 (Execute this script on Working Server from where you want to execute the script)

Write-Host "==================================================================" -ForegroundColor Green
Write-Host "You Must be a SharePoint Administrator to Test this script" -ForegroundColor Green
Write-Host "==================================================================" -ForegroundColor Green
Write-host "Press enter if you are a SharePoint Administrator or Press Ctrl + C to Cancel" -ForegroundColor Yellow
Read-Host 
Write-Host "Testing Remote PowerShell Completed on all Non SharePoint Servers..." -ForegroundColor Green

$farm = Get-Credential
$Servers = @("Server1", "Server2")
foreach($Server in $Servers)
{
    $FQDN = $Server + ".fullyqualitydomain.contoso.com"
    Write-Host "Testing Remote PowerShell on SharePoint : $FQDN" -ForegroundColor Yellow
    $s = New-PSSession -ComputerName $FQDN -Authentication CredSSP -Credential $farm
    Invoke-Command -Session $s -ScriptBlock { add-pssnapin Microsoft.SharePoint.PowerShell -ea 0 }
    Invoke-Command -Session $s -ScriptBlock { get-spfarm | Select Version }
    Invoke-Command -Session $s -ScriptBlock { get-spcontentdatabase | Select Id, Name }
    Get-PSSession | Remove-PSSession
    Write-Host "Testing Remote PowerShell Completed on $Server" -ForegroundColor Green
}

Write-Host "Testing Remote PowerShell Completed on SharePoint Servers..." -ForegroundColor Green
Write-Host "Starting on Non SharePoint Servers..." -ForegroundColor Yellow
$Servers = @("Server3", "Server4")
foreach($Server in $Servers)
{
    $FQDN = $Server + ".fullyqualitydomain.contoso.com"
    Write-Host "Testing Remote PowerShell on Non SharePoint : $FQDN" -ForegroundColor Yellow   
    $s = New-PSSession -ComputerName $FQDN -Authentication CredSSP -Credential $farm
    Write-Host "Getting Server name using WMI..." -ForegroundColor Yellow
    Invoke-Command -Session $s -ScriptBlock { $(Get-WmiObject Win32_Computersystem).name }
    Get-PSSession | Remove-PSSession
    Write-Host "Testing Remote PowerShell Completed on $Server" -ForegroundColor Green
}
Write-Host "Testing Remote PowerShell Completed on all Non SharePoint Servers..." -ForegroundColor Green

Note: If you do not see the right output fromt his command you must restart the server.  I have to restart the working server in 2 seperate occasions.  Now you can do anything on SharePoint Servers without even loggin to the servers.

Sharepoint Web Config Modification Using PowerShell


Below is an example of how to add a web configuration modification in SharePoint Using PowerShell.  The script has a pience of function to add the Location configuration for timeout as well as a function that allows you to delete the modication done by the user.  Rew points to consider when you want to write that code.

Owner: Every configuration is tagged with the owner and can be retreived using the propertly.  Be careful in making different web config entries as if you set a single Owner all the configuration can get cleaned up.

$configMod.Name = “add[@name=””location””]” : Define the Name of entry you did in value.
$configMod.Path = “/configuration” : Define the place you want to add the entry.  You can extended it with /Configuration/SharePoint/SafeControls/
$configMod.Value = “<location path=’_vti_bin/sitedata.asmx’></location> : Actual Full String.  use Double (Double Quotes “”) to cover string and make sure you are using the right double quotes “” by pasting the script in notepad or PowerShell ISE.

Write-Host "===============================================" -ForegroundColor Yellow
Write-Host "Adding Timout Value to SharePoint Web.Config" -ForegroundColor Yellow
Write-Host "===============================================" -ForegroundColor Yellow

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function RemoveMyEntries($webapp, $Owner)
{
   $oldMods = @();
   $webapp.WebConfigModifications | where-object { $_.Owner -eq $Owner } | foreach-object { $oldMods = $oldMods + $_}
   Write-Host $oldMods.Count "Items Found"
   $oldMods | foreach-object { $webapp.WebConfigModifications.Remove($_) }
   
   #$webapp.Update()
   #$webapp.Parent.ApplyWebConfigModifications()
}

$Owner = "Jerry"
$WebApp = Get-SPWebApplication http://portal.hp.com

Write-Host $WebApp
#Write-Host "Removing All Entries Made by $Owner"
RemoveMyEntries $WebApp $Owner 
sleep -Seconds 10
#Write-Host "Removed All Entries Made by $Owner"

Write-Host "Creating New Entry"
$configMod = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$configMod.Name = "add[@name=""location""]"
$configMod.Path = “/configuration”
$configMod.Value = "<location path='_vti_bin/sitedata.asmx'><system.web><httpRuntime executionTimeout='3600'/></system.web></location>"
$configMod.Sequence = 0
$configMod.Type = 0 #for enum value of SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode
$configMod.Owner = $Owner
$WebApp.WebConfigModifications.Add($configMod)
$WebApp.Update()
$WebApp.Parent.ApplyWebConfigModifications()
Write-Host "Web Application Entry has been added. Wait for a couple of minutes and then test it out" -ForegroundColor Green

Creating extended Search topology in Sharepoint 2013


If you are creating a Search service application in SharePoint 2013 and want to create an extedned search topology, the only choice you have is “PowerShell”.  Althought the process looks bit complex but if you spent few minutes in the PowerShell script below it will become very simply.

Below script uses a 9 server Search Toplogy where we have the following configuration

  • 3 Query Processing Components
  • 3 Index Partitions and their Replicas
  • 2 Admin Components
  • 2 Crawl Components
  • 2 Analytic Components
  • 2 Content Processing Components

You can see that we have redundant search components.  with this topology we were planning to cover 30 content sources with over 40 Million items in in the index.

First on the root define the Servers and mention their role.  I used an Excel sheet first then moved them in Powershell

Note: If you are extending an existing which already has index.  it is good to RESET Index.  Additonally you can pause the Search Service Applicaton and then resume it after new topology.

$hostA = Get-SPEnterpriseSearchServiceInstance -Identity “SERVER135" #Query Processing -  Index 0
$hostB = Get-SPEnterpriseSearchServiceInstance -Identity "SERVER136" #Query Processing -  Index 1
$hostC = Get-SPEnterpriseSearchServiceInstance -Identity "SERVER137" #Query Processing -  Index 2

$hostD = Get-SPEnterpriseSearchServiceInstance -Identity “SERVER138" #Analytics Processing - Index 2 (Replica)
$hostE = Get-SPEnterpriseSearchServiceInstance -Identity “SERVER139” #Analytics Processing - Index 1 (Replica)
$hostF = Get-SPEnterpriseSearchServiceInstance -Identity “SERVER140" #Index 0 (Replica)

$hostG = Get-SPEnterpriseSearchServiceInstance -Identity “SERVER141" #Content Processing - Crawl Component
$hostH = Get-SPEnterpriseSearchServiceInstance -Identity “SERVER142" #Content Processing - Crawl Component

Next Step is to Start the Enterprise Search Service Instance on these servers

Start-SPEnterpriseSearchServiceInstance -Identity $hostA
Start-SPEnterpriseSearchServiceInstance -Identity $hostB
Start-SPEnterpriseSearchServiceInstance -Identity $hostC
Start-SPEnterpriseSearchServiceInstance -Identity $hostD
Start-SPEnterpriseSearchServiceInstance -Identity $hostE
Start-SPEnterpriseSearchServiceInstance -Identity $hostF
Start-SPEnterpriseSearchServiceInstance -Identity $hostG
Start-SPEnterpriseSearchServiceInstance -Identity $hostH

Now wait for all services to be provisioned.  You can check the status using the script below

//Wait until status of “OnLine” by issuing the following commands:

Get-SPEnterpriseSearchServiceInstance -Identity $hostA | Select Server, Status
Get-SPEnterpriseSearchServiceInstance -Identity $hostB | Select Server, Status
Get-SPEnterpriseSearchServiceInstance -Identity $hostC | Select Server, Status
Get-SPEnterpriseSearchServiceInstance -Identity $hostD | Select Server, Status
Get-SPEnterpriseSearchServiceInstance -Identity $hostE | Select Server, Status
Get-SPEnterpriseSearchServiceInstance -Identity $hostF | Select Server, Status
Get-SPEnterpriseSearchServiceInstance -Identity $hostG | Select Server, Status
Get-SPEnterpriseSearchServiceInstance -Identity $hostH | Select Server, Status

Now Next Step is to Get the Search Service Application and Create a new Search Topology.  To reuse existing topology you can clone it.

$ssa = Get-SPEnterpriseSearchServiceApplication
$newTopology  = New-SPEnterpriseSearchTopology -SearchApplication $ssa

Next Step would be to Create the Components.  Below i am creating by the hosts for easier managment.

Host A

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostA
New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostA -IndexPartition 0

Host B

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostB
New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostB -IndexPartition 1

Host C

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostC
New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostC -IndexPartition 2

Host D

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostD
New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostD -IndexPartition 2

Host E

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostE
New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostE -IndexPartition 1

Host F

New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $hostF -IndexPartition 0
New-SPEnterpriseSearchAdminComponent -SearchTopology $newTopology -SearchServiceInstance $hostF

Host G

New-SPEnterpriseSearchCrawlComponent -SearchTopology $newTopology -SearchServiceInstance $hostG
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostG

Host H

New-SPEnterpriseSearchCrawlComponent -SearchTopology $newTopology -SearchServiceInstance $hostH
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $hostH

Now Set the topology as Active Topolgy

Set-SPEnterpriseSearchTopology -Identity $newTopology
iisreset 
Get-SPEnterpriseSearchTopology -SearchApplication $ssa

Remove the Old Toplogy

#Removing Old Topology Get-SPEnterpriseSearchTopology -SearchApplication $ssa #Note the ID of the old toplogy $OldTopology = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Identity 64e1b2ba-bfc6-44d4-9ebe-9f9b5952bdd0 #To Verify $OldTopology Remove-SPEnterpriseSearchTopology -Identity $OldTopology.Id -SearchApplication $ssa

#You are all Set now Open Central Administration –> Manage Service Applications –> Search #Service Application –> Review the components and all should show
#Green check mark. Refresh the browse if they take time to get green

Exporting SharePoint document using powershell


Few months back I found this PowerShell script and extended it to support a site collection.

$ver = $host | select version 
if($Ver.version.major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"} 
if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0)) 
{ 
Add-PSSnapin Microsoft.SharePoint.PowerShell  -ErrorAction SilentlyContinue
} 


$Directory = "c:\ExportFiles\" 
 
## 
#Define Functions 
## 
 
Function TrimDirectory ($Directory) 
{ 
    if($Directory.EndsWith("\")) 
    { 
        Set-Variable -Name Directory -Value ($Directory.Substring(0, ($Directory.Length -1))) -Scope Script 
    } 
} 
 
Function EnsureDirectory ($Directory) 
{ 
    if(!(Test-Path $Directory)) 
    { 
        TrimDirectory $Directory 
                 
        New-Item -Path $Directory -ItemType Directory 
    } 
} 
 
Function ExportFiles ($SPList, $GalleryName) 
{ 
    EnsureDirectory ($Directory + "\" + $GalleryName) 
    Write-Host $SPlist.rootfolder.files.count
    foreach ($file in $SPlist.rootfolder.files) 
    { 
         
        $DestinationFile = ($Directory + "\$GalleryName\" + $file.name) 
        $FileBinary = $file.OpenBinary() 
        $FileStream = New-Object System.IO.FileStream($DestinationFile), Create 
        $Writer = New-Object System.IO.BinaryWriter($FileStream) 
        $Writer.write($FileBinary) 
        $Writer.close() 
    } 
     
    foreach($Folder in $SPList.Folders) 
    { 
         
        if($ParentFolderURL) 
        { 
            Remove-Variable ParentFolderURL 
        } 
     
        $i = 0 
     
        $folderURL = $Folder.url.split("/") 
     
        while($I -lt ($FolderURL.count -1)) 
        { 
            $ParentFolderURL = "$ParentFolderURL/" + $FolderURL[$I] 
            $I++ 
        } 
         
        $DownloadDirectory = ($Directory + "\$GalleryName\" + $Folder.url.substring($SPList.RootFolder.Url.Length)) -replace "/", "\" 
         
        EnsureDirectory $DownloadDirectory 
         
        foreach ($File in $Folder.Folder.Files) 
        { 
            $DestinationFile = ($Directory + "\$GalleryName\" + $Folder.url.Substring($SPList.Rootfolder.URL.Length) + "\" + $file.name) -replace "/", "\" 
             
            $FileBinary = $file.OpenBinary() 
 
            $FileStream = New-Object System.IO.FileStream($DestinationFile), Create 
 
            $Writer = New-Object System.IO.BinaryWriter($FileStream) 
 
            $Writer.write($FileBinary) 
 
            $Writer.close() 
        } 
         
         
    } 
} 
 
 
## 
#Start Script 
## 
 
 
TrimDirectory $Directory 
EnsureDirectory $Directory 

Start-SPAssignment -Global

$SiteURL = "http://intranet.hp.com"
$Site = Get-SPSite $SiteURL

foreach($Web in $Site.AllWebs)
{

    foreach($List in $Web.Lists)
    {
        if(!$List.Hidden)
        {
            $Title = $List.Title
            Write-Host $Title
            $ListFolder = New-Item -Path ($Directory + "\$Title") -ItemType Directory -ErrorAction SilentlyContinue
            ExportFiles $List $Title.ToString()
        }
    }
}

Stop-SPAssignment -Global

#New-Item -Path ($Directory + "\Documents") -ItemType Directory 
#$Documents = $Site.RootWeb.Lists | ? {$_.title -eq "Documents"} 
#ExportFiles $Documents "Documents" 

Powershell – current folder and file


While working with PowerShell some times if is required to access resources like XML and csv files from local folder where the PS1 file is placed.  PowerShell 3.0 has made it easy for us.  Use the script below to get current folder, file and execution path

$thisfolderIncludingFileName = Split-Path -parent $MyInvocation.MyCommand.Definition
$currentScriptName = $MyInvocation.MyCommand.Name

$currentExecutionPath = $thisfolderIncludingFileName.Replace($currentScriptName, "");

Write-Host "Current Folder with FileName : $thisfolder"
Write-Host "Current File Name : $currentScriptName"
Write-Host "Current Exeuction Path $currentExecutionPath"

image

Note: I have find out that you must save your script file before you can test these calls and you can not get this path when you press F8 to execute any script line by line.

collecting and merging uls logs


During Troubleshooting and specially working with Microsoft Support team we have to collect logs from all servers in the farm and send it to them.  The issue is that these logs will have more information than what we have with out issue.  So there is the best option.

  1. Create a File
  2. Enable Verbose Ex or Verbose Logging
  3. Reproduce the issue
  4. Disable Verbose Ex or Verbose Logging
  5. Merge the Log Files

Luckily the script below will do that. 

Note: The output file will grow very large in case the issue has multiple steps for repduction + VerboseEx logging produce lot of extra information.  Change the verbose if you are not looking for EX.

save the below script as Ps1 and you are ready.

#Title: ULS Collector
#Description: This script will collect the ULS logs by way of merging them from every server.

#Add SharePoint Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set file location
$path = Read-Host "Please enter the full path for the log file along with the file name";

#Increase logging to verbose
Write-Host "Increasing ULS logging to VerboseEx...";
Set-SPLogLevel -TraceSeverity VerboseEx -EventSeverity Verbose;

#Prompting to start and setting the start time
Read-Host "Hit enter to start, then reproduce the issue"
$starttime = Get-Date -Format "MM/dd/yyyy HH:mm:ss"
Write-Host "The start time for the log file is $starttime";

#Prompting to stop and setting the end time
Read-Host "Hit enter to end"
$endtime = Get-Date -Format "MM/dd/yyyy HH:mm:ss"
Write-Host "The ending time for the log file is $endtime";

#Setting the log level back to normal
Clear-SPLogLevel

#Merging the logs to the specified path using the start and end times
Merge-SPLogFile -Path $path -Overwrite -StartTime $starttime -EndTime $endtime;
Write-Host "Logs have been collected. Resetting the log level back to normal."

New-SPLogFile