PowerShell for Windows Admins


June 28, 2013  11:39 AM

Refreshing values



Posted by: Richard Siddaway
PowerShell 3, WMI

The CIM cmdlets in PowerShell v3 enable you to refresh the data in the object. Try this:

$p = Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Processor
$p | Get-CimInstance | select percentprocessortime

$p will remain unchanged. Another use for this is monitoring processes – you could check on CPU utilisation

June 27, 2013  3:50 PM

PowerShell presentations



Posted by: Richard Siddaway
PowerShell

Jeffrey Snover and Jason Helmick will be presenting by webcast 18 July 9am – 5pm (PDT) on “Getting started with PowerShell”

Details from http://powershell.org/wp/2013/06/27/a-special-presentation-on-getting-started-with-powershell/

A follow up day of presentations will occur in August delving further into scripting, automation and building tools


June 27, 2013  3:44 PM

Writable properties for a WMI class



Posted by: Richard Siddaway
PowerShell 3, WMI

Do you know how to discover which properties on a WMI class, and therefore a WMI instance, can be modified?

Get-CimClass from the PowerShell 3.0 CIM cmdlets is the answer:

$class = Get-CimClass -ClassName win32_volume
$class.CimClassProperties

The last command returns all of the properties in this format

Name : Description
Value :
CimType : String
Flags : Property, ReadOnly, NullValue
Qualifiers : {read}
ReferenceClassName :

Name : DriveLetter
Value :
CimType : String
Flags : Property, NullValue
Qualifiers : {read, write}
ReferenceClassName :

Notice the first one has a Flag of ReadOnly and the second one has a Qualifier of write. So the question becomes how can you filter on those two items?

If you run something like this:

$class = Get-CimClass -ClassName Win32_Volume
$class.CimClassProperties |
foreach {
if ($psitem | select -ExpandProperty Qualifiers | where Name -eq ‘write’){$psitem}
if (($psitem.Flags -split ‘, ‘) -notcontains ‘Readonly’) {$psitem}
}

You will see that some properties may not be Readonly but also aren’t writable such as:

Name : NumberOfBlocks
Value :
CimType : UInt64
Flags : Property, NullValue
Qualifiers : {MappingStrings}
ReferenceClassName :

In that case we need just the writable properties

Get-CimClass -ClassName Win32_Volume |
select -ExpandProperty CimClassProperties |
foreach {
if ($psitem | select -ExpandProperty Qualifiers | where Name -eq ‘write’){$psitem}
}

This brings the results down to three properties DriveLetter, IndexingEnabled, Label

The first and last I expected – IndexEnabled was new to me


June 27, 2013  1:58 PM

Automation tools?



Posted by: Richard Siddaway
PowerShell

In this post http://richardspowershellblog.wordpress.com/2013/06/23/opinionautomate-or-suffer/ I talked about the need for admins to learn to automate. A couple of comments brought up the need for tools to create our automation scripts.

I remember the 4th generation languages of the late 1980s & 1990s. The promised that you wouldn’t have to code – just drag & drop onto the designer, answer a few questions and your application was created.

The worked great – as long as you wanted a cookie cutter application that only had limited functionality and was dog slow.

Automating code generation, in my experience, is a hard task. Compare the PowerShell snippets that come out of AD Admin center or the Exchange Management Console with what you actually write. They are usually very verbose and include lots of stuff you don’t need.

If someone can create a tool that creates my code for me, with minimal input on my side then I’ll sign up for it. I suspect it’ll be a long time coming. Until then happy coding.


June 27, 2013  1:46 PM

Windows Management Framework 4.0



Posted by: Richard Siddaway
PowerShell v4

The PowerShell 4.0 preview is now available. It comes as part of WMF 4.0

Windows Management Framework 4.0 Preview includes updates to Windows PowerShell, Windows PowerShell ISE, Windows PowerShell Web Services (Management OData IIS Extension), Windows Remote Management (WinRM), Windows Management Infrastructure (WMI), the Server Manager WMI provider, and a new feature for 4.0, Windows PowerShell Desired State Configuration (DSC).

Download is available at

http://www.microsoft.com/en-us/download/details.aspx?id=39347

Note: It only installs on these versions of Windows

- Windows 7 with Service Pack 1
- Windows Server 2008 R2 with Service Pack 1
- Windows Server 2012
Windows 8 is not an option


June 26, 2013  4:09 PM

Dropping a database



Posted by: Richard Siddaway
PowerShell, SQL Server

A question came up on the forum regarding dropping a database & I realised it was something I hadn’t done before.

SMO provides a set of classes for managing SQL Server. You get SMO when you install the SQL Server management tools

Import the module to load SMO assemblies

import-module sqlps

get the server object and view the databases
$server = New-Object Microsoft.SqlServer.Management.Smo.Server(“w12scorc”)
$server.Databases

view the target database
$server.databases["mydb"]

drop the database and view the databases again
$server.databases["mydb"].Drop()
$server.databases


June 26, 2013  2:06 PM

RDP annoyance



Posted by: Richard Siddaway
Windows 8, Windows Server 2012

I’ve RDPing into a number of servers from different systems recently and the way the screen resolution changes to match your monitor size is annoying. If I use the shortcut to the session I get whatever sizes were set in the last session so often logon, curse when the size isn’t convenient and logoff and reset.

maybe I should just buy a giant monitor?


June 26, 2013  1:59 PM

Windows Server 2012 R2



Posted by: Richard Siddaway
PowerShell

The Windows Server 2012 R2 preview is available on MSDN subscriber downloads. It has PowerShell v4!!!!


June 26, 2013  1:55 PM

Follow up on user group



Posted by: Richard Siddaway
PowerShell, User Group

I did a test tonight and the sound is definitely better over Lync. The sound wasn’t perfect but was much better than Live Meeting. Actually, seemed usable.

The system seems a lot more responsive in terms of client screen refresh. When showing slides the client refreshes very quickly. Showing code seemed better – not as quick bet definitely better than Live Meeting. I’ll try a new microphone and see if that improves things


June 25, 2013  1:43 PM

UK PowerShell group



Posted by: Richard Siddaway
PowerShell, User Group

As you are probably aware the UK PowerShell group has been very quiet over the last few months. This has been due to my personal circumstances – hopefully now resolved.

I want to re-start the group and was wondering what people wanted.

When I started the group 6 years ago we were the only PowerShell user group in the world! Things have changed. Back then I could easily organise physical meetings where the personal contact and ability to talk to people who were also learning PowerShell was invaluable. Its not possible to get the venues these days so I switched to using Live Meeting. Not as satisfying but much easier from a logistics stand point. There are problems with sound quality over Live Meeting. I’ve tried it on a number of networks from a number of machines and the sound is poor at best and impossible to listen to at worst.

The big problem for any user group is finding speakers. There aren’t that many people willing to speak on any particular topic and many of them aren’t based in the UK.

At the moment I’m thinking of a web cast every other month. I can’t do every month – I just don’t have the time. If I can find other speakers to fill the gaps that will be great but I’m working on worst case. Six sessions a year I can manage.

This supposes that I can resolve the sound problems. I’m experimenting with Lync and hope that will solve the problem. if it doesn’t then a total rethink is required.

So the question to the PowerShell community – what do you want?


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: