Wednesday, July 18, 2007

ping a list of servers stored in a file or a subnet



#requires -Version 2.0
Function Ping-Subnet {
#.Synopsis
# Ping a subnet returning all alive hosts.
#.Example
# Ping-Subnet -IP 192.168.1.0 -Netmask /24
#.Example
# Ping-Subnet -IP 192.168.1.128 -Netmask 255.255.255.128
Param(
[string]
$IP,
[string]
$netmask
)
Begin {
$IPs = New-Object System.Collections.ArrayList
$Jobs = New-Object System.Collections.ArrayList
$max = 50
Function Get-NetworkAddress {
#.Synopsis
# Get the network address of a given lan segment
#.Example
# Get-NetworkAddress -IP 192.168.1.36 -mask 255.255.255.0
Param (
[string]
$IP,
[string]
$Mask,
[switch]
$Binary
)
Begin {
$NetAdd = $null
}
Process {
$BinaryIP = ConvertTo-BinaryIP $IP
$BinaryMask = ConvertTo-BinaryIP $Mask
0..34 | %{
$IPBit = $BinaryIP.Substring($_,1)
$MaskBit = $BinaryMask.Substring($_,1)
IF ($IPBit -eq '1' -and $MaskBit -eq '1') {
$NetAdd = $NetAdd + "1"
} elseif ($IPBit -eq ".") {
$NetAdd = $NetAdd +'.'
} else {
$NetAdd = $NetAdd + "0"
}
}
if ($Binary) {
return $NetAdd
} else {
return ConvertFrom-BinaryIP $NetAdd
}
}
}
Function ConvertTo-BinaryIP {
#.Synopsis
# Convert an IP address to binary
#.Example
# ConvertTo-BinaryIP -IP 192.168.1.1
Param (
[string]
$IP
)
Process {
$out = @()
Foreach ($octet in $IP.split('.')) {
$strout = $null
0..7|% {
IF (($octet - [math]::pow(2,(7-$_)))-ge 0) {
$octet = $octet - [math]::pow(2,(7-$_))
[string]$strout = $strout + "1"
} else {
[string]$strout = $strout + "0"
}
}
$out += $strout
}
return [string]::join('.',$out)
}
}


Function ConvertFrom-BinaryIP {
#.Synopsis
# Convert from Binary to an IP address
#.Example
# Convertfrom-BinaryIP -IP 11000000.10101000.00000001.00000001
Param (
[string]
$IP
)
Process {
$out = @()
Foreach ($octet in $IP.split('.')) {
$strout = 0
0..7|% {
$bit = $octet.Substring(($_),1)
IF ($bit -eq 1) {
$strout = $strout + [math]::pow(2,(7-$_))
}
}
$out += $strout
}
return [string]::join('.',$out)
}
}

Function ConvertTo-MaskLength {
#.Synopsis
# Convert from a netmask to the masklength
#.Example
# ConvertTo-MaskLength -Mask 255.255.255.0
Param (
[string]
$mask
)
Process {
$out = 0
Foreach ($octet in $Mask.split('.')) {
$strout = 0
0..7|% {
IF (($octet - [math]::pow(2,(7-$_)))-ge 0) {
$octet = $octet - [math]::pow(2,(7-$_))
$out++
}
}
}
return $out
}
}

Function ConvertFrom-MaskLength {
#.Synopsis
# Convert from masklength to a netmask
#.Example
# ConvertFrom-MaskLength -Mask /24
#.Example
# ConvertFrom-MaskLength -Mask 24
Param (
[int]
$mask
)
Process {
$out = @()
[int]$wholeOctet = ($mask - ($mask % 8))/8
if ($wholeOctet -gt 0) {
1..$($wholeOctet) |%{
$out += "255"
}
}
$subnet = ($mask - ($wholeOctet * 8))
if ($subnet -gt 0) {
$octet = 0
0..($subnet - 1) | %{
$octet = $octet + [math]::pow(2,(7-$_))
}
$out += $octet
}
for ($i=$out.count;$i -lt 4; $I++) {
$out += 0
}
return [string]::join('.',$out)
}
}
Function Get-IPRange {
#.Synopsis
# Given an Ip and subnet, return every IP in that lan segment
#.Example
# Get-IPRange -IP 192.168.1.36 -Mask 255.255.255.0
#.Example
# Get-IPRange -IP 192.168.5.55 -Mask /23
Param (
[string]
$IP,
[string]
$netmask
)
Process {
iF ($netMask.length -le 3) {
$masklength = $netmask.replace('/','')
$Subnet = ConvertFrom-MaskLength $masklength
} else {
$Subnet = $netmask
$masklength = ConvertTo-MaskLength -Mask $netmask
}
$network = Get-NetworkAddress -IP $IP -Mask $Subnet
[int]$FirstOctet,[int]$SecondOctet,[int]$ThirdOctet,[int]$FourthOctet = $network.split('.')
$TotalIPs = ([math]::pow(2,(32-$masklength)) -2)
$blocks = ($TotalIPs - ($TotalIPs % 256))/256
if ($Blocks -gt 0) {
1..$blocks | %{
0..255 |%{
if ($FourthOctet -eq 255) {
If ($ThirdOctet -eq 255) {
If ($SecondOctet -eq 255) {
$FirstOctet++
$secondOctet = 0
} else {
$SecondOctet++
$ThirdOctet = 0
}
} else {
$FourthOctet = 0
$ThirdOctet++
}
} else {
$FourthOctet++
}
Write-Output ("{0}.{1}.{2}.{3}" -f `
$FirstOctet,$SecondOctet,$ThirdOctet,$FourthOctet)
}
}
}
$sBlock = $TotalIPs - ($blocks * 256)
if ($sBlock -gt 0) {
1..$SBlock | %{
if ($FourthOctet -eq 255) {
If ($ThirdOctet -eq 255) {
If ($SecondOctet -eq 255) {
$FirstOctet++
$secondOctet = 0
} else {
$SecondOctet++
$ThirdOctet = 0
}
} else {
$FourthOctet = 0
$ThirdOctet++
}
} else {
$FourthOctet++
}
Write-Output ("{0}.{1}.{2}.{3}" -f `
$FirstOctet,$SecondOctet,$ThirdOctet,$FourthOctet)
}
}
}
}
}
Process {
#get every ip in scope
Get-IPRange $IP $netmask | %{
[void]$IPs.Add($_)
}
#loop untill we've pinged them all
While ($IPs.count -gt 0 -or $jobs.count -gt 0) {
#if we have open spots kick off some more
IF ($jobs.count -le $max) {
# determin how many to kick off
$addjobs = ($max - $jobs.count)
Foreach ($IP in ($IPS | Select -first $addjobs)) {
#save the job id, and move on
[VOID]$Jobs.Add((gwmi -q "SELECT Address,StatusCode FROM Win32_Pingstatus WHERE Address = `'$IP`'" -asjob).Id)
#remove the IP from our pool
$IPs.Remove($IP)
}
}
#we'll use this array to track what's comeback
$Clean = @()
Foreach ($J in $jobs) {
# If this job is done get the results
if ((Get-Job -id $j).JobStateInfo.state -eq 'Completed') {
# if the ping was sucessfull return the IP Address
write-output (Receive-Job -id $j) | ?{$_.StatusCode -eq 0}| select -expand Address
# dispose of the job
remove-job -id $j
$clean += $j
}
}
Foreach ($c in $Clean) {
#remove the jobs that we just processed
$jobs.remove($c)
}
}
}
}
=================================

filter Validate-IPAddress {
trap{continue;}
[System.Net.IPAddress]::Parse(_).IPAddressToString;
}

filter Ping-Host{
begin{ ping = new-object System.Net.NetworkInformation.Ping; }
process{ if(ping.Send(_).status -eq "Success") {_;} }
}



cat ip.txt | Validate-IPAddress | Ping-Host | foreach {
write-host "_ is ALIVE, run some code" -f green -b black
}

Yes, you can resolve the IP to name, for example:

PS > [system.net.dns]::GetHostEntry("192.168.1.1").HostName

======================
Test things out for yourself using the measure-command cmdlet to see which is faster, especially when the ping will fail.

measure-command {gwmi "select * from win32_pingstatus where address='foobar'"}

$ping=New-Object system.Net.NetwokInformation.Ping
Measure-Command {$ping.send("foobar")}
foreach ($server in (get-content servers.txt))
{
gwmi -query "Select * from win32_pingstatus where address='$server'" select Address,Statuscode

}

If you remove the pipe and the select statement, you can see all the available properties.

To add the IP address use Select Address,StatusCode,ProtocolAddressThe order you select them is the order they'll display.

must b run from a win xp or 2003 box

from ScriptingAnswers.com Forums Ping instead of WMI

Microsoft Windows Power Shell and SQL Server 2005 SMO – Part 4

Microsoft Windows Power Shell and SQL Server 2005 SMO – Part 4

PowerShell Convert To Date Time Method - Don Hite

PowerShell Convert To Date Time Method - Don Hite

write your own commandlets

Windows PowerShell Visual Studio 2005 Templates (C# and VB.NET)

Windows PowerShell SDK

Hosting Windows PowerShell Part 1 2 & 3

The DFO Show - Hosting Windows PowerShell Part 1
The DFO Show - Hosting Windows PowerShell Part 2
The DFO Show - Hosting Windows PowerShell Part 3

Tuesday, July 17, 2007

webcasts

TechNet Webcast: Next-Generation Command Line Scripting: Windows PowerShell (Level 300)
Jeffrey Snover provides an overview of Windows PowerShell for TechEd 2006. 5 stars!!


TechNet Webcast: An Overview of Windows PowerShell (Level 200)

TechNet Webcast: And Now for Something Completely Different: Introducing Windows PowerShell (Level 200)

Windows PowerShell Week

TechNet Webcast: The Windows PowerShell Scripting Crash Course (Level 200)

TechNet Webcast: Converting from VBScript to Windows PowerShell (Level 200)

TechNet Webcast: Functions, Filters, and Efficiency in Windows PowerShell (Level 200)

TechNet Webcast: Under-the-Hood Extensions in Windows PowerShell (Level 200)

TechNet Webcast: Mastering the Windows PowerShell Pipeline (Level 200)

TechNet Webcast: Windows PowerShell and Windows Management Instrumentation (Level 200)

PowerShell Scripting in Exchange Server 2007 (Level 200)



TechNet Webcast: Writing Scripts in Windows PowerShell (Level 200)

TechNet Webcast: New Kid on the Scriptblock: Writing Scripts with Windows PowerShell (Level 200)

TechNet Webcast: And Now for Something Completely Different: Introducing Windows PowerShell (Level 200)

TechNet Webcast: 24 Hours of Exchange Server 2007 (Part 09 of 24): Using PowerShell for Exchange Management (Level 200)

TechNet Webcast: 24 Hours of Exchange Server 2007 (Part 08 of 24): Introduction to Windows PowerShell (Level 200)

TechNet Webcast: Overview of Server Manager and Windows PowerShell in Windows Server "Longhorn" (Level 300)

TechNet Webcast: Windows PowerShell in Windows Server 2008 (Level 200)

current script directory

http://blogs.msdn.com/powershell/archive/2007/06/19/get-scriptdirectory.aspx

function Get-ScriptDirectory{$Invocation = (Get-Variable MyInvocation -Scope 1).ValueSplit-Path $Invocation.MyCommand.Path}

Monday, July 16, 2007

Benp's Guide to Stuff Benp’s Basic Guide to Managing Active Directory Objects with PowerShell

Benp's Guide to Stuff Benp’s Basic Guide to Managing Active Directory Objects with PowerShell

active directory user info

#list all properties of a user object
Get-QADUser -ReturnPropertyNamesOnly -IncludeAllProperties

# Get a list of properties and store it in an array$properties = Get-QADUser -ReturnPropertyNamesOnly -IncludeAllProperties# Get the actual user object and the outputGet-QADUser "jane doe" -IncludeAllProperties Format-List $properties

(instead of the user name you can use DN, SID, GUID, UPN, username or Domain\username).

thanks to Dmitry Sotnikov

# output for joe user displayname,sAMAccountName,mail,scriptPath,Department

Get-QADUser 'User Joshph P' Format-List displayname,sAMAccountName,mail,scriptPath,Department
Get-QADUser joeuser1Format-List displayname,info,sAMAccountName,mail,scriptPath,Department



# Updating user properties


#Set Notes/info the Joe Useruser account:

cls
Get-QADUser joeuser1Format-List displayname,info,sAMAccountName,mail,scriptPath,Department
Set-QADUser joeuser1-info 'Elvis Rules!!!'
Get-QADUser joeuser1Format-List displayname,info,sAMAccountName,mail,scriptPath,Department

All information gathered from here PowerGUI Community : A quick intro to the Management Shell ...



#--------------------------------------------------------------------------------------
Function GetUserDetails ([adsi]$user){
$user=[ADSI](get-wmiobject -class ds_user -namespace root\directory\ldap -filter "DS_samaccountname='$env:username'").adsipath
write-host "Hello " + $user.givenname}
#--------------------------------------------------------------------------------------

Function Start { trap {reportError} $btnExit.Text = "close" GetUserDetails $user write-host "Bye " + $user.sn #(1 / $null)}
#---------------------------------------------------

$aDSPath=(
get-wmiobject -class ds_user
-namespace root\directory\ldap
-filter "DS_samaccountname='$env:username'"
).adsipath

The above is NOT an ADSI query. It's a WMI query - notice the "getWMIObjecti". Open WBEMTEST and connect to the "root\directory\ldap" namespave then browse to the "ds_user" wmi class and you will see all of the properties as named by WMI.

Finding the static methods of a class

Finding the static methods of a class

powershell & dns

Using PowerShell to script DNS with WMI
Glen's Exchange Dev Blog Powershell DNS Utility script for querying MX, PTR and SPF records
-n software inc - NetCmdlets for Windows PowerShell
The PowerShell Guy Add Extended DNS support to PowerShell in 5 minutes

unanswered ?
Sandbox Calling FolderBrowserDialog from a ...

powerGUI

PowerGUI Community Main
Introduction to PowerGUI demo
Extending PowerGUI
PowerGUI Community A quick intro to the Management Shell ...
PowerGUI Hands-On Labs
PowerGUI Hands-On Labs Manual.

Sunday, July 15, 2007

A quick intro to the Management Shell for AD from Quest Software by Andrei Polevoi

originally posted here
this is a terrific post unfortunately being legally blind i find the print too small so i redid it and you can find it here

get maching info What’s that machine called

“Captain Literal”.NET » What’s that machine called

D:\PsScripts]36> . .\networkTools.ps1# Create a CSV file, just like Mamood has[D:\PsScripts]38> “MachineName”, “machine1″, ” machine2″, ” machine3″, ” machine4″ > machineList.csv# Get machine information from DNS[D:\PsScripts]40> $machines = @();[D:\PsScripts]41> import-csv machineList.csv % { $machineInfo = resolve-hostByName $_.MachineName; $machines += New-MachineObject $machineInfo.Hostname $machineInfo.AddressList[0] }# Ping each host to get alive status[D:\PsScripts]43> $machines % { $_.Alive = Get-AliveStatus $_.HostName }# Get MAC Address for each alive host[D:\PsScripts]45> $machines ? { $_.Alive } % { $_.MacAddress = Get-MacAddressForHost $_.HostName $_.IpAddress }# Finally, output as a table (or you could export to CSV if you prefer)[D:\PsScripts]47> $machines ftHostName IpAddress MacAddress Alive——– ——— ———- —–machine1.captainliteral.net 192.168.8.3 00:04:FF:0B:23:B2 Truemachine2.captainliteral.net 192.168.8.8 Falsemachine3.captainliteral.net 192.168.7.1 Falsemachine4.captainliteral.net 192.168.8.5 00:16:17:0E:23:B2 True
And that’s that.

Group Policy Administration with Windows PowerShell

SDM gpo Software

Simplify Group Policy Administration with Windows PowerShell

Saturday, July 14, 2007

oh the places i'v gone

a unoriginized collection i have visited that have been gathered from various computers i have woked on hopfully some day soon will get put in the right placess

PowerShell ROCKS!!!
Powershell Script Scripting Ldap Searches using PowerShell
Powershell Script List Domain Information
Powershell Script Library Applications User Applications Free Powershell Scripts. Download Free Powershell Scripts. Submit Powershell Scripts Free
Powershell Script Library Free Powershell Scripts. Download Free Powershell Scripts. Submit Powershell Scripts Free
Sandbox Windows PowerShell in Action
Microsoft Windows PowerShell and SQL Server 2005 SMO – Part II
Microsoft Windows PowerShell and SQL Server 2005 SMO – Part 3
Collection Creation Example
myITforum.com Makecoll.wsf - Script for Automating Collection Creation
myITforum.com Perform a task on a computer, a list of computers, an SMS client or an SMS collection
myITforum.com QueryCount and DiscProps MMC Tools
myITforum.com Software Deployment via Web Reports!
PowerGUI Community
Reporting Script (SMS 2003 Operations Guide)
scripting SMS 2003
Richard Siddaway's Weblog
Some PowerShell scripts ...
Windows PowerShell (Monad) - Microsoft's new Windows scripting language
Adventures in SPWonderland
Blogs
BS on PoSH - Blog » PowerShell Information Central
ScriptingAnswers.com Forums Searching AD with Powershell
ScriptingAnswers.com Forums Sending email from Powershell Script
ScriptingAnswers.com Forums Windows PowerShell
ScriptingAnswers.com Forums gui box with powershell
ScriptingAnswers.com Forums Handling ADSI objects
ScriptingAnswers.com Forums list computers from OU
ScriptingAnswers.com Forums Open an exisiting spreadsheet and read values
ScriptingAnswers.com Forums Passing-Returning values to functions
Lead, Follow, or Move » PowerShell
-n software inc - NetCmdlets for Windows Powershell - LDAP-Active Directory
OU Management with PowerShell « Dmitry’s PowerBlog PowerShell and beyond
powershell OU - Google Search
Search for a SAM Account Name
Searching Active Directory
Windows PowerShell ADSI Connections of LDAP
Windows Powershell Working with Active Directory -- TechNet Magazine, June 2007
2007 February 02 « Powershell,Passion,Persistence and Pursuit
Arul Kumaravel's WebLog ADSI Scripting with Windows PowerShell.
http://blogs.flaphead.dns2go.com/archive/tags/Tools/default.aspx
Chris' Weblog - Scripting
David Mohundro - Monday, August 28, 2006
Discussions - microsoft.public.windows.powershell Google Groups
How do I get a list of computers in an AD OU and then use them in a powershell script - TechNet Forums
Just Powershell it
pshell.info - VMware
TestPathCommand Properties (Microsoft.PowerShell.Commands)
Windows PowerShell Test-Path We Goofed
Admin Script Editor Script Library
powershell test-path - Google Search
pshell.info - Basics
Download details XML Notepad 2007
fri Windows PowerShell Week Question and Answer Log
get-content
How to Download Windows PowerShell 1.0
Introducing Windows PowerShell
James Manning's blog using PowerShell for Outlook automation
Mappings for the Active Directory Users and Computers Snap-in
--o-- PowerShelled PowerShell and SMS 2003
PowerGUI Community Main
PowerGUI Community PowerGui Library
PowerShell Commands for Active Directory Quest Software
PowerShell Community Extensions
PowerShell Community Extensions - Home
powershell read from a file - Google Search
PowerShell ROCKS!!!
PowerShell Scripts
Powershell Live
Powershell Live - foreach and foreach-object.
powershell's favorites on del.icio.us
powershell's favorites tagged with Prompt on del.icio.us
reference get-content
Rob van der Woude's Scripting Pages Batch Files, PowerShell, Rexx, KiXtart, Perl, VBScript, HTA
Sandbox Windows PowerShell in Action
SAPIEN Press - scripting books, VBScript books, PowerShell books, and more
SAPIEN Press - scripting books, VBScript books, PowerShell books, and more2
SAPIEN Technologies Knowledge Base
SAPIEN Technologies Support Forums
SAPIENblog
Scripting with Windows PowerShell
Serge van den Oever [Macaw]
Serge van den Oever [Macaw] PowerShell and debugging
Serge van den Oever [Macaw] PowerShell pitfalls reading text from file using get-content
SigningPowerShellScripts
The PowerShell Guy
The PowerShell Guy PowerShell Community Extensions Active Directory Provider Part 1
Don Hite PowerShell Script To Export Installed Product Information To A CSV File
Download details XML Notepad 2007
get-content
Guy's Scripting Ezine 110 - PowerShell and WMI
How to Download Windows PowerShell 1.0
Managing Windows Networks Using Scripts - Part 3 Understanding WMI
--o-- PowerShelled PowerShell and SMS 2003
PowerGUI Community Main
PowerGUI Community PowerGui Library
Deployment made simple using Powershell - The Code Project - .NET
Don Hite Microsoft Developer Network Windows PowerShell Online Resources
Monad Tutorial « WordPress.com
Musings of a PC My next self-tutorial on PowerShell
Nick's Blog April 2007
PowerGadgets Desktop Reporting and Monitoring for IT-DB Professionals - Who Don't Write Code.
PowerShell For Fun Perfect Prompt for Windows PowerShell
powershell tutorial - Google Search
Scott Hanselman's Computer Zen - Signing PowerShell Scripts
The Code Project - Search Articles - Free Source Code and Tutorials
Windows PowerShell Setting the console title to be your current working directory
Windows PowerShell Programmer's Guide
Windows PowerShell SDK
A guided tour of the Microsoft Command Shell Page 2
An Introduction to Windows Power Shell (Monad) - The Code Project - Win32 - SDK
how to create an access database from an excel spreadsheet - Google Search
NetCmdlets Part 3 PowerShell and Active Directory using -n software's LDAP cmdlet
powershell get a list of computers in active directory - Google Search
The PowerShell Guy
Adminspotting.net » Detecting Service Pack 2
Adminspotting.net » Iterating Active Directory
DotNetSlackers CodeSnip Get a complete computer list from Active Directory using .NET 2.0
Hey, Scripting Guy! How Can I Bind to an Active Directory User Account Using Windows PowerShell
Hey, Scripting Guy! How Can I Use Windows PowerShell to Get a List of All My Computers
Kill-UserProcess (my first whatif Script)
More on Select-Object
C# to PowerShell Translation Thought Process
Get-Uptime (The Custom Object extravaganza!!!)
--o-- PowerShelled PowerShell WMI Support in RC2 (Series part 2)
Windows Server Scripting - ScriptCenter PowerShell Scripts
+[WMIClass] - Google Search
An in-depth look at WMI and instrumentation, Part II
How can you remotely instantiate a WMI class in Windows Powershell
Latest Newsgroup Posts Re [WMIClass] versus get-wmiobject
BS on PoSH - Blog » Birth of a Script-Function

active directory

MOW has a number of blog postings on AD:http://thepowershellguy.com/blogs/posh/archive/2007/02/09/ad-infrastructure-management-with-powershell.aspxhttp://thepowershellguy.com/blogs/posh/archive/2007/02/09/ad-infrastructure-management-with-powershell.aspx

Another thing you can do is install the PowerShell community extensons which include an Active Directory provider:http://www.codeplex.com/PowerShellCX

There are a variety of PowerShell extensions available on CodePlex:http://www.codeplex.com/Project/ProjectDirectory.aspx?TagName=powershellThe


Exchange team has a library of examples at:http://www.exchangeninjas.com/PSSCategorieshere's one that has uses AD:http://www.exchangeninjas.com/ExchangeActiveSyncMonitoring

You can also use the WMI classes to get started AD if you're familiar with them. For example:get-wmiobject -class Win32_NTDomain

scripts

myItforum
Windows PowerShell Tip of the Week
The Script Center Script Repository Sample Windows PowerShell Scripts
ScriptingAnswers.com - PowerShell samples
Sample Monad-MSH Scripts
codePlex-PowerShell Scripts - Home
Scripting for Exchange
The Exchange 2007 Wiki - PowerShell Scripts
F5 DevCentral Labs PowerShell with iControl use PowerShell to manage your BIG-IP.
myITforum posh scripts

Thursday, July 12, 2007

scripting method

http://www.codeplex.com/PsObject/Wiki/View.aspx?title=WMI&version=4
http://powershelllive.com/blogs/feed-powershellguy/archive/2007/03/01/hey-powershell-guy-how-can-i-get-the-uptime-of-a-service.aspx
http://thepowershellguy.com/blogs/posh/archive/2007/03/26/powershell-wmi-explorer-part-2.aspx
PS> $w1 = Get-WmiObject -class Win32_OperatingSystem
PS> $w1 Get-Member
ConvertFromDateTime ScriptMethod System.Object ConvertFromDateTime();ConvertToDateTime ScriptMethod System.Object ConvertToDateTime();Delete ScriptMethod System.Object Delete();GetType ScriptMethod System.Object GetType();Put ScriptMethod System.Object Put();
PS> $w1.ConvertToDateTime($w1.LastBootUpTime)08 April 2007 10:05:35

Tuesday, July 10, 2007

Invoking Generic Methods on Non-Generic Classes in PowerShell

Invoking Generic Methods on Non-Generic Classes in PowerShell

posh & .NET

.NET types

How do I easily load assemblies, when LoadWithPartialName has been deprecated?

BS on PoSH - Blog » A Powershell Adventure Chpt2 ‘Using .NET in Powershell’

posh & .net who ate my disk

Skip the PowerShell Tutorials and Take a Test Drive Instead

powershell on codplex

powershell on codplex

gui box with powershell

gui box with powershell?

Exchange SMTP Log file DNS Test tool Powershell script

Using System.Windows.Forms.MessageBox in PowerShell

Accessing Database And Displaying Images Using Windows PowerShell

posh N wmi


thinking in powershell

thanks to Dennis Verweij and his blog Just Powershell it for this informative information on how to begin thinking in powershell

code using commandletts

#-- Get-ChildItemForEach-Object {if (test-path ./$_/rapporten){$dirname=$_.name;Get-ChildItem ./$dirname/reports}}Select-Object @{e={$dirname};n="homedir"},@{e={$_.name};n="report"}Export-Csv $env:systemroot\temp\reports.csv
#--

same code using aliases

#-- ls% {if (test-path ./$_/rapporten){$dirname=$_.name;ls ./$dirname/reports}}select @{e={$dirname};n="homedir"},@{e={$_.name};n="report"}export-csv $env:systemroot\temp\reports.csv
#--

thinking in powershell example referencing the above code

This may look like a lot of typing, but believe me, after a while, you'll type it in the command line as if it is you're native language.

Just type what you're thinking and it will all fall in place :

I want a directorylisting = ls
With the output I want to .. =
For every childitem it want.. = % {
If the directory exists If want to do the following = if (test-path ......){
remember the directory you search = $dirname=$_.name
and list the content of the report directory in this directory = ls ./$dirname/reports
End the "if" = }
End the "foreach"= }
With the output I want to .. =
and from this output only select the homedirectory and the name of the report in the report directory and name these "homedir" and "report" = select @{e={$dirname};n="homedir"},@{e={$_.name};n="report"}
With the output I want to .. =
export this data to a csv file in systemroot\temp and name it reports.csv = export-csv $env:systemroot\temp\reports.csv

Working with Active Directory

Active Directory

Managing Active Directory with Windows PowerShell

other blogs of mine

XoomAndMe


webSightings websites i find interesting as well as personal thoughts

powershell&me my powershell journey

miscITfinds miscellaneous info i have found useful in my work

music&me info i have found useful in my music hobby

Windows Live™ Spaces blog info i have found useful in my work as well as other interests

setting up powershell environment

this purpose of this blog is to document my experiences with ms powershell aks posh

if you want to be a part of the future of windows administration you need to be familiar with and able 2 use posh

use the information below to setup you posh environment

first steps
How to Download Windows PowerShell 1.0

Download details Windows PowerShell 1.0 English-Language Installation Package for Windows XP (KB926139)

Download details Windows PowerShell 1.0 Installation Package for Windows Vista (KB928439)
install the appropriate package


get and install
PowerShell Community Extensions - Home
PowerShell Analyzer
PowerGUI Community Main

To get started using posh
Mastering PowerShell in your Lunch Break : Day 1: Getting Organized
Mastering PowerShell in your Lunch Break : Day 2: Writing Scripts and Translating VBScript Links for days 3-7 are on the right hand side

Windows PowerShell course book and demo files available for download

Scripting with Windows PowerShell - ms script center

learn to think in powershell

powershell 101 course on a disk if you can't go to a live don jones training it is the next best thing

additional resources
PowerGUI Hands-On Labs Manual. word doc powerGUI page on this blog PowerShell Commands for Active Directory Quest Software powershell cheat sheet PDF powershell PDF posters Microsoft Windows PowerShell 1.0 DeskSheet PDF
Windows PowerShell Tip of the Week
powerShell&Me webcasts
powershell Blogs