PowerShell for Windows Admins


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


September 12, 2010  5:52 AM

Deleting files older than a certain date

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

A question on the ITKE forums asked how files older than a certain date (in this case two months) could be deleted without touching younger files.

001
002
003
$date = (Get-Date).AddMonths(-2)
Get-ChildItem -Path c:\scripts | where {!$_.PSIsContainer} |
foreach {if ($_.LastWriteTime -lt $date){Remove-Item $_ -whatif}}

Simply remove the –whatif parameter for the delete to actually happen


September 6, 2010  12:47 PM

WMI and Network Adapters: 4

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We have looked at using Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration. 

Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetEnabled=’$true’" |
Format-List NetConnectionID, Description, MACAddress, Speed

Get-WmiObject -Class Win32_NetworkAdapterConfiguration |
where {$_.IPAddress} | Foreach { $_.Description; $_ |
select -ExpandProperty IPAddress}

Now we need to look at combining the information from the two classes. One way to do it is like this

001
002
003
004
005
006
007
008
009
010
011
012
Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetEnabled=’$true’" | 
foreach {
 $_ | Format-List NetConnectionID, Description, MACAddress, Speed 

 $filt = "Index=’" + $_.DeviceID + "’"
 $nic = `
 Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter $filt 
 
 $nic | Format-List DefaultIPGateway, IPSubnet, DNSServerSearchOrder
 "IP Address"
 $nic | select -ExpandProperty IPAddress
}

This doesn’t give the most elegant of results so we will need to refine what we are doing


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: