PowerShell for Windows Admins


October 29, 2015  12:31 PM

Win free entry to the PowerShell Summit

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Want to go to the PowerShell Summit? Want to go for free?

You can win free entry to the Summit (need to pay your own travel & hotel) through the competition at http://powershell.org/wp/2015/10/28/win-a-free-4-day-pass-to-powershell-and-devops-summit-2016/

October 26, 2015  9:07 AM

-in operator

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

As an alternative to the –contains operator you can use the –in operator

Repeating the tests from the previous post on –contains

PS> $primes = 1,3,5,7,11,13,17,19,23,29,31,37,41,43,47
PS> $candidate = 7
PS> $candidate -in $primes
True
PS> $candidate = 4
PS> $candidate -in $primes
False

The –in operator can be used in the simplified where syntax but –contains can’t


October 26, 2015  8:57 AM

-contains operator

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Sometimes you may want to test if a value is in a collection of values

For instance

$primes = 1,3,5,7,11,13,17,19,23,29,31,37,41,43,47

if you want to test if 7 is a member of the collection

$candidate = 7
$primes -contains $candidate
True

Likewise testing 4

$candidate = 4
$primes -contains $candidate
False


October 26, 2015  8:44 AM

DSC resource kit update–October 2015

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

The DSC resource kit is the primary place to look for DSC resources beyond those baked into Windows.

An update to the resources in the kit has been announced. Some new resources and lots of bug fixes.

see http://blogs.msdn.com/b/powershell/archive/2015/10/23/dsc-resource-kit-updates-are-here.aspx

for details


October 24, 2015  7:48 AM

Testing connectivity before Invoke-Command

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

A question on the forum asked about testing if a remote machine could be reached before using Invoke-Command against it.

The usual way to test if you can reach a remote machine is to ping it

PS> Test-Connection -ComputerName $env:COMPUTERNAME -Quiet
True

That shows you can reach the machine but it doesn’t mean that you can use Invoke-Command to send a request.

I think a better test is to use Test-WSMan

It will test if the WinRm service is running (won’t test if remoting is enabled)

$computers = “$env:COMPUTERNAME”, ‘NotFound’

foreach ($computer in $computers){
$target = $computer
if (Test-WSMan -ComputerName $computer -ErrorAction Ignore) {
Invoke-Command -ComputerName $computer -ScriptBlock {Get-Service}
}
else {
Write-Warning -Message “Couldn’t connect to $computer”
}

}

You can push the output to file or put the unreachable machine names into a file if you need to record them.


October 23, 2015  10:08 AM

UK PowerShell User Group

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

Two meetings of the UK PowerShell group have been announced

Tuesday 24 November in Manchester

Thursday 26 November at Rackspace, in Hayes Middlesex

Details from  www.get-psuguk.eventbrite.co.uk

There is a rumour that I might be speaking at the 26 November event


October 20, 2015  1:49 PM

PowerShell and SSH

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell, SSH

The PowerShell team have announced the availability of OpenSSH 7.1 for Windows – http://blogs.msdn.com/b/powershell/archive/2015/10/19/openssh-for-windows-update.aspx

This is their first step in bringing SSH support into PowerShell.

The roadmap for next steps is available on their blog at the link above


October 19, 2015  5:00 AM

PowerShell resources–you tube

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell

One place you might not think of looking for PowerShell resources is you tube.  PowerShell.org has its own channel on you tube – https://www.youtube.com/user/powershellorg – where we’ve posted the session recordings from:

PowerShell Summit Europe 2015

PowerShell summit Europe 2014

PowerShell Summit NA 2015

selected sessions from

PowerShell Summit NA 2014 and

PowerShell Summit NA 2013

are also available.

In addition we have a number other recordings available.

Enjoy


October 17, 2015  4:00 AM

WMI linked classes

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

You will find that many WMI classes have links – some are associations built in to WMI (a subject for another time) while other classes can be linked based on property values. An example of the latter is the Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration classes. The DeviceId on Win32_NetworkAdapter  matches Index on Win32_NetworkAdapterConfiguration.

The following function (adapted from a question on the forum) shows one way this link can be used

function Get-NetworkInfo{
[cmdletbinding()]
param( [string]$ComputerName )

$networkinfo = @()

$networks = Get-WmiObject Win32_Networkadapter -Filter ‘NetEnabled=True’ -ComputerName $ComputerName

$adapter = 0
foreach($network in $networks){

$id = $network.DeviceId

$IPinfo = Get-WmiObject win32_networkadapterconfiguration -Filter “Index = $id” -ComputerName $ComputerName
$winServers = 0
$winServers = ($IPinfo.WinsPrimaryServer -join ‘,’),($IPinfo.WinsSecondaryServer -join ‘,’)

$adapter += 1

$props = @{
‘Adapter’ = $adapter;
‘Manufacturer’ = $network.Manufacturer;
‘Description’ = $network.Description;
‘Connection’ = $network.NetConnectionID;
‘SpeedGB’ = [math]::Round($network.Speed / 1GB, 2)
‘IPAddress’ = $IPinfo.IPAddress -join ‘,’
‘Submask’ = $IPinfo.IPSubnet -join ‘,’
‘Gateway’ = $IPinfo.DefaultIPGateway -join ‘,’
‘DNSServers’ = $IPinfo.DnsServerSearchOrder-join ‘,’
‘WinServers’ = $winServers -join ‘,’
‘DomainSuffixes’ = $IPinfo.DNSDomainSuffixSearchOrder -join ‘,’
}

$networkinfo += New-Object -TypeName psobject -Property $props
}
$networkinfo
}
Get-NetworkInfo -ComputerName $env:COMPUTERNAME


October 16, 2015  5:40 AM

Manning Deal of The Day – 17 October 2015

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Books, Powershell

A treat for PowerShell users looking for books. 50% off PowerShell in Depth, second edition and PowerShell in Action, third edition on 17 October 2015

Half off Windows PowerShell in Action, Third Edition. Use code dotd101715au at https://www.manning.com/books/windows-powershell-in-action-
third-edition

Half off Powershell in Depth, Second Edition. Use code dotd101715au at https://www.manning.com/books/powershell-in-depth-second-edition

I’m co-author of both books and while I may be a touch biased about it I think this is n excellent opportunity to get 2 great PowerShell books


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: