This is how to quickly check an xml file for specific content:
[xml]$a = get-content D:\Path\To\File\DailyPaper.xml
$a.SelectNodes(“//Language[@iso=’de’]/Byline”)
Random outpourings of a software developer
This is how to quickly check an xml file for specific content:
[xml]$a = get-content D:\Path\To\File\DailyPaper.xml
$a.SelectNodes(“//Language[@iso=’de’]/Byline”)
From:
| mkdir "~\Desktop\AzureFriday" | |
| cd "~\Desktop\AzureFriday" | |
| [Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath | |
| $a = ([xml](new-object net.webclient).downloadstring("http://channel9.msdn.com/Shows/Azure-Friday/feed/mp4high")) | |
| $a.rss.channel.item | foreach{ | |
| $url = New-Object System.Uri($_.enclosure.url) | |
| $file = $url.Segments[-1] | |
| "Downloading: " + $file | |
| if (!(test-path $file)) | |
| { | |
| (New-Object System.Net.WebClient).DownloadFile($url, $file) | |
| } | |
| } |
mkdir “~\Desktop\AzureFriday”cd “~\Desktop\AzureFriday”[Environment]::CurrentDirectory=(Get-Location –PSProvider FileSystem).ProviderPath$a = ([xml](new-object net.webclient).downloadstring(“http://channel9.msdn.com/Shows/Azure-Friday/feed/mp4high”))$a.rss.channel.item | foreach{$url = New-Object System.Uri($_.enclosure.url)$file = $url.Segments[–1]“Downloading: “ + $fileif (!(test-path $file)){(New-Object System.Net.WebClient).DownloadFile($url, $file)}}
This is an article on how to migrate the azure emulator from v2.2 to v2.3
Note that the emulator has changed again by the time you get to v2.5.
Given that the emulator is a poor copy of what really happens in azure I would recommend designing you apps to work locally standalone yet use services in the cloud (with abstracted local versions if required).
Powershell is very useful for quick queries or repeatable scripts.
Scripts can be shared, tested, adapted and reused.
Here are a few key points about powershell:
Simple Functions
I’ll start with a function example.
function Test($a, $b)
{
“$a – $b”
}
This is a function written in the simple form (there are two advanced variations which I won’t go into here).
To call this you should use the following:
Test a b
This is the positional form of parameters.
Alternatively you could use:
Test -a a -b b
This is the named parameter form.
You can of course mix these up.
Test -b b a
You can even use a dictionary object to pass the parameters in:
$var = @{a=1;b=2}
test @var
However you will get odd behavior if you try and use brackets or commas:
Test(1,2)
1 2 –
Test 1,2
1 2 –
This is because brackets and commas create lists.
There is an exception to this when you are calling methods on .net objects.
[DateTime]::UtcNow.AddDays(-1)
Here brackets and commas are required.
Powershell even gives help details about custom functions.
get-help test
NAME
TestSYNTAX
Test [[-a] <Object>] [[-b] <Object>]ALIASES
NoneREMARKS
None
Cmdlets
All of the built in functions (called cmdlets) behave in exactly the same way as custom functions.
They have a very strong naming convention: Verb-Noun
The verb is one of a given list (get-verb gives you the list, currently there are 98)
The noun is by convention singular.
They are intended to be composed in a pipeline.
The rule is anything not bound to a variable or cast to null is passed down the pipeline.
The following is how I determined how many verbs there are:
get-verb | Measure-Object | select count
Comparison operations.
Powershell uses the normal > and < symbols for file redirection (because it is backwards compatible with dos).
This means that you need to use the switch versions of these.
This is where the built in help comes in handy:
get-help about_ | Out-GridView
get-help about_comp -ShowWindow
Aliases
Some commands have short aliases:
get-alias
These typically map back to the dos or unix command that they resemble.
Pipeline
The command prompt in powershell forms a read-evaluate-print-loop.
1..10
1..10 | % {write-host “Hello $_”}
1..10 | sort -Descending | % {write-host “Hello $_”}
Each command in the chain will act as soon as it gets some data.
However greedy operators (such as sort) need the source to finish before passing parameters on.
Useful Cmdlets
where
get-member
out-gridview
import-csv
This is the first in a series of articles that I am going to write about an introduction to powershell.
However to start with I’ll give a useful option for the Powershell Integrated Scripting Environment (ISE – pronounced ICE).
$psISE.Options.FontSize = 20
This allows the editor to be seen in a presentation room.
This is a good example of powershell being embedded in another application.
Now the question is how did I find out about this property?
First I started up the ISE
Then I wanted to find out what variables existed.
That required querying the variables virtual drive:
However I can’t remember the name of this drive.
So the starting point was:
get-psdrive
This returned a list that looks like:
| Name | Provider | Root |
|---|---|---|
| Alias | Microsoft.PowerShell.Core\Alias | |
| C | Microsoft.PowerShell.Core\FileSystem | C:\ |
| Cert | Microsoft.PowerShell.Security\Certificate | \ |
| D | Microsoft.PowerShell.Core\FileSystem | D:\ |
| E | Microsoft.PowerShell.Core\FileSystem | E:\ |
| Env | Microsoft.PowerShell.Core\Environment | |
| F | Microsoft.PowerShell.Core\FileSystem | F:\ |
| Function | Microsoft.PowerShell.Core\Function | |
| HKCU | Microsoft.PowerShell.Core\Registry | HKEY_CURRENT_USER |
| HKLM | Microsoft.PowerShell.Core\Registry | HKEY_LOCAL_MACHINE |
| Variable | Microsoft.PowerShell.Core\Variable | |
| WSMan | Microsoft.WSMan.Management\WSMan |
From this I was able to identify the Variable PSDrive.
I was then able to change directory to the variable drive and then list the contents
cd variable:
dir
This showed the following:
| Name | Value |
|---|---|
| $ | dir |
| ? | True |
| ^ | dir |
| args | System.Object[] |
| ConfirmPreference | High |
| ConsoleFileName | |
| DebugPreference | SilentlyContinue |
| Error | System.Collections.ArrayList |
| ErrorActionPreference | Continue |
| ErrorView | NormalView |
| ExecutionContext | System.Management.Automation.EngineIntrinsics |
| false | False |
| FormatEnumerationLimit | 4 |
| HOME | C:\Users\Chris |
| Host | System.Management.Automation.Internal.Host.InternalHost |
| input | System.Collections.ArrayList+ArrayListEnumeratorSimple |
| MaximumAliasCount | 4096 |
| MaximumDriveCount | 4096 |
| MaximumErrorCount | 256 |
| MaximumFunctionCount | 4096 |
| MaximumHistoryCount | 4096 |
| MaximumVariableCount | 4096 |
| my7digitalKey | 7dvtxrfd7pm5 |
| my7digitalsecret | gek57mdmmqvk85cn |
| MyInvocation | System.Management.Automation.InvocationInfo |
| NestedPromptLevel | 0 |
| null | |
| OutputEncoding | System.Text.SBCSCodePageEncoding |
| PID | 26208 |
| profile | C:\Users\Chris\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile. ps1 |
| ProgressPreference | Continue |
| PSBoundParameters | System.Management.Automation.PSBoundParametersDictionary |
| PSCommandPath | |
| PSCulture | en-GB |
| PSDefaultParameterValues | System.Management.Automation.DefaultParameterDictionary |
| PSEmailServer | |
| PSHOME | C:\Windows\System32\WindowsPowerShell\v1.0 |
| psISE | Microsoft.PowerShell.Host.ISE.ObjectModelRoot |
| PSScriptRoot | |
| PSSessionApplicationName | wsman |
| PSSessionConfigurationName | http://schemas.microsoft.com/powershell/Microsoft.PowerS hell |
| PSSessionOption | System.Management.Automation.Remoting.PSSessionOption |
| PSUICulture | en-US |
| psUnsupportedConsoleApplications | Microsoft.PowerShell.Host.ISE.UICollection`1[Syste m.String] |
| PSVersionTable | System.Management.Automation.PSVersionHashTable |
| PWD | Variable:\ |
| ShellId | Microsoft.PowerShell |
| StackTrace | at System.Management.Automation.Internal.PipelineProcessor.Synchronou sExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate) at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, Co mmandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] c ommandRedirections, FunctionContext funcContext) at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) |
| true | True |
| VerbosePreference | SilentlyContinue |
| WarningPreference | Continue |
| WhatIfPreference | False |
From this the psISE looks to be the thing that I am looking for.
The next step is to inspect the object to see what I can find to use.
$psISE | gm
| Name | MemberType | Definition |
|---|---|---|
| Equals | Method | bool Equals(System.Object obj) |
| GetHashCode | Method | int GetHashCode() |
| GetType | Method | type GetType() |
| ToString | Method | string ToString() |
| CurrentFile | Property | Microsoft.PowerShell.Host.ISE.ISEFile CurrentFile {get ;} |
| CurrentPowerShellTab | Property | Microsoft.PowerShell.Host.ISE.PowerShellTab C urrentPowerShellTab {get;} |
| CurrentVisibleHorizontalTool | Property | Microsoft.PowerShell.Host.ISE.ISEAddO nTool CurrentVisibleHorizontalTool {get;} |
| CurrentVisibleVerticalTool | Property | Microsoft.PowerShell.Host.ISE.ISEAddOnT ool CurrentVisibleVerticalTool {get;} |
| Options | Property | Microsoft.PowerShell.Host.ISE.ISEOptions Options {get;} |
| PowerShellTabs | Property | Microsoft.PowerShell.Host.ISE.PowerShellTabCollecti on PowerShellTabs {get;} |
Options look promising.
$psISE.Options | gm
| Name | MemberType | Definition |
|---|---|---|
| PropertyChanged | Event | System.ComponentModel.PropertyChangedEventHandler PropertyChanged(System.Object, System.ComponentModel.PropertyChangedEventArgs) |
| Equals | Method | bool Equals(System.Object obj) |
| GetHashCode | Method | int GetHashCode() |
| GetType | Method | type GetType() |
| RestoreDefaultConsoleTokenColors | Method | void RestoreDefaultConsoleTokenColors() |
| RestoreDefaults | Method | void RestoreDefaults() |
| RestoreDefaultTokenColors | Method | void RestoreDefaultTokenColors() |
| RestoreDefaultXmlTokenColors | Method | void RestoreDefaultXmlTokenColors() |
| ToString | Method | string ToString() |
| AutoSaveMinuteInterval | Property | int16 AutoSaveMinuteInterval {get;set;} |
| ConsolePaneBackgroundColor | Property | System.Windows.Media.Color ConsolePaneBackgroundColor {get;set;} |
| ConsolePaneForegroundColor | Property | System.Windows.Media.Color ConsolePaneForegroundColor {get;set;} |
| ConsolePaneTextBackgroundColor | Property | System.Windows.Media.Color ConsolePaneTextBackgroundColor {get;set;} |
| ConsoleTokenColors | Property | System.Collections.Generic.IDictionary[System.Management.Automation.PSTokenType,System.Windows.Media.Color] ConsoleTokenColors {get;} |
| DebugBackgroundColor | Property | System.Windows.Media.Color DebugBackgroundColor {get;set;} |
| DebugForegroundColor | Property | System.Windows.Media.Color DebugForegroundColor {get;set;} |
| DefaultOptions | Property | Microsoft.PowerShell.Host.ISE.ISEOptions DefaultOptions {get;} |
| ErrorBackgroundColor | Property | System.Windows.Media.Color ErrorBackgroundColor {get;set;} |
| ErrorForegroundColor | Property | System.Windows.Media.Color ErrorForegroundColor {get;set;} |
| FontName | Property | string FontName {get;set;} |
| FontSize | Property | int FontSize {get;set;} |
| IntellisenseTimeoutInSeconds | Property | int IntellisenseTimeoutInSeconds {get;set;} |
| MruCount | Property | int MruCount {get;set;} |
| ScriptPaneBackgroundColor | Property | System.Windows.Media.Color ScriptPaneBackgroundColor {get;set;} |
| ScriptPaneForegroundColor | Property | System.Windows.Media.Color ScriptPaneForegroundColor {get;set;} |
| SelectedScriptPaneState | Property | Microsoft.PowerShell.Host.ISE.SelectedScriptPaneState SelectedScriptPaneState {get;set;} |
| ShowDefaultSnippets | Property | bool ShowDefaultSnippets {get;set;} |
| ShowIntellisenseInConsolePane | Property | bool ShowIntellisenseInConsolePane {get;set;} |
| ShowIntellisenseInScriptPane | Property | bool ShowIntellisenseInScriptPane {get;set;} |
| ShowLineNumbers | Property | bool ShowLineNumbers {get;set;} |
| ShowOutlining | Property | bool ShowOutlining {get;set;} |
| ShowToolBar | Property | bool ShowToolBar {get;set;} |
| ShowWarningBeforeSavingOnRun | Property | bool ShowWarningBeforeSavingOnRun {get;set;} |
| ShowWarningForDuplicateFiles | Property | bool ShowWarningForDuplicateFiles {get;set;} |
| TokenColors | Property | System.Collections.Generic.IDictionary[System.Management.Automation.PSTokenType,System.Windows.Media.Color] TokenColors {get;} |
| UseEnterToSelectInConsolePaneIntellisense | Property | bool UseEnterToSelectInConsolePaneIntellisense {get;set;} |
| UseEnterToSelectInScriptPaneIntellisense | Property | bool UseEnterToSelectInScriptPaneIntellisense {get;set;} |
| UseLocalHelp | Property | bool UseLocalHelp {get;set;} |
| VerboseBackgroundColor | Property | System.Windows.Media.Color VerboseBackgroundColor {get;set;} |
| VerboseForegroundColor | Property | System.Windows.Media.Color VerboseForegroundColor {get;set;} |
| WarningBackgroundColor | Property | System.Windows.Media.Color WarningBackgroundColor {get;set;} |
| WarningForegroundColor | Property | System.Windows.Media.Color WarningForegroundColor {get;set;} |
| XmlTokenColors | Property | System.Collections.Generic.IDictionary[Microsoft.PowerShell.Host.ISE.PSXmlTokenType,System.Windows.Media.Color] XmlTokenColors {get;} |
| Zoom | Property | double Zoom {get;set;} |
And here we find fontsize
This gives the command that I demonstrated at the start.
The following commands were used in the construction of this article:
get-psdrive | select Name,Provider,Root | ConvertTo-Html -Fragment
dir | select Name,Value | ConvertTo-Html -Fragment
$psISE.Options | gm | select Name, MemberType, Definition | convertto-html -Fragment | clip
At last we have the December Update and it is now the 16th January.
| Family
|
Version
|
Is Default
|
|---|---|---|
| 3 | WA-GUEST-OS-3.20_201410-01 | False |
| 3 | WA-GUEST-OS-3.21_201411-01 | False |
| 3 | WA-GUEST-OS-3.22_201412-01 | True |
| 4 | WA-GUEST-OS-4.13_201410-01 | False |
| 4 | WA-GUEST-OS-4.14_201411-01 | False |
| 4 | WA-GUEST-OS-4.15_201412-01 | True |
Please can we have a little more frequency in updates.
This http://msdn.microsoft.com/en-us/library/azure/ee924680.aspx gives some updates.
I have finally convinced my mother to buy a new laptop to replace her ageing XP system.
You would think that the setup of a modern laptop should be so simple that the supplied instructions should be enough. This needs some serious work as it is currently not useful.
Partway through the setup it asked my mother to sign in with a windows live account (which of course she does not have). Then she was prompted to create an account with a maximum password length of 16 characters (I was recommending the modern style three words plus punctuation but this was not going to work).
Eventually she got the machine up and I helped her to install “start is back” to make the machine usable (I can’t explain the metro interface over the phone).
The next step was to install office 365. This again required the creation of a windows live account (why the product has a licence key number that should be all that is required).
The windows live account is asking for a lot of personal details that are frankly none of the business of the installation process. As long as the user has a valid email address is all that is required – why do they need to know DOB and gender. It would even be possible to make sensible guesses as to language and country from the browser data used.
Partway through the process it asked you to check your email – which my mum did on her android tablet (not having set up the email on the new laptop yet). There was no way to get the user interface on the laptop to accept that the newly created username was valid. It required a full restart of the registration process (including re-entry of the 16 digit code) and this time to sign in with the now validated windows live account.
My mother now has a new laptop with office installed, but there is no way that she could have got this working without help. Microsoft need to invest in usability studies for various age groups. This is after firing whichever team thinks that the metro UI is in any way usable.
This is how to get a list of wmi providers:
Get-WmiObject -Namespace “root/cimv2” -List
These can be queried as follows:
Get-WmiObject -query “select * from win32_processor”
This is effectively granting you sql style queries against features on your machine.
I am still using my old blog on http://devrants.blog.com/
The performance of that had recovered so this is still a placeholder.
As of the end of 2014 we have:
| Family | IsDefault | Version |
|---|---|---|
| 3 | False | WA-GUEST-OS-3.17_201407-01 |
| 3 | False | WA-GUEST-OS-3.20_201410-01 |
| 3 | True | WA-GUEST-OS-3.21_201411-01 |
| 4 | False | WA-GUEST-OS-4.10_201407-01 |
| 4 | False | WA-GUEST-OS-4.13_201410-01 |
| 4 | True | WA-GUEST-OS-4.14_201411-01 |
According to the documentation site (http://msdn.microsoft.com/en-us/library/azure/ee924680.aspx) the latest versions are due to expire on the 11th of January with the new versions being enabled on the 5th January. I guess that means a lot of people will have to spend their first week back at work testing the new os release in the 5 working days before the existing guest oses are retired.