top of page

Keep in mind when you're drafting a PowerShell script that if any of the filepaths referenced in it contain beginning or ending brackets, the script will fail. So if we set up a simple copy-item script like this in Excel:

ree

. . . which copies files from one location to a new one, renamed with a new filename, but the filepaths include a bracketed word, the script will fail without giving an error message that something is wrong.


ree

The files in the first location are simply not copied to the new folder at all, and no error message flags the problem in the PowerShell blue console at the bottom.


We can get around this problem by adding a backtick ` in front of each beginning and ending bracket in the script. (Be sure to use a backtick and not an apostrophe.) You can enter a backtick by pressing ALT + 096. If your filepath is listed in double quotes, use two backticks in front of each bracket; if the path is enclosed in single quotes use just one backtick.



ree

So the updated script will look like this:

copy-item -Path "C:\foofolder\test\powershell\Exhibit 001.pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit A.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 002 ``[redacted``].pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit B.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 003.pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit C.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 004 ``[redacted``].pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit D.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 005.pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit E.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 006 ``[redacted``].pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit F.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 007.pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit G.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 008 ``[redacted``].pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit H.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 009.pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit I.pdf"

copy-item -Path "C:\foofolder\test\powershell\Exhibit 010 ``[redacted``].pdf" -Destination "C:\foofolder\test\powershell\Exhs A to Z\Exhibit J.pdf"


. . . and give you the result you wanted:


ree

 
 

This night's post shows how you can use a PowerShell script to save each page of an online book as a PDF.


The process involves using an add-in for Chrome called Screenshot Capture.   See: https://chromewebstore.google.com/detail/screenshot-capture/giabbpobpebjfegnpcclkocepcgockkc

 

When this is installed, when you press ALT + S it will automatically save a .png file of the open page to a specified location.  Use these settings, with the option for ‘Capture Viewport’.

  

ree

  

ree

This is the script:

 

Add-Type -AssemblyName System.Windows.Forms

 

$pathToChrome = 'C:\Program Files\Google\Chrome\Application\chrome.exe'

$tempFolder = '--user-data-dir=c:\temp' # pick a temp folder for user data

$startmode = '--start-fullscreen' # '--kiosk' is another option

 

Start-Process -FilePath $pathToChrome -ArgumentList $tempFolder, $startmode, $startPage

 

Start-Sleep -Seconds 5 # Wait for the browser to load

 

for ($i = 0; $i -lt 10; $i++) {

 

    # Press Alt+S

    [System.Windows.Forms.SendKeys]::SendWait('%s')

    Start-Sleep -Milliseconds 5000 # Small delay between key presses

   

    # Press Page Down

    [System.Windows.Forms.SendKeys]::SendWait('{PGDN}')

    Start-Sleep -Milliseconds 5000 # Small delay between key presses

    }

 

 

 Be sure to confirm that the path on the second line is where you have Chrome installed on your PC.


Enter the url of the web page on the line beginning, ‘$startPage’

 

Indicate the number of pages you need to grab here [in this example it’s 10 pages]

 for ($i = 0; $i -lt 10; $i++) {

 

The PowerShell script in effect presses ‘ALT + S’ and then the page down key for you.

 

It’s possible that the script can get thrown off if a page takes a long time to load, so the last part of the script pauses for a set amount of milliseconds.   So 5000 equals 5 seconds.


In Chrome, be sure to enter full screen mode by pressing F11.

 

Just enter the script in the white pane at the top, and then press the play button.


ree

After the script ends and the .png files are generated, you can easily convert them to a single PDF in Adobe Acrobat.


 
 

You can use a simple PowerShell script to extract the contents of multiple zip files. The command Expand-Archive followed by a file path to a zip file, will extract the contents to a location specified in the script.


Create a text file with each line beginning with Expand-Archive -LiteralPath '


. . . followed by the file paths, followed by  -DestinationPath 

. . . followed by the location that you want the files to be extracted to:


Expand-Archive -LiteralPath "C:\foofolder\Test.zip" -DestinationPath "C:\foofolder\extracthere"

Expand-Archive -LiteralPath "C:\foofolder\Litigation Support.7z" -DestinationPath "C:\foofolder\extracthere"


Open Windows PowerShell ISE (x86), and paste this script into the script pane.


ree

Note that this method will not work for 7zip files.


ree

I tested this tonight and successfully extracted more than 50,000 files from almost 50 zip files.



 
 

Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page