PowerShell for Windows Admins


March 2, 2012  4:29 PM

Windows 8 Modules

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We saw the modules that come with Windows server 8

 

This is the list of modules available in a vanilla Windows 8 32 bit install

AppLocker
Appx
BitLocker
BitsTransfer
BranchCache
CimCmdlets
DirectAccessClientComponents
Dism
DnsClient
International
iSCSI
Kds
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Host
Microsoft.PowerShell.Management
Microsoft.PowerShell.Security
Microsoft.PowerShell.Utility
Microsoft.WSMan.Management
MMAgent
MsDtc
NetAdapter
NetLbfo
NetQos
NetSecurity
NetSwitchTeam
NetTCPIP
NetworkConnectivityStatus
NetworkTransition
PKI
PrintManagement
PSDiagnostics
PSScheduledJob
PSWorkflow
ScheduledTasks
SecureBoot
SmbShare
SmbWitness
Storage
TroubleshootingPack
TrustedPlatformModule
Wdac
WindowsDeveloperLicense

Again the core PowerShell modules are italicised – though that concept is becoming redundant as PowerShell v3 auto loads all modules it finds on the module path

March 2, 2012  1:09 PM

PowerShell v3 in Depth

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Hot on the heels on the announcements of that PowerShell v3 beta is available for download either as a free standalone product for installation on Windows 7, Windows 2008 & Windows 2008 R2 or as a commercial product where an operating system is included – Windows 8 or Windows server 8 to suit your mood

http://msmvps.com/blogs/richardsiddaway/archive/2012/03/01/windows-8-and-powershell-3-betas.aspx

comes the announcement from Manning of a new PowerShell book

PowerShell v3 in Depth

Written by Don Jones, Jeffrey Hicks and myself it covers PowerShell v3 in great detail – how to get the absolute maximum out of PowerShell. The 40 chapters will cover all aspects of PowerShell v2 and v3. This book is about PowerShell it self – we won’t cover working with AD, Exchange etc.

This is a book with a single voice as all 3 authors work on each chapter – with individual anecdotes, comments and asides as a bonus-   you get our collected and individual experience and knowledge.  If you only buy one PowerShell book it should be this one

Access to the early drafts is available from

http://www.manning.com/jones2/


March 1, 2012  4:00 PM

Server 8 Beta PowerShell

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I downloaded the Windows Server 8 beta overnight and spun up a virtual machine. We get PowerShell v3 beta plus and whole host of modules

ADDeploymentWF
AppLocker
Appx
BestPractices
BitsTransfer
BranchCache
CimCmdlets
DirectAccessClientComponents
Dism
DnsClient
International
iSCSI
IscsiTarget
Kds
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Host
Microsoft.PowerShell.Management
Microsoft.PowerShell.Security
Microsoft.PowerShell.Utility
Microsoft.WSMan.Management
MMAgent
MsDtc
NetAdapter
NetLbfo
NetQos
NetSecurity
NetSwitchTeam
NetTCPIP
NetWNV
NetworkConnectivityStatus
NetworkTransition
NFS
PKI
PrintManagement
PSDiagnostics
PSScheduledJob
PSWorkflow
RDManagement
ScheduledTasks
SecureBoot
ServerManager
ServerManagerShell
SmbShare
SmbWitness
Storage
TelemetryManagement
TroubleshootingPack
TrustedPlatformModule
UpdateServicesDeployment
UserAccessLogging
Wdac
Whea
WindowsDeveloperLicense

This is a totally vanilla install with no features or roles installed. The RSAT tools aren’t installed either. 

The modules in italics are part of the base PowerShell install.   By comparison this is what is available from PowerShell v3 installed on Windows 7

AppLocker
BitsTransfer
CimCmdlets
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Host
Microsoft.PowerShell.Management
Microsoft.PowerShell.Security
Microsoft.PowerShell.Utility
Microsoft.WSMan.Management
PSDiagnostics
PSScheduledJob
PSWorkflow
TroubleshootingPack

Thats a lot of PowerShell to look at.  I’ll look and see what Windows 8 has by default


February 28, 2012  5:22 PM

UK PowerShell group–February 2012 recording

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The recording, slides and demo scripts from tonight’s PowerShell and SQL Server session are available as a single zip file for download from

https://skydrive.live.com/#cid=43CFA46A74CF3E96&id=43CFA46A74CF3E96%212943

The file is created with jzip but any zip handling program should be able to unzip it

Thank you to the attendees and especially for the questions – I’ve posted the answer to the question regarding accessing named instances using a port number here

http://msmvps.com/blogs/richardsiddaway/archive/2012/02/28/connecting-via-smo-to-a-named-instance.aspx

Next meeting will be 28 March 2012

Topic will probably be CIM in PowerShell v3


February 27, 2012  10:56 AM

February UG meeting–Final reminder

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

The UK PowerShell group presents a Live Meeting tomorrow on using PowerShell with SQL Server

Details from

http://msmvps.com/blogs/richardsiddaway/archive/2012/02/09/february-powershell-group-meeting-sql-server-and-powershell.aspx


February 25, 2012  10:11 AM

Using [wmiclass] accelerator and string substitution

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tripped over an interesting problem

I want to use the [wmiclass] accelerator because I need to find the key of a WMI class (code borrowed from PowerShell team blog – to be returned when I’ve finished with it)

 

$t = [WMIClass]$class

$t.properties |

select @{Name="PName";Expression={$_.name}} -ExpandProperty Qualifiers |

where {$_.Name -eq "key"} |

foreach {"The key for the $class class is $($_.Pname)"}

 

Now I wanted to add the namespace so I tried this

PS> $namespace="root\cimv2"
PS> $class="Win32_Process"
PS> [wmiclass]"\\.\$namespace:$class"
Cannot convert value "\\.\Win32_Process" to type "System.Management.ManagementClass". Error: "Invalid namespace "
At line:1 char:11
+ [wmiclass] <<<< "\\.\$namespace:$class"
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

 

Huh – of course root\cimv2 is valid

But its not a WMI problem its a string substitution problem

because

PS> $target = "$namespace:$class"
PS> $target
Win32_Process

Oh – no namespace

Its because of the colon

The way we get round it is to escape the : using a backtick `

[wmiclass]\\.\$namespace`:$class

Which works

Just a little WMI quirk to be aware of


February 22, 2012  3:32 PM

Download multiple files by BITS

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Last time we looked at BITS we saw how to transfer a single file. The example in the help file doesn’t work in my environment so this is what I came up with as a work around

Import-Module BitsTransfer -Force            
            
$computername = "WebR201"            
$destination = "c:\source\transfer\"            
            
Get-WSManInstance -ResourceURI wmicimv2/* -Enumerate -Dialect WQL `
 -Filter "SELECT * FROM CIM_DATAFILE WHERE Drive='C:' AND Path='\\Transfer\\' " `
  -ComputerName $computername  |            
foreach {            
             
$name = Split-Path -Path $($_.Name) -Leaf            
$source =  "http://webr201/transfer/$name"            
Write-Host "Transferring $source to $destination"            
            
Start-BitsTransfer -Source $source -Destination $destination             
            
Test-Path -Path ($destination + $name) -Verbose            
}

Import the module

The use WMI over WSMAN cmdlets to find the files in the folder – this assumes that I know the physical path to the virtual directory – within my enterprise there’s no reason why I shouldn’t.

For each of the files I create the URL to the file – use Write-Host to put out a message and then use Test-Path on the destination folder to determine that it has arrived


February 22, 2012  1:13 PM

object vs value

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

An interesting question came up recently. A Powershell user was trying to access an AD attribute so they did something like this

$x = Get-ADUser -Identity usera -Properties * | select useraccountcontrol

 

When they tried to use $x it didn’t correctly in the rest of the script.

 

Select-object is used to filter down the attributes that are left on the object as it passes on the pipeline

So

PS> Get-ADUser -Identity usera -Properties * | select useraccountcontrol

useraccountcontrol
        ——————
                        512

 

If you just want the value rather than an object (I know that its still an object but in reality we work directly with the value) then use –expandproperty. On a property with a single value it returns that value

PS> Get-ADUser -Identity usera -Properties * | select -expandproperty useraccountcontrol
512


February 21, 2012  4:14 PM

System Center engineering blogs

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The System Center family of products is getting a big make over in the 2012 release. The team blogs have just been rebranded to reflect this

System Center: Service Manager

System Center: Operations Manager

System Center: Virtual Machine Manager

System Center: Orchestrator

System Center: Data Protection Manager


February 21, 2012  3:58 PM

BITS

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

As well as looking at WMI I thought it was time to branch out a bit and look at other functionality that could administrators

The BITS (Background Intelligent Transfer Service) service is used for file transfer. Its normally thought of as being used across the internet but it can also be used in the enterprise. PowerShell v2 on Windows Vista/2008 and above comes with a BITS module

Import-Module BitsTransfer

which contains these cmdlets

Add-BitsFile – Adds one or more files to an existing Background Intelligent Transfer Service (BITS) transfer job.
Complete-BitsTransfer – Completes a Background Intelligent Transfer Service (BITS) transfer job.
Get-BitsTransfer – Retrieves the associated BitsJob object for an existing Background Intelligent Transfer Service (BITS) transfer job
Remove-BitsTransfer – Cancels a Background Intelligent Transfer Service (BITS) transfer job.
Resume-BitsTransfer – Resumes a Background Intelligent Transfer Service (BITS) transfer job.
Set-BitsTransfer – Modifies the properties of an existing Background Intelligent Transfer Service (BITS) transfer job.
Start-BitsTransfer – Creates a new Background Intelligent Transfer Service (BITS) transfer job.
Suspend-BitsTransfer – Suspends a Background Intelligent Transfer Service (BITS) transfer job.

The actual transfer can be accomplished like this

Start-BitsTransfer -Source http://webr201/transfer/test1.txt -Destination c:\source\transfer\

The help states that wildcards are supported in the source but my testing, so far just produces an error message.

So far I’ve been using a full IIS server as the source – there is another way as we will see later


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: