PowerShell for Windows Admins


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


September 2, 2010  12:26 PM

September PowerShell User Group

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

When: Tuesday, Sep 14, 2010 8:30 PM (BST)
Where: Virtual

*~*~*~*~*~*~*~*~*~*

Jonathan Medd – PowerShell MVP – explains the new remoting features in PowerShell 2.0

Richard Siddaway has invited you to attend an online meeting using Live Meeting.

Join the meeting.

Audio Information

Computer Audio

To use computer audio, you need speakers and microphone, or a headset.

First Time Users:

To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.

Troubleshooting

Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:

    https://www.livemeeting.com/cc/usergroups/join
  2. Copy and paste the required information:

    Meeting ID: 56QBWG

    Entry Code: WF,6(G8xj

    Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Notice

Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.


August 31, 2010  2:03 PM

WMI and Network Adapters: 3

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

We have seen how to query WMI for information on network adapters.  But what we didn’t get was information about the addresses allocated to the NICs.  We need a different class for that

Get-WmiObject -Class Win32_NetworkAdapterConfiguration

However this gives us too much information as it includes all cards – we only want to see those with addresses

Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where {$_.IPAddress}

Gives us the two NICs (on my machine that are live). 

To just get the addresses

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

Gives a quick view of the addresses associated with each card


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: