Share via


Tech Ed 2008 - Demo 1 - Administering Windows

Hello Again

Well I’ve delivered my session “Windows, PowerShell and WMI: Unveiling Microsoft’s Best Kept Secret”, and as promised here are the scripts for the Demo’s I used during my session:

Demo 1 – Administering Windows

All these demos are simple command lines that I just typed straight in PowerShell, no need for any fancy scripts.

Basics

The following lines of code show help on how to use the Get-WMIObject cmdlet in PowerShell, how to list all classes in the cimv2 namespace and finally how to use some basic parameters.

 

Get-Help -name Get-WMIObject

Get-Help -name Get-WMIObject –det

get-wmiobject -namespace "root\cimv2" –list

Gwmi -namespace "root\cimv2" –list

Gwmi -namespace "root\cimv2" -class Win32_LogicalDisk

Gwmi -class Win32_LogicalDisk

Gwmi Win32_LogicalDisk

Gwmi Win32_LogicalDisk –computername localhost

$cred = get-credentials

Gwmi Win32_LogicalDisk –credential $cred

 

Disks

These lines of code show how to get disk information from a system, identify all the properties and methods of the disk objects that can be used, then uses some properties.

Gwmi Win32_LogicalDisk | Get-Member

$disks = gwmi Win32_LogicalDisk –computername localhost

$disks[0].freespace

$disks[0].freespace/1gb

$disks[0].filesystem

 

Hotfixes

These lines connect to a system and list all the Hotfixes that have been installed.

$hotfixes = gwmi Win32_QuickFixEngineering –computername localhost

$hotfixes | get-member

$hotfixes | format-table Hotfixid

 

 

OperatingSystem

These lines enumerate basic operating system information: the OS version, service pack level and OS architecture type.

$os = gwmi win32_OperatingSystem -computername Serverxxx

$os | get-member

$os | format-list caption, CSDVersion,OSArchitecture

 

Network Adapter

The following lines modify the IP Address and Subnet Mask of a network adapter using the EnableStatic method.

$nics = Gwmi win32_NetworkAdapterConfiguration

$nic = $nics | where{$_.description –like “*XXXXXXXXXXXX*”}

$IPAddress = x.x.x.x

$subnetmask = x.x.x.x

$nic.EnableStatic($IPAddress, $SubnetMask)

 

Well that’s the first demo stay tuned for Demo 2 – Administering Servers in Bulk.

Enjoy!

BenP

Comments

  • Anonymous
    January 01, 2003
    I mentioned that one of my favorite TechEd 2008 talks was Ben Pearce's talk, "Windows, PowerShell and

  • Anonymous
    January 01, 2003
    The comment has been removed