Monthly Archive

Categories

Windows 8 Server

Setting a Network address in Windows Server 8

 

Windows Server 8 & Windows 8 bring a host of new functionality to us. I wanted to try out some of it so created a new VM and installed the OS – went for full GUI for now

Opened PowerShell and ran

Set-ExecutionPolicy remotesigned
Enable-PSRemoting -Force

The NetTCPIP module has some commands for working with network addresses

Get-NetIPInterface -ConnectionState Connected

ifIndex ifAlias            AddressFamily  NlMtu(Bytes)  InterfaceMetric Dhcp    Store
------- -------            -------------  ------------  --------------- ----     -----
21      Virtual Wireless   IPv6           1500          5               Disabled Active
12      Virtual LAN        IPv6           1500          5               Disabled Active
21      Virtual Wireless   IPv4           1500          5               Disabled Active
12      Virtual LAN        IPv4           1500          5               Disabled Active

The display is abridged to fit

The important points are the ifIndex and ifAlias.  The index scheme is totally   different to the Win32_NetworkAdapter*  scheme

To set the address

New-NetIPAddress -InterfaceAlias "Virtual Wireless" -IPv4Address 192.168.2.10 -PrefixLength 24 -DefaultGateway 192.168.2.1

Set-DnsClientServerAddress -InterfaceAlias "Virtual Wireless" -ServerAddresses 192.168.2.1
Set-DnsClient -InterfaceIndex 21 -ConnectionSpecificSuffix beta8.test

Notice that you have to use New-NetIPAddress. The logic seems to be that you are adding a new address to the adapter so use New*.

Set-NetIPAddress works to modify an existing address BUT you can’t change the default gateway that way!

The Set-DnsClient* cmdlets are in the DnsClient module

All of these cmdlets are based on calls to WMI classes

At the end of all that I wanted to bounce the machine any way so used

Restart-Computer

PowerShell web access

Would you like to be able to access a PowerShell console in a web browser to manage your remote machines?

You would – then PowerShell web access in Windows Server 8 is just for you

Introductory details here:

http://blogs.msdn.com/b/powershell/archive/2012/03/07/introducing-windows-powershell-web-access-in-windows-server-8-beta.aspx

Windows Server 8–features removed or deprecated

When you start your implementation planning for Windows Server 8 make sure to check with this page for functionality that has been removed or deprecated (means it will be removed in a future version)

http://technet.microsoft.com/en-us/library/hh831568.aspx

Server 8 Beta PowerShell

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

Windows 8 and PowerShell 3 betas

If you haven’t already heard there are new toys available

Windows 8 beta is available from

http://windows.microsoft.com/en-GB/windows-8/download

Windows Server 8 beta is available from

http://www.microsoft.com/en-us/server-cloud/windows-server/v8-default.aspx

 

Most importantly PowerShell v3 beta is from

http://www.microsoft.com/download/en/details.aspx?id=28998

Windows Management Framework 3.0 makes some updated management functionality available to be installed on Windows 7 SP1, Windows Server 2008 R2 SP1 & Windows Server 2008 SP2. Windows Management Framework 3.0 contains Windows PowerShell 3.0, WMI & WinRM.

CIM instances

We are use to using Get-WmiObject to retrieve information from WMI. if you have been following this blog for any length of time you will have see lots of examples of that particular cmdlet. The CIM equivalent is Get-CIMInstance. It might appear that Get-CIMClass would be used but that is used to get information about the WMI class itself. think Get-WmiObject –List  on steroids.

This should be familiar

Get-WmiObject -Class Win32_ComputerSystem

The direct comparison is

Get-CimInstance -ClassName Win32_ComputerSystem

 

We can run WQL queries

$q = "SELECT * FROM Win32_ComputerSystem"
Get-WmiObject -Query $q

 

Get-CimInstance -Query $q

 

And we can filter

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3"

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3"

 

Another difference is that CIM cmdlets tend to default to a table output but WMI cmdlets tend to default to a list

 

We can even select properties

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -Property DeviceID, FreeSpace, Size

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" -SelectProperties DeviceID, FreeSpace, Size

 

Here we get a big difference

WMI returns the properties we asked for plus the System properties (those starting with __) for the class. CIM returns the whole object but only the select properties and the system type properties are populated.

 

So far you could be forgiven for thinking these are very similar and we don’t need both. The big differences come when we look at accessing remote machines next time.

WMI and CIM

Do you know the difference between WMI and CIM?

CIM is the Common Information Model - http://www.dmtf.org/standards/cim

“CIM provides a common definition of management information for systems, networks, applications and services, and allows for vendor extensions. CIM's common definitions enable vendors to exchange semantically rich management information between systems throughout the network.”

 

WMI is Microsoft’s implementation of CIM

Get-WmiObject CIM_DiskDrive
Get-WmiObject Win32_DiskDrive

return the same information

Win32_DiskDrive is derived from CIM_DiskDrive.  The CIM class is the superclass for the Win32 class.

Why is this important?

Because in PowerShell v3 Microsoft introduce a while new API for working with WMI -  and whole new bunch of cmdlets

Get-CimAssociatedInstance
Get-CimClass
Get-CimInstance
Get-CimSession
Invoke-CimMethod
New-CimInstance
New-CimSession
New-CimSessionOption
Register-CimIndicationEvent
Remove-CimInstance
Remove-CimSession
Set-CimInstance

compare these to the WMI cmdlets

Get-WmiObject
Invoke-WmiMethod
Register-WmiEvent
Remove-WmiObject
Set-WmiInstance

The analogous CIM cmdlets are highlighted.

The CIM cmdlets use different .NET classes to WMI cmdlets

PS> Get-WmiObject Win32_DiskDrive | gm

   TypeName: System.Management.ManagementObject#root\cimv2\Win32_DiskDrive

 

PS> Get-CimInstance Win32_DiskDrive | gm

   TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_DiskDrive

 

Microsoft have made a big investment in WMI/CIM for Windows 8.  I’ll explore some of the new things in coming posts

PowerShell, Storage, WMI and Windows Server 8

A must read if you are interested in any of these

http://blogs.technet.com/b/server-cloud/archive/2011/10/14/windows-server-8-standards-based-storage-management.aspx

 

WMI is getting everywhere these days – better learn it quick

PowerShell 3 and DHCP: scope options

In this post - http://msmvps.com/blogs/richardsiddaway/archive/2011/09/23/powershell-3-and-dhcp-2-scopes.aspx - we created a new DHCP scope.

Now we need to set some options on the scope. One of the main options we need to set is the DNS server

We can see the available options using

Get-DhcpServerv4OptionDefinition -ComputerName server02

This displays a list of the available options – remember that we can add our own so this isn’t necessarily a static list

The options that are set for the test scope are

PS> Get-DhcpServerv4OptionValue -ComputerName server02 -ScopeId 192.168.100.0

OptionId   Name            Type       Value                VendorClass     UserClass       PolicyName
--------   ----            ----       -----                -----------     ---------       ----------
51         Lease           DWord      {86400}

The DNS server for this scope can be set like this

PS> Set-DhcpServerv4OptionValue -ComputerName server02 -ScopeId 192.168.100.0 `
-DnsServer 10.10.54.201

OptionId   Name            Type       Value                VendorClass     UserClass       PolicyName
--------   ----            ----       -----                -----------     ---------       ----------
6          DNS Servers     IPv4Add... {10.10.54.201}

PowerShell 3 and DHCP 2: scopes

In this post http://msmvps.com/blogs/richardsiddaway/archive/2011/09/20/powershell-and-dhcp-1-servers.aspx

I showed how we could discover DHCP server information

Scopes can be discovered

Get-DhcpServerv4Scope -ComputerName server02  -ScopeId 10.10.54.0

Now how do we create a scope?

We use Add-DhcpServerv4Scope. Now shouldn’t that have been New-DhcpServerv4Scope?

Never the less this is how it works

Add-DhcpServerv4Scope -ComputerName server02 -Name TestScope 
-StartRange 192.168.100.1 -EndRange 192.168.100.200
-Description "Scope for testing" -Type DHCP
-State Active -SubnetMask 255.255.255.0
-LeaseDuration (New-TimeSpan -Days 1)

Type can be Dhcp,Bootp or Both

State can be Active or InActive

This creates and activates the scope

To inactivate a scope

Set-DhcpServerv4Scope -ComputerName server02
-ScopeId 192.168.100.0
-State Inactive

To reactivate

Set-DhcpServerv4Scope -ComputerName server02
-ScopeId 192.168.100.0
-State Active

To create a reservation

Add-DhcpServerv4Reservation -ComputerName server02
-ScopeId 192.168.100.0 -IPAddress 192.168.100.190
-ClientId 00-01-02-03-04-05 -Name Test57 
-Description "Exclusion for test device"

The ClientId is the MAC address (this one is made up)

To view the scopes reservations

Get-DhcpServerv4Reservation -ComputerName server02 -ScopeId 192.168.100.0

To remove a reservation

Remove-DhcpServerv4Reservation -ComputerName server02
-ScopeId 192.168.100.0 -ClientId 00-01-02-03-04-05