Compare cert salaries and plan your next career move
[/COLOR] [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=black]$payroll = get-childitem -recurse P:\ | Where-Object {$_.Name -eq “Payroll”}[/COLOR][/SIZE][/FONT] [SIZE=2][FONT=Courier New][COLOR=black]foreach($item in $payroll)[/COLOR][/FONT][/SIZE] [SIZE=2][FONT=Courier New][COLOR=black]{[/COLOR][/FONT][/SIZE] [SIZE=2][FONT=Courier New][COLOR=black]Write-Host $item.FullName[/COLOR][/FONT][/SIZE] [SIZE=2][FONT=Courier New][COLOR=black]}[/COLOR][/FONT][/SIZE][/SIZE][/FONT][/SIZE][/FONT] [COLOR=black]
RobertKaucher wrote: » It always amazes me how much you can do with just a few lines of code in PoSh.
astorrs wrote: » I'm amused by how you can turn almost anything into a single line of code. Get-ChildItem -Recurse P:\ | ? {$_.Name -eq “Payroll”} | % { Write-Host $_.FullName }
RobertKaucher wrote: » Why do I always forget ? and %? Thanks guys, like I said. i always learn something.
HeroPsycho wrote: » Don't crunch the code... (in a script)get-admin :: PowerShell PSA: Stop Crunching the CODE!
Pash wrote: » It's funny though, Microsoft branded powershell handbooks and best practice stuff always go with shorthand option.
astorrs wrote: » LOL okay so I knew someone would have to say that. I agree that if you're sharing the code in a public forum or saving it in a script, be descriptive. With that said, I'm never using -Object for the usual suspects: ForEach-Object, Where-Object, Select-Object, Sort-Object, etc. I'd argue dropping it on those actually makes the code more readable. If you're banging it in on the command line to just "get something done", sorry but I'm all for $a + $b | ? ( $_ -ne $c } | ogv Easier to fit on the line/page I'd assume.
Pash wrote: » Anyway, nice suggestion about -filter property instead of piping it into where object, or if you are gonna pipe it, select only folders. Great stuff.
Compare salaries for top cybersecurity certifications. Free download for TechExams community.