Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - i love powershell

Reply
 
Old 11-03-2006   #1 (permalink)
klumsy@xtra.co.nz


 
 

i love powershell



today i wanted to an audit of a bunch of machines, to see what thye had
for their autostart


$ourerrors = new-Object system.Collections.ArrayList
$machines[1..200] | % {$comp = $_.ip; $_.ip } |
% {write-Host "working on $comP";trap {Write-host "**********error with
$comp" ; $ourerrors.Add($comp);continue } ;
[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("Localmachine",$comp
).opensubkey("software\microsoft\windows\currentversion\run").GetValueNames()
|
Select-Object (as comp, {$comp}, name , {$_} , val,
{[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("Localmachine",$mach
).opensubkey("software\microsoft\windows\currentversion\run").getvalue($_)})

}



works great.. learnt the best way to use trap is embed it in the scope
i am wanting to trap..

b.t.w if you are wanting my AS function..

#region setup AS function
function new-selectexpression
{
if ($args.count -eq 1) { $theargs = $args[0] } else {$theargs= $args }
if ($theargs.count -gt 1)
{
for($loop=0;$loop -lt ($theargs.count-1);$loop+=2)
{
@{Name=$theargs[$loop];Expression=$theargs[$loop+1]}
}
}
if (!($theargs.count % 2) -eq 0)
{@{Name=$inputs[$inputs.count-1];Expression= invoke-Expression "{}" } }
}
set-Alias as new-selectexpression
#endregion


My System SpecsSystem Spec
Old 11-05-2006   #2 (permalink)
dreeschkind


 
 

RE: i love powershell

Very interesting stuff, I like the idea of your 'as' function!
But I have one thing to add, I think there is a small bug in your script:
Those $inputs at the end, aren't they supposed to be $theargs instead, is
that correct?
I changed it the way I think it was meant and also added @( ) at several
places to correctly handle the case that there is only one element in the
parameter array.
The scriptblock that will be used in case that there is an odd number of
elements is now {$_}. I think this makes sense. Tell me what you think.

##################################
function new-selectexpression
{
if ($args.count -eq 1) { $theargs = $args[0] } else {$theargs= $args }
if (@($theargs).count -gt 1)
{
for($loop=0;$loop -lt (@($theargs).count-1);$loop+=2)
{
@{Name=@($theargs)[$loop];Expression=@($theargs)[$loop+1]}
}
}
if (!(@($theargs).count % 2) -eq 0)
{
@{Name=@($theargs)[@($theargs).count-1];Expression= invoke-Expression '{$_}'
} }
}
set-Alias as new-selectexpression
##################################

--
greetings
dreeschkind

"klumsy@xtra.co.nz" wrote:

>
>
> today i wanted to an audit of a bunch of machines, to see what thye had
> for their autostart
>
>
> $ourerrors = new-Object system.Collections.ArrayList
> $machines[1..200] | % {$comp = $_.ip; $_.ip } |
> % {write-Host "working on $comP";trap {Write-host "**********error with
> $comp" ; $ourerrors.Add($comp);continue } ;
> [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("Localmachine",$comp
> ).opensubkey("software\microsoft\windows\currentversion\run").GetValueNames()
> |
> Select-Object (as comp, {$comp}, name , {$_} , val,
> {[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("Localmachine",$mach
> ).opensubkey("software\microsoft\windows\currentversion\run").getvalue($_)})
>
> }
>
>
>
> works great.. learnt the best way to use trap is embed it in the scope
> i am wanting to trap..
>
> b.t.w if you are wanting my AS function..
>
> #region setup AS function
> function new-selectexpression
> {
> if ($args.count -eq 1) { $theargs = $args[0] } else {$theargs= $args }
> if ($theargs.count -gt 1)
> {
> for($loop=0;$loop -lt ($theargs.count-1);$loop+=2)
> {
> @{Name=$theargs[$loop];Expression=$theargs[$loop+1]}
> }
> }
> if (!($theargs.count % 2) -eq 0)
> {@{Name=$inputs[$inputs.count-1];Expression= invoke-Expression "{}" } }
> }
> set-Alias as new-selectexpression
> #endregion
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
love Vista mail
For the love of god please help me Vista music pictures video
For the love of God.. Help me! Vista General
For the love of God please help! Vista mail
RE: Well....I LOVE IT Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46