PowerShell: calling CMD things

PSCmd01

PS E:\sandbox\PowerShell> $currDir = "E:\sandbox\PowerShell"
PS E:\sandbox\PowerShell> $command = "dir $($currDir)\*.txt > x.log; type x.log"
PS E:\sandbox\PowerShell> $command
dir E:\sandbox\PowerShell\*.txt > x.log; type x.log
PS E:\sandbox\PowerShell> Invoke-Expression -Command:$command

 

 

Advertisements

PowerShell: pattern matching

Here, I am defining a hex character, as 1 of A-F (case insensitive) or 1 of 0-9. The format is no different from any other common Regex/pattern matching implementation:

Then, we want to look for the pattern anywhere within the passed line (\b..\b – word boundary). Still in that $guidPattern string, we are saying that the pattern starts with exactly 8 of the hex characters we defined earlier, followed by a literal ‘-‘, etc… ending up with exactly 12 characters, then a word boundary.

And finally the whole thing in a PowerShell script:


<#
Given a set of files, for each file, if a line does not contain the pattern, then
write the line to name-copy-plus-suffix of the file, else do not write the line.
#>
$root = "C:\Sandbox"
cd $root
$fileSet = Get-ChildItem -Path .\*.xml -Name
$fileSet

$hexChar = "[A-Fa-f0-9]"

$guidPattern = "\b$hexChar{8}-$hexChar{4}-$hexChar{4}-$hexChar{4}-$hexChar{12}\b"

$fileSet | foreach {
$fileName = "$root\$_"
$fileToSave = "$fileName" + ".sansGuid"
Write-Host "Processing $fileName"
$reader = New-Object -TypeName System.IO.StreamReader("$fileName")
$writer = [System.IO.StreamWriter] $fileToSave
$writer.Write("");

while (($line = $reader.ReadLine()) -ne $null) {
if ($line -notMatch $guidPattern) {
$writer.WriteLine($line)
}
}
$writer.Close()
$reader.Close();
}

AngularJS: ng-class

Image

ng-class01
In the picture, we see that the Fantasy font is ON (html default) for list item 2, and off for list items 1 and 3, as [true] makes it use the stuffit css selector in these cases.

(Later: turns out that given differences between Chrome and IE, Impact font is a good synonym for Fantasy that seems to render the same in both)

Azure PowerShell: things have changed

… but of course you don’t get told in anything in-your-face. To wit, this command…

AzureCli19.PNG

… used to return stuff.. and now returns the blank line you see. Turns out this is because Get-AzureVM now refers to the “Classic” variants in the Azure Portal. If you created through the (implicitly recommended) Resource Manager in the Azure Portal, then you now have to use this command:

AzureCli20.PNG

, where the [Rm] part stands for [Resource Manager] . This is a reasonable link.

So that took a while to get there. Next: I have 2 subscriptions. Although I could use this to enumerate my subscriptions, with [123] being my default subscription:

AzureCli21.PNG

, it a LONG time to work out that a) you can only work in one subscription context at a time, and that resources not in the default subscription will not be listed until you do this:

AzureCli22.PNG

With that context set, it will now happily list e.g. the VMs I created on my non-default subscription:

AzureCli20.PNG

And a general MSDN link around those Azure RM cmdlets:

https://msdn.microsoft.com/en-us/library/mt619263.aspx

https://msdn.microsoft.com/en-us/library/mt603718.aspx

And just throwing in some of the keywords/cmdlets I used on the way:

  1. Import-Module -Name PowerShellGet 
  2. Install-Module AzureRM
  3. Install-Module Azure -AllowClobber
  4. Import-Module AzureRM
  5. Get-AzureAccount
  6. Get-AzureVM
  7. Get-AzureRmVM
  8.  Login-AzureRmAccount
  9. Add-AzureRmAccount
  10. Get-AzureRmSubscription

 

By the way, June 22 2016 (that is, just 2 weeks ago) seems a date when a lot changed in PowerShell for Azure. And even the updated docs still talk about “this is early documentation, subject to change, etc…”

Hm, and now I’ve just spotted the “true” CLI ( as opposed to PowerShell):

https://azure.microsoft.com/en-gb/documentation/articles/xplat-cli-install/

Another time. Night.

 

 

Azure: disks

As my MSDN Azure subscription was threatening to have exhausted its credit before the end of the month, I decided to see if it was easy to resize the VM, or at least the Blobs making up the disk storage. Those disks are SSDs, 1TB. Azure charges for this by disk size (so called Premium Data Storage), and not by the actual data used. It is not possible to EASILY resize those disks, so I decided cut my losses and create a 128GB SSD as my data disk, which should easily be enough for my needs.

As so often, everything else in the post is a set of screenshots:

Node: Install

You might also want to see the earlier post here.

I went to a new Windows Server, and dumbly starting typing in Node, and npm, and nothing…

NodeInstall00

Go here.

NodeInstall02.PNG

Grab whichever version suits you…

NodeInstall03.PNG

NodeInstall04.PNG

NodeInstall05.PNG

NodeInstall06.PNG

NodeInstall07.PNG

Better…

NodeInstall08.PNG

And now for the web server. Again credit to this person here

npm install express

NodeInstall09.PNG