Monthly Archive

Categories

PowerShell

Wanted

Wanted one nice kind PowerShell community member to buy the last lonely ticket for the 2017 PowerShell and DevOps Summit.

 

That’s right we have one place left. And its definitely the last. if you want it – better hurry.

PowerShell Summit 2017 – – more seats available

After selling out in record time we’ve managed to squeeze a few more seats in after discussion with the conference centre.

 

Those seats are live now.

 

They are very definitely, the absolute last set of seats we’ll be able to add this year.

 

First come – First served. When they’re gone – they’re gone

PowerShell Summit 2017–sold out

We sold the last seat for the 2017 Summit - https://eventloom.com/event/home/summit2017 yesterday.

 

If, and its a very big if, more seats become available we'll notify you though the event web site and on powershell.org

PowerShell on Linux installs

PowerShell on Linux installs are now easier as you can use the Linux package management tools to download and update PowerShell Core 6.0

 

Details from https://blogs.msdn.microsoft.com/powershell/2017/02/01/installing-latest-powershell-core-6-0-release-on-linux-just-got-easier/

Powershell versions

An explanation of PowerShell versions is available here - http://itknowledgeexchange.techtarget.com/powershell/powershell-versions-2/

Finding DNS static records

An interesting question from the forums about finding DNS static records

 

You can view the records in a DNS zone

Get-CimInstance -Namespace root\MicrosoftDNS -ClassName MicrosoftDNs_Atype -ComputerName W16DC01  -Filter "DomainName = 'manticore.org'" |
select OwnerName, Timestamp, IPAddress

 

but how do you know which are static records.

 

There isn’t an obvious way to do it but if you dig into the records (hint create a static record and look at the differences) you’ll see that static records have a timestamp of 0

 

So to see just the static records

Get-CimInstance -Namespace root\MicrosoftDNS -ClassName MicrosoftDNs_Atype -ComputerName W16DC01 -Filter "DomainName = 'manticore.org' AND Timestamp = 0" |
select OwnerName, Timestamp, IPAddress

 

Rather than using the CIM class directly it’s simpler to use the cmdlets from the DNSserver module – install the remote admin tools to get access.

 

To view the A type records

Get-DnsServerResourceRecord -ComputerName W16DC01 -ZoneName 'manticore.org' -RRType A

 

To view the static records only

Get-DnsServerResourceRecord -ComputerName W16DC01 -ZoneName 'manticore.org' -RRType A |
where {-not $_.TimeStamp}

 

Notice that you’re checking for the absence of a timestamp

Summit 2017–seats going fast

Seats at eh PowerShell Summit -  https://eventloom.com/event/home/summit2017 – are going fast.

 

We’ve sold over 70% of the seats – they’re current 55 seats left split between 4-day and 3-day passes. The 3-day passes don’t go on sale until 12 February and we’ll be moving 3-day to 4-day as sales happen between now and then. We have a number of sales in the pipeline that will reduce the number of available seats as well.

 

We are at maximum capacity for the venue – and probably for the event in its present format.

 

We are expecting a rapid sell off of the remaining seats when open registration of 3-day passes. We don’t maintain any sort of waiting list and when the seats are gone – they’re gone.

 

If you are thinking of attending the 2017 Summit I’d advise you to get your seat booked quickly – I wouldn’t be at all surprised if we’d sold out by the end of February.

Community Lightning Demos

We are continually evolving the content we present at the PowerShell Summit. This year we're bringing back something that was a feature of the early PowerShell Deep Dives and Summits - the Community Lightning Demos. We have a session set aside on Wednesday afternoon for this. Timescales will depend on the number of people wanting to show something.

In the words of PowerShell MVP Warren Frame who's organising this for us:

Ever wanted to present at Summit but were unsure if you could? This is your opportunity to present something you've discovered to your peers in the PowerShell community. A code trick, or tip, a new module you've created, an open source module or a feature of a cmdlet that's relatively unknown.. The list goes on and on. Anything PowerShell, or DevOps related that you think is cool and that will interest other people is a suitable topic. We're looking for 5-10 minute demos. Something you've done, discovered, solved or run up against. This is your opportunity to "give back" to our community by sharing your knowledge. Make sure its something you can present from your laptop and that you don't need extensive Internet access. A sign up sheet will be available Sunday, Monday and Tuesday. We just need your name and topic. Who knows you may be asked to present a full session at the following Summit. Some of our best speakers started in the Lightning Demos sessions of past events.

This is your opportunity to start presenting to a knowledgeable and appreciative audience. In past events we've had some amazing things come to light - things the PowerShell team didn't realise about PowerShell. If you have something to share please consider signing up for this.

WMF 5.1 now available

The download for WMF 5.1 for down level operating systems is now available:

https://blogs.msdn.microsoft.com/powershell/2017/01/19/windows-management-framework-wmf-5-1-released/

WMF 5.1 can be installed on Windows 7 and 8.1 plus Windows Server 2008 R2, 2012, 2012 R2

Windows 10 and Server 2016 already have PowerShell 5.1 and don’t need this install.

if installing on Windows 7 or Server 2008 R2 the installation process has changed – READ THE RELEASE NOTES OR BE PREPARED FOR A LOT OF EXTRA EFFORT

Using $_

The $_ symbol seems to be causing confusion from some recent forum questions I’ve seen.

 

$_ represents the current object on the pipeline – if you want to know why $_ was chosen you’ll have to read PowerShell in Action!

 

You can use $_ in a number of situations – in commands that perform an action on every object (or selected objects) on the pipeline. Here’s some of the commoner usages:

 

In the early versions of PowerShell you used it in the filter script of Where-Object

Get-Process | Where-Object -FilterScript {$_.CPU -gt 50}

 

This is more usually written as

Get-Process | Where {$_.CPU -gt 50}

 

As of PowerShell v3 if you are filtering on ONE property you can simplify the syntax

Get-Process | Where CPU -gt 50

 

which is a truncated version of

Get-Process | Where -Property CPU -gt -Value 50

 

When you write it like this its obvious what is happening. Get in the habit of thinking of the syntax in this manner even if you write in the shortened form

If you need to filter on TWO or more properties you have to use the old style syntax

Get-Process | Where {$_.CPU -gt 50 -AND $_.Handles -gt 1000}

 

In all of these cases you’re comparing a property of the current pipeline object against a value. If the comparison is true the object is passed onto the next step of the pipeline. If its false the object is discarded.

 

You can use $psitem in place of $_ if you prefer

Get-Process | Where {$psitem.CPU -gt 50}

 

In the Foreach-Object cmdlet you can use $_ to refer to the current object

Get-CimInstance -ClassName Win32_NetworkAdapter -Filter "NetEnabled = $true" |
ForEach-Object {
$ip = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter "Index = $($_.DeviceId)"
$props = @{
Name = $_.NetConnectionId
Product = $_.ProductName
DHCP = $ip.DHCPEnabled
IP   = $ip.IPAddress
}
New-Object -TypeName PSObject -Property $props
}

$psitem also works in this situation

 

The third common usage of $_ is in select-object in calculated fields (you can do the same in Format-Table)

Get-CimInstance -ClassName Win32_LOgicalDisk -Filter "DriveType=3" |
select DeviceId, VolumeName,
@{N='Size(GB)'; E={[math]::Round($_.Size / 1GB, 2)}},
@{N='Used(GB)'; E={[math]::Round(($_.Size - $_.FreeSpace) / 1GB, 2)}},
@{N='Free(%)'; E={[math]::Round(($_.FreeSpace / $_.Size) * 100, 2 )}}

 

In this example we’re changing the size to GB from bytes and calculating the used space and the % free space. Again you could use $psitem instead of $_

ONE PLACE YOU CAN’T USE $_  IS IN A FOREACH LOOP

This fails

$nics = Get-CimInstance -ClassName Win32_NetworkAdapter -Filter "NetEnabled = $true"
$data = foreach ($nic in $nics) {
$ip = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter "Index = $($_.DeviceId)"
$props = @{
Name = $_.NetConnectionId
Product = $_.ProductName
DHCP = $ip.DHCPEnabled
IP   = $ip.IPAddress
}
New-Object -TypeName PSObject -Property $props
}
$data |Format-List

 

To recap $_ (or $psitem) is used to represent the current object on the pipeline. You can us it in commands that are performing an action on every object on the pipeline.