![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||