Summary: Microsoft Scripting Guy, Ed Wilson, talks about Windows PowerShell cleanup work to do following a migration to Windows Server 2012.
Microsoft Scripting Guy, Ed Wilson, is here. Well, following any migration, there is always a bit of cleanup work. Luckily, Windows Server 2012 enables Windows PowerShell remoting by default. This means that the cleanup is not too bad.
Note Read about my experience upgrading my group of servers to Windows Server 2012 in yesterday’s Hey, Scripting Guy! blog post: The 32-hour Upgrade to Windows Server 2012.
First Windows PowerShell task—ensure you update Help
One of the cool new features of Windows PowerShell 3.0 is the updatable Help. The great thing about this is that it makes it easy to always have the latest Help files. Once I complete my upgrade to Windows Server 2012 (or, for that matter, to Windows 8, or any computer to Windows PowerShell 3.0) I need to run the Update-Help cmdlet.
I could simply run Update-Help on each computer, and then tell it to go off to the Internet and grab the latest Help files. But that is inefficient, and Windows PowerShell 3.0 has provisions for offline updates.
So, from my laptop computer (which, incidentally, has the Windows 8 RSAT tools and, therefore, all the modules installed on it), I run the Save-Help cmdlet. I point it to a shared folder on my network. The following image shows the command and the associated output.
OK, so that was less than impressive. The reason? Well, the destination folder must exist. I was hoping that it would be smart enough to create my poshhelp directory. Oh, well. No problem. I revise the command as appears here.
PS C:\> New-Item -ItemType directory -Path \\dc1\share\poshhelp
Directory: \\dc1\share
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 11/5/2012 2:12 PM poshhelp
PS C:\> Save-Help -Module * -DestinationPath \\dc1\share\poshHelp
A couple of errors still appear, but that is due to the fact that Help is trying to update Help for some modules that do not have updated Help. Cool. Now, I need to update the Help by using the share for all my new Windows Server 2012 servers. This is easier than it appears. Remember, I have the RSAT tools on my laptop, therefore, I have access to the Get-ADComputer cmdlet. I use the following command to obtain all of the servers that run Windows Server 2012 on my network.
PS C:\> Get-ADComputer -Filter * -properties operatingsystem | where operatingsystem
-match 2012 | select name
name
----
DC3
DC4
W8SERVER8
W8S504
HYPERV3
SQL1
WDS1
HYPERV2
DC2
WEB1
I store the results of the command (not by using Select-Object) into a variable I call cn. This is shown here.
$cn = Get-ADComputer -Filter * -properties operatingsystem | where operatingsystem -match 2012
By using an automatic expansion (a cool Windows PowerShell 3.0 feature), it is easy to get the computer names. I just pick out the property. I will include it in my command to create the Windows PowerShell session. I know some of these computers are offline, and so I expect some errors. Here is the command I use to create the sessions.
$session = New-PSSession -cn $cn.name -Credential iammred\administrator
I query the $session variable to see that at least some computers worked. This appears here.
PS C:\> $session
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
4 Session4 DC3 Opened Microsoft.PowerShell Available
5 Session5 DC4 Opened Microsoft.PowerShell Available
8 Session8 HYPERV3 Opened Microsoft.PowerShell Available
11 Session11 HYPERV2 Opened Microsoft.PowerShell Available
9 Session9 SQL1 Opened Microsoft.PowerShell Available
10 Session10 WDS1 Opened Microsoft.PowerShell Available
13 Session13 WEB1 Opened Microsoft.PowerShell Available
12 Session12 DC2 Opened Microsoft.PowerShell Available
The commands and associated output appear here.
I now use Invoke-Command to update Help on all of my servers. This appears here.
Invoke-Command -Session $session -ScriptBlock {Update-Help -PSPath \\dc1\Share\poshhelp -Force}
If I do not want to fool with downloading Help, I can use the following command to update Help on all of my servers.
Invoke-Command -Session $session -ScriptBlock {Update-Help -force}
Of course, a few more errors about missing modules and stuff appear, but, in the end, I have updated all the Help on my servers.
Enable script support
Now, I want to enable scripting on the servers. This is also a single cmdlet—Set-ExecutionPolicy. Here is the command I use:
Invoke-Command -Session $session -ScriptBlock {Set-ExecutionPolicy remotesigned -force}
I can easily check the results by using Get-ExecutionPolicy. This is shown here.
PS C:\> Invoke-Command -Session $session -ScriptBlock {Get-ExecutionPolicy}
PSComputerName RunspaceId Value
-------------- ---------- -----
DC4 571a049f-c671-46e7-b72a-... RemoteSigned
DC3 8cc8e20d-2426-44fd-9ae5-... RemoteSigned
HYPERV3 b3f5afae-1f1b-43ca-918f-... RemoteSigned
SQL1 9609e293-26ff-4866-9734-... RemoteSigned
WEB1 d5dfcde8-2de1-4b8f-9a21-... RemoteSigned
WDS1 75124ffd-5f4b-4e27-91f4-... RemoteSigned
DC2 ea287978-f21f-4f27-85e1-... RemoteSigned
HYPERV2 a4e5f5ab-add7-4fe3-a7a7-... RemoteSigned
That is all there is to updating Help and configuring script support on my remote servers running Windows Server 2012. Join me tomorrow, when I will do remote updates.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy