Re: [PoSh] Collecting oneliners/scripts to wow others

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



a one-liner I also like :

a GUI directory copy :

(new-object -com Shell.application).NameSpace((new-object -com Shell.application).browseforFolder(0, "Select Target", 0, 0x11)).CopyHere((new-object -com Shell.application).browseforFolder(0,"Select Source", 0, 0x11))

gr /\/\o\/\/

Keith Hill [MVP] wrote:
"dreeschkind" <dreeschkind@xxxxxxxxxxxxxxxxxxxxxxxxx <mailto:dreeschkind@xxxxxxxxxxxxxxxxxxxxxxxxx>> wrote in message news:0D3A3FD9-E891-4425-BA89-1CFC8A75DF44@xxxxxxxxxxxxxxxx
> Hi all,
>
> Monad/MSH/PowerShell is my default shell for several month now and everytime
> someone looks over my shoulder, he/she asks me what the hell I'm doing with
> that 'stupid old dos prompt'. So I have to explain the whole thing over and
> over again.
>
> For this purpose I'm looking for impressive oneliners and great scripts to
> demonstrate the vastly superior power and manifold possibilities and to
> explain the key concept in very short time. I know there are some examples in
> the documentationpack for comparison with unix shells, but these didn't
> really worked for me. My own functions are mainly experimental and often are
> not that usefull at all because I'm still exploring the full power of
> PowerShell.
>
> So if you have really cool and nifty functions/skripts in your profile etc.
> that you are using for this particular purpose or that you are using
> frequently or that you are really proud of, please post them here!
Here's some from my blog (and from daily use):
If you are thinking about adding more RAM and can't remember how your current memory occupies banks:
PoSH> get-WMIObject Win32_PhysicalMemory |
>> select DeviceLocator, Capacity, Speed | sort DeviceLocator | ft -auto
>>
DeviceLocator Capacity Speed
------------- -------- -----
CHANNEL A DIMM 0 536870912 400
CHANNEL A DIMM 1 536870912 400
CHANNEL B DIMM 0 1073741824 400
For developers:
# Show me all the versions of the MS CRT loaded and what processes
# are using them.
PoSH> get-process | select processname -expand Modules -ea SilentlyContinue |
>> where {$_.ModuleName -like "msvc*.dll"} |
>> group {$_.ModuleName} | format-list
Name : MSVCP71.dll
Count : 12
Group : {CCAPP, CCEVTMGR, CCSETMGR, EDICT, iexplore, msimn, msn, NAVAPSVC,
NPFMNTOR, SPBBCSvc, WeatherDataClient, WINWORD}
Values : {MSVCP71.dll}
<snip>
Stats on your music collection:
PoSH> gci "$home\my documents\my music" -rec |
>> where {!$_.PSIsContainer -and $_.Extension -match "wma|mp3"} |
>> Measure-Object -property length -sum -min -max -ave
>>

Count : 1018
Average : 2991362.43123772
Sum : 3045206955
Max : 102750941
Min : 89025
Property : Length
And two simple ones that I like:
PoSH> gci | group extension | sort count
PoSH> gci | sort extension | ft -groupby extension
And to see when during the day you use the shell the most:
get-history -count $MaximumHistoryCount |
group {$_.StartExecutionTime.Hour} |
sort Count -desc |
format-table Count,@{l="Hour";e={$_.Name}},Group -auto
Here's one I used recently after I recovered files onto a new hard drive. It tells you which files have changed within a certain period of time.
$startDate = (get-date).AddDays(-3) # Get date for 3 days previous to today
gci . -rec | where {$_.LastWriteTime -gt $startDate}
Finally, dumping system event log errors:
get-eventlog system | where {$_.EntryType -eq "Error"} | fl
--
Keith
.



Relevant Pages

  • Re: open statement, pathname and file extension
    ... EOFalso refers to that channel, which is why EOF fails when k is greater ... App.Dir tells you the application folder. ... You can't use Open to work out the filename extension for you. ... The code requires to declare the complete file pathname so that the ...
    (microsoft.public.vb.syntax)
  • Re: BIOS has detected a non-optimal memory configuration.
    ... "Bruce Chambers" wrote: ... Changing the existing DIMM ... Channel A DIMM 0 should ... Im not a big cpu person who knows all these ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: sort by file extension
    ... microsoft.public.windowsxp.basics, Patricia Shannon ... I want to be able to sort by file extension. ... In Windows Explorer, I have .log files that show the "Type" to be ... So when I sort by "Type", it sorts the .log and .txt files together. ...
    (microsoft.public.windowsxp.basics)
  • Re: Howto conjoin information from two hash tables?
    ... Extract the file number from your data and sort by that in your ... Extract the file number on the fly, ... Files for channel 'ch1': ... Channel type Number Name ...
    (comp.lang.perl.misc)
  • Re: BIOS has detected a non-optimal memory configuration.
    ... non-optimal memory configuration Dual Channel operation requires identical paired DIMMS installed in both memory channels. ... Changing the existing DIMM config. ...
    (microsoft.public.windowsxp.help_and_support)