![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #11 (permalink) |
| | Re: Pecursive Delete Implementation in PowerShell The 'speed' part of my suggestion doesn't have to do with less typing, is just that by filtering through Get-ChildItem's -filter less objects are passed down the pipeline to Where-Object, therefore, enhancing performance The aliases used in my suggestion are standard, and the brief name for the parameters is a PowerShell feature sometimes referred as "parameter disambiguation", that later you might find very useful. See my reply to lrbell for more on that. Besides you can always ask for clarification, lots of smart --myself NOT included-- and helpful people here that can help out. -- Kiron |
My System Specs![]() |
| | #12 (permalink) |
| | Re: Pecursive Delete Implementation in PowerShell I wrote a function that calculates the minimum paramater length you can type something like: PS C:\Scripts>get-params select-string ----------------- - Select-String - ----------------- name alias position ---- ----- -------- caseSensitive -c named exclude -e named include -inc named inputObject -inp named list -l named path -path 2 pattern -patt 1 quiet -q named simpleMatch -s named text -t 2 You can find it here: http://scriptolog.blogspot.com/2007/...parameter.html Shay http://scriptolog.blogspot.com > You can find out more on aliases by typing: > help about_alias > PowerShell is indeed a great shell/language. One of its features is > that all Cmdlets' parameters can be named by their first characters > --instead of the full name-- as long as they disambiguate, or clearly > identify, the parameter with the least amount of characters. > > There are also aliases for half of the ubiquitous parameters, better > known as 'common' parameters. > > Ubiquitous parameter, Alias > --------------------------- > Confirm > Debug > ErrorAction, ea > ErrorVariable, ev > OutBuffer, ob > OutVariable, ov > Verbose > WhatIf > This function will get a sorted list of the regular and common > parameters of a standard Cmdlet. With this list you can see which > parameters can be named with just their first character, or if you > need to type its second and third to clearly identify them. There is > at least one other alias I'm aware of, for New-Item's -itemType > regular parameter you can use -type; there may be more. > > function Get-ParameterList > ([string]$cmdlet = $(throw "Specify a PowerShell Cmdlet")) > { > if (@(powershell -noProfile {get-command -type Cmdlet | % > {$_.Name}}) -contains $cmdlet) > { > ((get-command $cmdlet).definition).split() -match '\[-[a-z]+' > -replace > '\[*-|\]' | sort -unique > } > else {"$cmdlet is not a standard Cmdlet"} > } > set-alias gpl Get-ParameterList > > # list all parameters, regular and common > # note the use of the just created alias > gpl Get-ChildItem > Debug > ErrorAction > ErrorVariable > Exclude > Filter > Force > Include > LiteralPath > Name > OutBuffer > OutVariable > Path > Recurse > Verbose > According to the this list, and the implementation of common > parameters' > aliases, for Get-ChildItem you can use: > -Debug or -d > -ErrorAction or -ea > -ErrorVariable or -ev > -Exclude or -ex > -Filter or -fi > -Force or -fo > -Include or -i > -LiteralPath or -l > -Name or -n > -OutBuffer or -ob > -OutVariable or -ov > -Path or -p > -Recurse or -r > -Verbose or -v > --- > Kiron |
My System Specs![]() |
| | #13 (permalink) |
| | Re: Pecursive Delete Implementation in PowerShell Thanks Shay, the parameter 'short' name generator is great. Get-Help is a good source of information on each parameter, be aware that some commonly used Cmdlets' help contents are missing parameters. This script gets Set-Content's, Add-Content's and Get-Content's parameters found through Get-Command and Get-Help, then compares the lists to see which parameters, if any, are missing from either list: I commented other $cmdlets assignments in case anyone is interested in looking at other parameter discrepancies or comparing all standard Cmdlets. <Get-MissingParameters.ps1> $ubiq = 'Debug|ErrorAction|ErrorVariable|OutBuffer|OutVariable|Verbose' # parameters missing in Get-Help $cmdlets = 'Set-Content', 'Add-Content', 'Get-Content' # parameters missing in Get-Command's Definition # $cmdlets = 'Set-TraceSource', 'Trace-Command' # parameters listed in Get-Help but are not functional # $cmdlets = 'Get-ChildItem', 'Select-String' # compare all standard Cmdlets # $cmdlets = (powershell -noProfile {get-command -type Cmdlet | % {$_.Name}}) foreach ($cmdlet in $cmdlets) { $thruGetCommand = ((gcm $cmdlet).definition).split() -match '\[-[a-z]+|^\-[a-z]+' -replace '\[*-|\]' -notMatch $ubiq | sort -unique $thruGetHelp = get-help $cmdlet -parameter * 2>$null| % {$_.name} | sort if ($thruGetHelp -ne $null) { if ($thruGetCommand.length -ne $thruGetHelp.length) { "Differences found in $cmdlet's parameters:" compare-object $thruGetCommand $thruGetHelp | ft -hide -auto } } } <Get-MissingParameters.ps1> PowerShell's scalar/array treatment --as in your CSV post-- seems to be the reason why your function doesn't support Cmdlets that have one or zero regular parameter, but all support common parameters. Get-Command's Definition property will list all functional parameters, except the -Debugger for Set-TraceSource and Trace-Command. Thanks also for updating the common parameters' aliases. Debug, db Verbose, vb -- Kiron |
My System Specs![]() |
| | #14 (permalink) |
| | Re: Pecursive Delete Implementation in PowerShell Thanks, kiron. Cool stuff! Cheers all PowerShell enthusiasts. Shay http://scriptolog.blogspot.com > Thanks Shay, the parameter 'short' name generator is great. > Get-Help is a good source of information on each parameter, be aware > that > some commonly used Cmdlets' help contents are missing parameters. > This script gets Set-Content's, Add-Content's and Get-Content's > parameters > found through Get-Command and Get-Help, then compares the lists to see > which > parameters, if any, are missing from either list: > I commented other $cmdlets assignments in case anyone is interested in > looking at other parameter discrepancies or comparing all standard > Cmdlets. > <Get-MissingParameters.ps1> > $ubiq = > 'Debug|ErrorAction|ErrorVariable|OutBuffer|OutVariable|Verbose' > # parameters missing in Get-Help > $cmdlets = 'Set-Content', 'Add-Content', 'Get-Content' > # parameters missing in Get-Command's Definition > # $cmdlets = 'Set-TraceSource', 'Trace-Command' > # parameters listed in Get-Help but are not functional # $cmdlets = > 'Get-ChildItem', 'Select-String' > > # compare all standard Cmdlets > # $cmdlets = (powershell -noProfile {get-command -type Cmdlet | % > {$_.Name}}) > foreach ($cmdlet in $cmdlets) > { > $thruGetCommand = ((gcm $cmdlet).definition).split() -match > '\[-[a-z]+|^\-[a-z]+' -replace '\[*-|\]' -notMatch $ubiq | sort > -unique > $thruGetHelp = get-help $cmdlet -parameter * 2>$null| % {$_.name} | > sort > if ($thruGetHelp -ne $null) > { > if ($thruGetCommand.length -ne $thruGetHelp.length) > { > "Differences found in $cmdlet's parameters:" > compare-object $thruGetCommand $thruGetHelp | ft -hide -auto > } > } > } > <Get-MissingParameters.ps1> > > PowerShell's scalar/array treatment --as in your CSV post-- seems to > be the reason why your function doesn't support Cmdlets that have one > or zero regular parameter, but all support common parameters. > Get-Command's Definition property will list all functional parameters, > except the -Debugger for Set-TraceSource and Trace-Command. > > Thanks also for updating the common parameters' aliases. > > Debug, db > Verbose, vb > -- > Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Looking to delete last 3 lines with powershell | PowerShell | |||
| Delete Files using powershell | PowerShell | |||
| How do I delete an OU in Active Directory from Powershell. | PowerShell | |||
| How to delete a DFS node using Powershell | PowerShell | |||
| delete temp dlls via powershell | PowerShell | |||