2012 May 15, 3:30
Built-in
-
map
-
input | %{ expression($_) }
-
forEach
-
input | %{ [void]expression($_) }
-
filter
-
input | ?{ expression($_) }
-
indexOf
-
input.indexOf(value)
Close to built-in
-
some
-
if (input | ?{ expression($_) }) { ... }
-
every
-
if (-not input | ?{ !expression($_) }) { ... }
-
lastIndexOf
-
[array]::lastIndexOf(input, value)
Write it yourself
-
reduce
-
function reduce($fn, $a, $init) { $s = $init; $a | %{ $s = &$fn $s $_; }; $s; }
javascript powershell array technical 2011 Oct 26, 8:04
"Knowledge is Power; France is bacon"
technical 2011 Jul 27, 10:33The write-progress command in powershell allows scripts to express their progress in terms of percent or time left and powershell displays this in a friendly manner at the top of my window.
Surprisingly, not hooked up to the Shell's TaskbarItemInfo's progress.
technical powershell progress coding shell 2011 May 28, 11:00
I wanted to ensure that my switch statement in my implementation of IInternetSecurityManager::ProcessURLAction had a case for every possible documented URLACTION. I wrote the following short
command line sequence to see the list of all URLACTIONs in the SDK header file not found in my source file:
grep URLACTION urlmon.idl | sed 's/.*\(URLACTION[a-zA-Z0-9_]*\).*/\1/g;' | sort | uniq > allURLACTIONs.txt
grep URLACTION MySecurityManager.cpp | sed 's/.*\(URLACTION[a-zA-Z0-9_]*\).*/\1/g;' | sort | uniq > myURLACTIONs.txt
comm -23 allURLACTIONs.txt myURLACTIONs.txt
I'm
not a sed expert so I had to read the
sed documentation, and I heard about
comm from Kris Kowal's blog which happilly was in the
Win32 GNU tools pack I
already run.
But in my effort to learn and use PowerShell I found the following similar command line:
diff
(more urlmon.idl | %{ if ($_ -cmatch "URLACTION[a-zA-Z0-9_]*") { $matches[0] } } | sort -uniq)
(more MySecurityManager.cpp | %{ if ($_ -cmatch "URLACTION[a-zA-Z0-9_]*") { $matches[0] } } | sort -uniq)
In
the PowerShell version I can skip the temporary files which is nice. 'diff' is mapped to 'compare-object' which seems similar to comm but with no parameters to filter out the different streams
(although this could be done more verbosely with the ?{ } filter syntax). In PowerShell uniq functionality is built into sort. The builtin -cmatch operator (c is for case sensitive) to do regexp is
nice plus the side effect of generating the $matches variable with the regexp results.
powershell tool cli technical command line 2011 May 26, 1:28This was on my todo list. I'll scratch it off knowing far more funded folks are doing this: "A startup called BlueStacks has developed an Android runtime environment for the Windows operating system.
It will enable users to run Android applications alongside conventional Windows software on Microsoft's operating system." "One example would be a convertible netbook tablet that normally runs
Windows but switches to an Android interface for greater touch-friendliness when the screen is flipped.
Such a product would offer the full power and multitasking capabilities of Windows but also benefit from having access to Android's broad touch-enabled software ecosystem."
windows programming android java technical 2011 May 26, 11:00
When you run clip.exe, whatever comes into its standard input is put onto the clipboard. So when you need to move the result of something in your command window somewhere else you can pipe the
result into clip.exe. Then you won't have to worry about the irritating way cmd.exe does block copy/pasting and you avoid having to manually fixup line breaks in wrapped lines. For instance, you
can put the contents of a script into the clipboard with:
more cdo.cmd | clip
I've got a lot of stuff dumped in my bin folder that I sync across all my PCs so I didn't realize that clip.exe is a part of standard Windows installs.
Nice for avoiding the block copy in cmd.exe but I'd prefer to have the contents sort of tee'd into the clipboard and standard output. So TeeClip.ps1:
$input | tee -var teeclipout | clip;
$teeclipout;
powershell clip tool clipboard cli technical windows tee 2011 May 22, 7:20
I'm trying to learn and use PowerShell more, but plenty of other folks I know don't use PowerShell. To allow them to use my scripts I use the following cmd.exe batch file to make it easy to call
PowerShell scripts. To use, just name the batch file name the same as the corresponding PowerShell script filename and put it in the same directory.
@echo off
if "%1"=="/?" goto help
if "%1"=="/h" goto help
if "%1"=="-?" goto help
if "%1"=="-h" goto help
%systemroot%\system32\windowspowershell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -Command . %~dpn0.ps1 %*
goto end
:help
%systemroot%\system32\windowspowershell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -Command help %~dpn0.ps1 -full
goto end
:end
Additionally for PowerShell scripts that modify the current working directory I use the following batch file:
@echo off
if "%1"=="/?" goto help
if "%1"=="/h" goto help
if "%1"=="-?" goto help
if "%1"=="-h" goto help
%systemroot%\system32\windowspowershell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -Command . %~dpn0.ps1 %*;(pwd).Path 1> %temp%\%~n0.tmp 2> nul
set /p newdir=
powershell technical programming batch file console 2011 Apr 14, 5:11This page and esp. the final comment on the page were very helpful with describing how to parse XML in PowerShell.
powershell xml xpath technical programming 2011 Jan 4, 7:25How to take ownership and re-ACL registry keys from a powershell prompt.
technical powershell acl regkey registry windows 2010 Sep 27, 3:15This is awesome and similar to something I got a cube for. Wikipedia runs its videos through a service that sets up torrents for arbitrary URLs. So awesome! Now if only this were built into the user
agent rather than requiring hardcoding the sites to use it...
technical p2p wikipedia network networking torrent web 2010 Aug 23, 10:48What if the death star briefing in Star Wars IV had Power Point?
humor powerpoint office starwars presentation communication 2010 Aug 20, 11:20
For a new project I'm working on involving IE's installed Accelerators and OpenSearch search providers via the Windows 7
Accelerator Platform, I've created a C#/COM interop class for those APIs.
Download the osinterop.cs interop file here.
technical accelerator csharp com 2010 Aug 17, 3:05
I've just got a new media center PC connected directly to my television with lots of HD space and so I'm ripping a bunch of my DVDs to the PC so I don't have to fuss with the physical media. I'm
ripping with DVD Rip, viewing the results in Windows 7's Windows Media Center after turning on the WMC DVD Library, and using a powershell script I wrote to copy over cover art and metadata.
My powershell script follows. To use it you must do the following:
- Run Windows Media Center with the DVD in the drive and view the disc's metadata info.
- Rip each DVD to its own subdirectory of a common directory.
- The name of the subdirectory to which the DVD is ripped must have the same name as the DVD name in the metadata. An exception to this are characters that aren't allowed in Windows paths (e.g.
<, >, ?, *, etc)
- Run the script and pass the path to the common directory containing the DVD rips as the first parameter.
Running WMC and viewing the DVD's metadata forces WMC to copy the metadata off the Internet and cache it locally. After playing with Fiddler and reading this
blog post on WMC metadata I made the following script that copies metadata and cover art from the WMC cache to the corresponding
DVD rip directory.
Download copydvdinfo.ps1
powershell wmc technical tv dvd windows-media-center 2010 Jun 22, 1:49"The PowerGUI Visual Studio Extension adds PowerShell IntelliSense support to Visual Studio."
technical powershell visual-studio microsoft programming shell ide 2010 May 10, 8:43Charles Stross on the intersection of ebooks and the publishing industry. Includes the answer to the misinformed question "why are you charging so much for access to the file your authors emailed
you?" Also includes this quote on Cory Doctorow "... Cory is a Special Snowflake with EFF superpowers and New York Times Bestseller mojo which make him immune to the normal laws of man and nature."
charles-stross cory-doctorow ebook drm amazon publishing kindle apple book 2010 May 6, 7:25Another subset of javascript and DOM access to make a sandbox: "FBJS is Facebook's solution for developers who want to use JavaScript in their Facebook applications. We built FBJS to empower
developers with all the functionality they need, and to protect our users' privacy at the same time."
sandbox web browser facebook html javascript technical security web-sandbox 2010 Apr 21, 6:53"Lindsey Simon has got a powerful update to BrowserScope, the community-driven tool to test and profile browsers. The new feature is exciting as it truly delivers the “community-driven” piece at
scale: you can now add your own tests to the corpus, TestSwarm style."
web browser test google browser-scope internet technical 2010 Mar 22, 8:40PDF overtakes Word as targeted attack vector of choice.
security office adobe pdf word powerpoint microsoft technical statistics internet malware 2010 Feb 22, 6:30Electric vehicles as components of the future smart electric grid, as roaming batteries providing power as necessary.
car electric-vehicle electricity power electric-grid