Posts RSS Comments RSS 117 Posts and 170 Comments till now

Archive for July, 2007

How would you do it (AD Convergance?)

I think its great how you can do so many things so differently in Powershell. So here is the Challenge.

Goal is to check Active Directory replication convergance?

Conditions:
1) No third Party tools/snapins (only whats there by defualt)
2) No Creating Objects in AD
3) Must work in Large Environments
4) It needs to be fast.

Optional:
1) Return the Up To Dateness Vector Table
2) Have a monitor mode where it loops
3) Power Gadget Snap-in for RESULTS ONLY!

UPDATE:
IMO the only way to do this is to get this information is the to get the
HighestOrginatingUSN for a server and then check the UTD Vector on each
server to see if it is greater than the HighestOrginatingUSN. The only
problem with this approach is time… when done serially… this takes
awhile which makes it useable in large environments. I am investigating
runspaces to achieve this.

Get-ChildItem with Pretty Colors (UPDATED)

Cedric Posted a message on the NG (news group) wanting a function like ls for linux. He wanted color while keeping width. I am sure there are other ways to do this, but what I did was created a script (I will convert to a function later) called Get-ChildItemPretty.ps1. The code is at the bottom, but I wanted to point out a few things.

1) It has 3 Parameters and 1 switch
- Dir: This is the Path you want to List (Defaults to $pwd)
- Wide : How Many Colums Wide (Defaults to 3)
- Pad : For Spacing on the Names (Defaults to 30)
- Recurse : Switch to Recurse
- Passtru : outputs objects
2) By default this colors Folders Blue and Exe’s Red, but you could add what ever colors and extentions you want.
3) I have thought about adding a Sort option to Sort by Name or by Type (what do you think?)
4) You could add -full switch that would return fullname instead of just name.
5) You could add -output switch that would return objects as well for pipeline parsing.

### UPDATED ###
Working with /\/\0\/\/ (mostly MOW really) we came up with a better way using $host.UI
This adds a PassTru to output objects

  1. # Colored wide directory list function
  2. #
  3. # /\/\o\/\/ 2007
  4. # www.thePowerShellGuy.com
  5. function List-Wide { param ($dir=$pwd,$Column=3,[Switch]$PassTru,[Switch]$recurse)
  6.     $origFg = $host.ui.rawui.foregroundColor
  7.     if($recurse)
  8.     {
  9.         $list = get-ChildItem $dir -recurse
  10.     }
  11.     else
  12.     {
  13.         $list = get-ChildItem $dir
  14.     }
  15.     foreach ($Item in $list)
  16.     {
  17.         Switch ($Item.Extension)
  18.         {
  19.             ".Exe" {$foregroundColor = "Yellow"}
  20.             ".cmd" {$foregroundColor = "Green"}
  21.             ".ps1" {$foregroundColor = "Red"}
  22.             ".vbs" {$foregroundColor = "Red"}
  23.             Default {$foregroundColor = $origFg}
  24.         }
  25.         if ($item.PSISContainer) {$foregroundColor = "Blue"}
  26.         $max = \[int\]($Host.UI.RawUI.WindowSize.Width / $Column)
  27.         $field = ($item.name.padRight($max).Substring(0,($Max -1)) + ‘ ‘)
  28.         if ($item.name.length -gt $max -1)
  29.         {
  30.             $field = $field.Substring(0,($Max -3)) + ‘\*\*\*’
  31.         }
  32.         if ($Host.UI.RawUI.WindowSize.Width - $host.UI.RawUI.CursorPosition.X -lt $max)
  33.         {
  34.             $host.ui.WriteLine()
  35.         }
  36.         $Host.UI.Write($foregroundColor,$host.ui.rawui.BackgroundColor,$field)
  37.         if ($PassTru)
  38.         {
  39.             $Item
  40.         }
  41.     }
  42.     $Host.UI.WriteLine()
  43. }

Old Version

						tshell :: Jul.10.2007 :: 
						Powershell,  functions  :: 
						No Comments »