How Do You Download Big Files with PowerShell?

Problem scenario
You want to download a very large file using PowerShell (from a file share on your network or URL on the Internet).  But the file is larger than the available RAM on your server.  How do you download a large file using Powershell?

Solution
Invoke-restmethod, Invoke-webrequest, curl and wget (even with the redirect “” command) all put the file being downloaded into memory. 

How do I get a forward slash (“/”) to be passed from a Puppet manifest on a Linux server with Puppet Master to a Windows server with Puppet Agent?

Question:  How do I get a forward slash (“/”) to be passed from a Puppet manifest on a Linux server with Puppet Master to a Windows Server with Puppet Agent?

Answer # 1 (for creating Scheduled Tasks with Puppet manifests): For a Scheduled Task, the forward slash may be crucial.  A forward slash (that Puppet between Linux and Windows will automatically substitute for a back slash) with a shutdown.exe server is the only way for a reboot to work properly with a Scheduled Task. 

How to Troubleshoot PowerShell Downloading a File From the Internet

Problem scenario:  When trying to use PowerShell to download a file, get you this error ‘Error calling “DownloadFile” with “2” argument(s): “An Exception occurred during a WebClient request.”‘

Solution:  Make sure you have ample space on the disk and make sure the destination folder exists.  A typo in the path or if the folder not existing could cause this error.  Insufficient disk space could also cause the problem. 

How Can Jenkins Invoke PsExec?

Problem scenario:  When using Jenkins, PsExec never seems to work when called as a batch command in a .bat file or PowerShell script.  Jenkins logs an error about the PsExec command not being found.

Solution / workaround:  PsExec seems to never work if called by a PowerShell script or a batch script via Jenkins.  The only exception seems to be if a Scheduled Task calls a .bat file or PowerShell script that uses PsExec. 

How To Install PsExec on Windows Server

Not all directions are clear.  Here is an example where Microsoft has less than perfect directions:

“Installation

Just copy PsExec onto your executable path. Typing “psexec” displays its usage syntax.”

First off, psexec won’t display usage syntax until after the installation. If you are like me you are asking what is the executable path?

The answer can be found by opening PowerShell and typing this:

Get-ChildItem Env:Path | ft -wrap -AutoSize

Any of those semi-colon delimited results can be the destination of the files inside the PsTools.zip file. 

Unexpected PowerShell Closures and Controlling the Flow of PowerShell Scripts

Problem scenario:  You PowerShell or PowerCLI window keeps exiting automatically when you run a script.  You find that RAM and CPU are not constrained.  
Root cause: Human error.
Solution:  Look for the “exit” or the “Exit-Pssession” commands.  These can close PowerShell’s ISE or PowerCLI.  You may need to eliminate these commands or use a different keyword.

———————————————————————————————————————————————————————–
Problem scenario: 

How to Create .EXE Files With PowerShell

Problem Scenario 
You want to package a standalone .ps1 script as an .exe file.  How do you create an executable file that does what a PowerShell script does?

Solution 
Install PowerShell Community Extensions.  Then download this .ps1 file and use it according to the conventions in the comments, near the top, of the script itself,

The usage instructions are in the code. 

How To Install PowerShell Community Extensions

Problem Scenario:  You want the rich features provided by PowerShell Community Extensions (also known as PSCX).

Solution:
1.  Download the .msi from this link
2,  Double click it. 
3.  Install it by accepting the License Agreement and the defaults. 
4.  Open PowerShell as Administrator. 
5. In PowerShell, Change directories to where it was installed (e.g., C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx). 

Windows Server 2012 Scheduled Tasks Are Not Launching PowerShell Scripts Properly

Problem scenario:  For no apparent reason, Scheduled Tasks are not kicking off PowerShell scripts.  You have configured Scheduled Tasks to launch .ps1 files.The task calls “%windir%\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe” (in the Action tab’s “Program/Script” field) with an argument like this C:\Program Files\good script.ps”

You manually run the scheduled task (by right clicking its name and choosing Run) and the Scheduled Task will seem to run.  In reality, the .ps1 file will not execute (despite having the correct Execution Policy). 

PowerShell Can Throw a SetInfo With 0 Argument(s) Error When Creating a User

Problem scenario
You run a PowerShell script that has a command setinfo.  For example, the script is like this:

        #…
        $userName = ‘jdoe’
        $compName = $env:COMPUTERNAME
        $cona = [ADSI]”WinNT://$compName”
        $user = $cona.Create(‘User’,$userName)
        $user.SetInfo()

You get “Exception calling “SetInfo” with “0” argument(s): “The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements.”

You may go to Administrative Tools ->