Assert-AutoShutdownSchedule 2.0.2 BST fix

If you are using this in your Azure subscription, you might want to consider a fix for BST

Around line 60

$VERSION = "2.0.2"
 
# DEAL WITH BST
$bst_on="03/27/2016 01:00:00"
$bst_off="10/30/2016 02:00:00"
 
#2015	Sunday, 29 March, 01:00	Sunday, 25 October, 02:00
#2016	Sunday, 27 March, 01:00	Sunday, 30 October, 02:00
#2017	Sunday, 26 March, 01:00	Sunday, 29 October, 02:00
#2018	Sunday, 25 March, 01:00	Sunday, 28 October, 02:00
#2019	Sunday, 31 March, 01:00	Sunday, 27 October, 02:00
...

and then around line 67

function CheckScheduleEntry ([string]$TimeRange)
{	
	# Initialize variables
	$rangeStart, $rangeEnd, $parsedDay = $null
	$currentTime = (Get-Date).ToUniversalTime()
    $midnight = $currentTime.AddDays(1).Date
 
 
	# BST	
	if($currentTime -ge $bst_on -and $currentTime -le $bst_off) {
		write-output "Adjusting $currenttime to BST"
 
		$currentTime = ($currentTime.addHours(1))
 
		write-output "BST is $currenttime"
	}	        
...

and then around line 283

# Main runbook content
try
{
    $currentTime = (Get-Date).ToUniversalTime()
 
	# BST
	if($currentTime -ge $bst_on -and $currentTime -le $bst_off) {
		write-output "Adjusting $currenttime to BST"
 
		$currentTime = ($currentTime.addHours(1))
 
		write-output "BST is $currenttime"
	}
...

Remember to publish your script after you edit it, and of course, test it !

Make sure your Azure ARM VM’s are not a threat

The script below will deploy or un-deploy the Azure antimalware extension from all VM’s in a resource group. You need to ensure the anySettings and SqlSettings are correct for your world.

[cmdletbinding()]
param (
    $rgname="release4.11.0.1",
    [bool]$adding = $true
)
 
# Get-AzureVMAvailableExtension | fl -Property Publisher, ExtensionName
 
$location="north europe"
$extName="IaasAntimalware"
$extType="IaaSAntimalware"
$extPublisherName="Microsoft.Azure.Security"
 
 
$anySetting = @"
{
"AntimalwareEnabled": true, 
"RealtimeProtectionEnabled": true,
"ScheduledScanSettings": {
       "isEnabled": true,
       "day": 1,
       "time": 120,
       "scanType": "Quick"
       },
"Exclusions": {}
}
"@
 
$sqlSetting = @"
{
"AntimalwareEnabled": true, 
"RealtimeProtectionEnabled": true, 
"ScheduledScanSettings": {        
       "isEnabled": true, 
       "day": 1, 
       "time": 120, 
       "scanType": "Quick"  
       },        
       "Exclusions": {
             "Extensions": ".mdf;.ldf",
             "Paths": "D:\\;E:\\",
             "Processes": "excludedproc1.exe;excludedproc2.exe"    
             }
       }
"@
 
 
$allVersions= (Get-AzureRmVMExtensionImage -Location $location -PublisherName "$extPublisherName" -Type "$extType").Version
$versionString = $allVersions[($allVersions.count)-1].Split(".")[0] + "." + $allVersions[($allVersions.count)-1].Split(".")[1]
 
 
$vms = get-azurermvm -ResourceGroupName $rgname
 
$vms | % {
    $thisVm = $_
 
    $whichSetting="Any"
    $setting = $anySetting
 
    if($thisVm.Name -like "*-sql") {
        $setting = $sqlSetting
        $whichSetting="SQL"
    }
    if($adding) {
 
    write-host ("ADDING $whichsetting setting to " + $thisVm.Name)
 
    Set-AzureRmVMExtension `
            -ResourceGroupName $rgname `
            -VMName $thisVm.Name `
            -Name "$extName" `
            -Publisher "$extPublisherName" `
            -TypeHandlerVersion "$versionString" `
            -ExtensionType "$extType" `
            -Location "$location" `
            -SettingString "$setting"
    }
    else {
        write-host ("REMOVING FROM " + $thisVm.Name)
        Remove-AzureRmVMExtension -ResourceGroupName $rgname -VMName $thisVm.Name -Name "$extName"
    }
}

All my Azure VPN connections just vanished

As part of the process for setting up VPN’s in azure, you may need to download the network.xml config file, edit it and upload it back to Azure.

Be warned that if you upload anything but a flat text file, azure may well accept the file, but stop showing your VPN connections on the portal.

So if yours vanish, check the format of the file you uploaded last.

Time to wake up the blog

I have spent the last 18 months – 2 years building tooling to automate the stand up / configure / tear down of various Azure virtual environments for various clients.  This is partly why the blog has been very quiet 🙂

I figure I have a pretty stable and workable solution based upon custom PowerShell scripts, some base VM images and some scheduled PowerShell tasks.

While I was busy doing this, M$ were building pretty much the same thing, calling it Azure Resource Manager.

This is what I must now get to grips with, cross technology training seems to be imminent.

To be fair, the M$ offering does at first glance look slightly improved on my ‘original’

Azure Resource Manager

SharePoint on-line 2013 web service call to execute a CAML query against a list

Well, talk about a journey; If you will be doing any SharePoint on-line 2013 workflows, you are going to need to understand this.

These were my inspiration
Great tutorial
Great Fiddler reference

Without those two, I would still be there at Christmas.  This is my summary;

I am querying a list in a sub web called ‘Config’ for a list Called ConfigItems

First you need to grab the auth cookies, browse to https://yourSPonline.sharepoint.com

FIDDLER: Get ContextInfo to grab a form digest from: This is a GET
https://yourSPonline.sharepoint.com/_api/contextinfo”

User-Agent: Fiddler
Cookie: rtFa+sO9PIAAAAA==; FedAuth=77u/PD94bWwg==
Content-Type: application/json;odata=verbose;
Content-Length: 0
Accept: application/json;odata=verbose;
Host: yourSPonline.sharepoint.com

Now, examine the json, find formdigest
Add it to your headers as X-RequestDigest
X-RequestDigest: 0x445623A1758C83A5,25 Mar 2014 07:37:55 -0000
So now you have

User-Agent: Fiddler
Cookie: rtFa+sO9PIAAAAA==; FedAuth=77u/PD94bWwg==
Content-Type: application/json;odata=verbose;
Content-Length: 0
Accept: application/json;odata=verbose;
Host: dev3.sharepoint.com
X-RequestDigest: 0x445623A1758C83A5,25 Mar 2014 07:37:55 -0000

Now you can call list api’s – Get all items from a sub web called Config USE A GET

https://yourSPonline.sharepoint.com/Config/_api/web/lists/getByTitle(‘configitems’)/items”

or via CAML, this is a PUT

https://yourSPonline.sharepoint.com/Config/_api/web/lists/getByTitle(‘configitems’)/GetItems(query=@v1)?@v1={“ViewXml”:”<View><Query><ViewFields><FieldRef%20Name=’Title’/><FieldRef%20Name=’ItemValue’/></ViewFields><Where><Eq><FieldRef%20Name=’ItemGroup’/><Value%20Type=’Choice’>SomeWorkflow</Value></Eq></Where></Query></View>”}
or
https://yourSPonline.sharepoint.com/Config/_api/web/lists/getByTitle(‘configitems’)/GetItems(query=@v1)?@v1={“ViewXml”:”<View><Query><ViewFields><FieldRef%20Name=’Title’/><FieldRef%20Name=’ItemValue’/></ViewFields><Where><Eq><FieldRef%20Name=’ItemGroup’/><Value%20Type=’Choice’>None</Value></Eq></Where></Query></View>”}

 

 

SharePoint on-line : simple 2013 workflow to send an email

Struggled for a while with this.

  • Download latest SharePoint designer 2013 (some early releases were buggy I am told)
  • Apply any SharePoint designer updates (Had an issue with designer not able to load visio)
  • Make sure the “Acount” Designer is using is your 0n-line account not your desktop account
  • Connect to an site collection (Not your admin site collection :-))
  • Enable site feature “Workflows can use app permissions”
  • Grant app permissions in your site collection see this (http://msdn.microsoft.com/en-us/library/jj822159.aspx)
  • Create a (in my case) site workflow
  • Add an app step
  • Inside the app step Include a send email action, send it to yourself
  • Publish the workflow
  • Go to site settings -> Site content -> site workflows
  • Execute your workflow
  • Check your inbox of the email address specified in your Profile

That’s all folks.

 

Search fix (Simple single server farm only)

I am constantly having issues with three things on SharePoint 2013 farms

  • Search
  • UP Synch
  • Managed metadata

So to search.  Often following a reboot the search admin screen will show one component or another in a non ideal state.  Red cross, Yellow warning triangle etc.

googling will show you many and various ways to fix some / all or none of these issues, re create index, flush SharePoint Caches, re provision Search host, and the list goes on and on and on…

For times when all these fail me, I have crafted this simple script to surgically take out a broken component and replace it with a shiney new one.  It is intended for single server with simple search topology and if you use it you are responsible for ensuring the code is fit for ‘your’ purpose.

I think the script is self explanatory.

 

[cmdletbinding()]
param (
    [Parameter(Mandatory=$true)]
    $component # Crawl, Admin, Query, Content, Analytics, Index
)
 
write-host "ONLY USE ON A SIMPLE, SINGLE SERVER FARM,  IF THIS IS THE CASE, COMMENT OUT NEXT LINE AND RE RUN"
break
 
# Grab the Search Service Instance
#
$Sinstance = Get-SPEnterpriseSearchServiceInstance -Identity $env:COMPUTERNAME
 
# Grab active topology
#
$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
 
# Create a clone of active to work with
#
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active
 
# grab component giving us trouble
#
$problem = Get-SPEnterpriseSearchComponent -SearchTopology $clone | ? {$_.Name -like "$component*"}
$problem
 
# Remove troublesome component from clone
#
if($problem.GetType().ToString() -eq "System.Object[]") {
    $problem | Remove-SPEnterpriseSearchComponent -Identity $_ -SearchTopology $clone -Confirm:$false
}
else {
    Remove-SPEnterpriseSearchComponent -Identity $problem -SearchTopology $clone -Confirm:$false
}
 
switch($component) {
    "Crawl" {
        New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $Sinstance
    }
 
    "Admin" {
        New-SPEnterpriseSearchAdminComponent -SearchTopology $clone -SearchServiceInstance $Sinstance
    }
 
    "Query" {
        New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $Sinstance
    }
 
    "Content" {
        New-SPEnterpriseSearchContentProcessingComponent  -SearchTopology $clone -SearchServiceInstance $Sinstance
    }
 
    "Analytics" {
        New-SPEnterpriseSearchAnalyticsProcessingComponent  -SearchTopology $clone -SearchServiceInstance $Sinstance
    }
 
    "Index" {
        New-SPEnterpriseSearchIndexComponent  -SearchTopology $clone -SearchServiceInstance $Sinstance    
    }
 
    default {
        write-host "Dont understand" $component
    }
}
 
# Make clone active
#
Set-SPEnterpriseSearchTopology -Identity $clone
 
# Clear out Inactive topologies
#
get-SPEnterpriseSearchTopology -SearchApplication $ssa | ? {$_.state -ine "Active" } | Remove-SPEnterpriseSearchTopology -Confirm:$false