PowerShell for Windows Admins


October 7, 2010  1:01 PM

Architecture, Administration and Automation

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

At first glance these three topics may seem to have nothing in common apart from the fact that they all begin with the letter “A”.  They are however intimately linked as we will see.

Architecture in an IT sense has many definitions (one per practising IT Architect at the last count) but I regard it as a the set of principles  around which you design your IT. To keep it simple I’ll restrict the discussion to infrastructure. I have heard much debate about the difference between architecture and design. I have a simple view – if products are mentioned its a design. As an example the decision to utilise virtualisation is an architectural one but whether to use Hyper-V or VMware for instance is a design decision.

So now we’ve decided what architecture is what its impact on administration. Quite simple really. One of the biggest problems facing IT administrators today is the complexity of the environment they are working in. You can easily find yourself in an environment with six versions of Windows (NT, 2000, 2003, 2003 R2, 2008, 2008R2 – I know the first two are out of support but I bet a lot of organisations are still using them) and that’s before you add in the complexity of 32 vs 64 bit and standard vs enterprise (or even datacenter) editions. Add a few applications – multiple versions and editions of SQL Server, a few Exchange servers, SharePoint, web servers, a raft of third party applications  -  plus file and print gives you a wide spread of skills that are needed. We mustn’t forget Windows itself plus the necessary additions of Active Directory and DNS. We haven’t even got to  the client systems and their applications which further muddy the waters.  Then we get to servers – virtualised plus one or more of the big vendors (usually more) and a whole bunch of different models add to the fun. The odd Linux or Unix server just to keep us awake and all the network, remote access and other issues and we end up with a very busy set of people.

It is the IT architect’s responsibility to architect/design complexity out of the environment. Standardise on specific sizes of servers, a single virtualisation platforms, minimise the number of Windows versions etc, etc etc.  This makes the administrator’s job easier because there is a relatively simple, standard set of items to wok with.

One of the biggest causes of downtime is human error. Reducing the complexity of the environment helps to reduce the possibility of error. The other way to reduce human error is to introduce as much automation as possible. The administrator has a responsibility to embrace and use automation to make their jobs easier and reduce errors.  The architect has the responsibility to ensure that the components selected in the architecture/design can be automated using the standard toolset within the organisation.

Architecture + Automation =  improved Administration

October 6, 2010  2:53 PM

WMI and Network Adapters: 9

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We have seen how to test if a NIC is DHCP enabled but what about manipulating the DHCP settings.  First off lets look at renewing a DHCP lease.

We can see the lease information

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′"  | select *dhcp*

The important properties are:

DHCPEnabled       : True
DHCPLeaseExpires  : 20101007180829.000000+060
DHCPLeaseObtained : 20101006180829.000000+060

The system can be told to get a new lease by using the RenewDHCPLease method

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′"  |

Invoke-WmiMethod -Name RenewDHCPLease

We can then test the lease again

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′"  | select *dhcp*

DHCPEnabled       : True
DHCPLeaseExpires  : 20101007214733.000000+060
DHCPLeaseObtained : 20101006214733.000000+060

Job done


September 30, 2010  12:28 PM

WMI and Network Adapters: 8

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We were looking at MAC Addresses last time. We can filter on MAC address

Get-WmiObject -Class Win32_NetworkAdapter -Filter "MACAddress=’00:27:2B:F5:96:D5′"

No its not my real MAC address :-)

There are two useful methods on the NetworAdapter class – Disable and Enable

They couldn’t be easier to use

$nic = Get-WmiObject -Class Win32_NetworkAdapter -Filter "MACAddress=’00:27:2B:F5:96:D5′"

Invoke-WmiMethod -InputObject $nic -Name Disable

aand if you want to bring it back

Invoke-WmiMethod -InputObject $nic -Name Enable

The filter can be modified to work on whichever property is the best for your activities


September 29, 2010  1:20 PM

WMI and Network Adapters: 7

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

One task I find myself doing on a regular basis is checking the physical address of a NIC. Ipconfig is OK but we have to wade through a lot of stuff.  Much simpler to do this

Get-WmiObject -Class Win32_NetworkAdapter -ComputerName "." |
select Name, MACAddress

Produces a nicely formatted output and its quick to type


September 27, 2010  3:18 PM

One cmdlet at a time

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

PowerShell MVP Jonathan Medd has compiled all of his blog posts on the new cmdlets in PowerShell 2.0 into a downloadable pdf file.

Hugely recommended as a reference to keep on you computer desk top.

get it now from http://www.jonathanmedd.net/2010/09/powershell-2-0-one-cmdlet-at-a-time-available-as-pdf-download.html


September 26, 2010  2:16 PM

WMI and Network Adapters: 6

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We have seen how to test for the DNS server in use. What about testing for DHCP?

001
002
003
004
005
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName "." | 
where {$_.DHCPEnabled} | 
select Description, IPAddress, DHCPServer,
@{Name=‘LeaseStart’;Expression={$_.ConvertToDateTime($_.DHCPLeaseObtained)}},
@{Name=‘Leaseend’;Expression={$_.ConvertToDateTime($_.DHCPLeaseExpires)}}

Get the instances of the NetworkAdapterConfiguration class. This time we filter in those instances that have the DHCPEnabled property set to True. We select the NIC description, IP Address, DHCP server and the start and end time of the lease. We have to convert the dates into a readable format using the ConvertToDate method.


September 26, 2010  12:59 PM

WMI and Network Adapters: 5

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Does a machine have problems communicating on the network? Then one troubleshooting step is to check the DNS servers it is using

001
002
003
004
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName "." |
where {$_.DNSServerSearchOrder} |
select Description, IPAddress, DNSServerSearchOrder

Get the instances of the NetworkAdapterConfiguration class for the computer and filter out those that don’t have a DNSServerSearchOrder set.  Display the results.

If you get nothing back then no NICs have DNS settings


September 20, 2010  1:34 PM

Environment

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

Want a quick peek at the environment settings on your machine? Then try

Get-WmiObject -Class Win32_Environment  | Format-Table name, variablevalue -AutoSize –Wrap

if you just want the local machine try

Get-ChildItem env:

for a slightly different view


September 15, 2010  1:20 PM

September UG meeting

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Many thanks to everyone who joined us for the Live Meeting last night. Especial thanks to Jonathan for an excellent presentation.  As promised Jonathan has posted the slide deck

http://www.jonathanmedd.net/2010/09/september-uk-powershell-user-group-%e2%80%93-remoting-slidedeck.html

 

The recording is available from

Richard Siddaway has invited you to view a Microsoft Office Live Meeting recording.
View Recording
Recording Details
    Subject: PowerShell Remoting
    Recording URL: https://www.livemeeting.com/cc/usergroups/view
    Recording ID: 56QBWG
    Attendee Key: WF,6(G8xj


September 13, 2010  12:21 PM

Scripting Guy Blog

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

The Scripting Guys are having a guest blogger week and first up is me blogging about managing DNS with PowerShell and WMI

http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/13/manage-dns-in-a-windows-environment-by-using-powershell.aspx

Enjoy


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: