Monthly Archive

PowerShell

PowerShell Summit NA 2015 speakers

Want to learn a bit more about some of the speakers at the PowerShell Summit?  Head over to the Scripting Guy blog - http://blogs.technet.com/b/heyscriptingguy/ – to see a series of posts giving you some background, and pictures, of a number of speakers.

PowerShell Europe 2015 Agenda

As has been announced registration for the PowerShell Summit Europe 2015 opens on 27 February 2015. http://powershell.org/wp/2015/02/20/powershell-summit-europe-registration/

 

Other details on the Summit can be found here:  http://powershell.org/wp/community-events/summit/powershell-summit-europe-2015/

 

The agenda for the Summit can be found on the event site for the Summit http://eventmgr.azurewebsites.net/event/home/PSEU15

Shutting down machines in parallel

My test lab is a set of virtual machines running on a Lenovo w1510 laptop. When I’ve finished working for the day I want to shut down the virtual machines and the laptop. I may have anywhere between 2 and 8 (or more) VMs running so scripting the shutdown helps a lot.

 

Machines can be shutdown independently so this is an action that is ideal for parallel execution through a workflow.

 

workflow stop-allvms {
$vms = Get-VM | where State -eq "Running" 
foreach -parallel ($vm in $vms) {
Stop-Computer -PSComputerName $vm.Name -Force -Verbose
}
}

stop-allvms

 

Get the running VMs. use foreach –parallel to run stop-computer against each VM. Notice I’ve had to change the parameter on Stop-Computer from –ComputerName to –PSComputerName

 

Another little workflow that makes life easier. I looks like workflows aren’t going to be the game changer that we originally thought but they do add some interesting options.

Starting VMs based on WSUS state

I use WSUS in my lab to update machines – means I only have to download updates once. The issue is that I have to start the VMs so they can communicate with the WSUS server. WSUS will start to flag warnings if machines haven’t contacted the WSUS server for more than that length of time.

 

Putting that together I can use the UpdateServices (WSUS) module and the Hyper-V module to start machines that have been turn off more than 7 days.

 

$date = (Get-Date).AddDays(-7)
Get-WsusComputer -NameIncludes 'W12R2' |
where LastReportedStatusTime -lt $date |
foreach {
  $psitem.FullDomainName
  $name = ($psitem.FullDomainName -split "\.")[0]

  $vm = Get-VM -Name $name -ComputerName server02
 
  if ($vm.State -eq 'Off') {

    Start-VM -Name $name -ComputerName server02
 
    Start-Sleep -Seconds 30
  }
}

 

Set a date 7 days in the past.

 

Use get-WsusComputer to pull the machine names. I filter on W12R2 (all my machine names contain an abbreviated OS type) and check the last status report time.

 

Any machines that haven’t reported – the VM data is retrieved and if the machine isn’t running it’s started. Machines take about 25-30 seconds to boot on my lab so a sleep of 30 seconds means I’m not starting them all at once.

Stages of panic

You’re working on a new script and something’s not working properly and you can’t figure it out.

 

Panic level 1 is when you start using Get-Command and Get-member on everything in sight trying to figure out what’s wrong with the objects

 

Panic level 2 is when you realise you have to dig through the PowerShell help files. You have used Update-Help recently haven’t you.

 

Panic level 3 is when you start pulling your PowerShell books off the shelf and scanning the indexes. You have copies of PowerShell in Depth and PowerShell in Action handy don’t you.

 

Panic level 4 is when you’re resorting to forum searches in the hope someone else has had this problem.

 

Panic level 5 sets in when the only thing you can find on the Internet is a blog post you wrote 3 years ago which vaguely touches on your problem.

 

Now you’ve got to start again analysing the code from the top.

 

Congratulations – if you’ve reached this stage you’re a PowerShell expert!

Scripting Guy CDXML series

Today starts a four part series I’ve written for the Scripting Guy blog on using CDXML to create a module to work with the registry.  Don’t know what CDXML is – you will when you’ve read the series

 

The first post is at http://blogs.technet.com/b/heyscriptingguy/archive/2015/02/02/registry-cmdlets-manage-the-registry.aspx

PowerShell Summit NA 2015 Agenda changes

We’ve had to make some minor changes to the Summit agenda – the revised schedule is shown on the event web site - http://eventmgr.azurewebsites.net/event/home/PSNA15

PowerShell Heroes 2015

Powershell.org has announced the 2015 list of PowerShell Heroes- http://powershell.org/wp/2015/01/17/announcing-our-2015-powershell-heroes/

 

These are people who have made an outstanding contribution to the PowerShell community but have not been recognised in other ways (such as an MVP award)

 

Please join me in congratulating them

DHCP scope lease time

I wanted to reduce the lease time on a DHCP scope

 

$lt = New-TimeSpan -Hours 12
Set-DhcpServerv4Scope -ScopeId 10.10.54.0 -LeaseDuration $lt

 

You could even make it a one liner if you wished

 

Set-DhcpServerv4Scope -ScopeId 10.10.54.0 –LeaseDuration (New-TimeSpan -Hours 12)

PowerShell Summit Europe 2015–topic submissions

Topic submissions for the PowerShell Summit Europe are still open. If you want to be considered as a speaker please submit your topic very soon.

 

At the moment there aren’t enough submissions to enable us to put on a quality event. The 2014 European Summit was an excellent event with many good sessions – now is the time to submit your sessions. We need your sessions.

 

We have a policy of accepting sessions from new speakers as well as established experts. It’s not who you are but the quality of the session that counts.

 

Details on how to submit session proposals are available here

http://powershell.org/wp/2014/11/24/call-for-presentations-for-powershell-summit-europe-2015/

 

Please submit your proposals soon as we can’t run the European PowerShell Summit without them