-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@echo off | ||
rem Create PowerShell Folder | ||
if exist .\PowerShell\ ( | ||
echo PowerShell Folder Already exists | ||
) else ( | ||
echo Creating PowerShell Folder | ||
mkdir .\PowerShell | ||
) | ||
rem Download PowerShell from https://github.com/PowerShell/PowerShell/releases/latest | ||
if exist .\PowerShell.zip ( | ||
echo PowerShell.zip found, skipping download | ||
) else ( | ||
echo PowerShell.zip not found, downloading PowerShell.zip | ||
rem Get the bit type of the processor | ||
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT | ||
rem Download the 32bit version or 64bit version of PowerShell | ||
if %OS%==32BIT c:\Windows\System32\windowspowershell\v1.0\powershell.exe -Command "& { $uri = $((Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/PowerShell/PowerShell/releases/latest').Links.href | Where-Object { $_ -like '*releases*win-x86.zip' }); Invoke-WebRequest -Uri $('https://github.com'+$uri) -OutFile '.\PowerShell.zip' }" | ||
if %OS%==64BIT c:\Windows\System32\windowspowershell\v1.0\powershell.exe -Command "& { $uri = $((Invoke-WebRequest -UseBasicParsing -Uri 'https://github.com/PowerShell/PowerShell/releases/latest').Links.href | Where-Object { $_ -like '*releases*win-x64.zip' }); Invoke-WebRequest -Uri $('https://github.com'+$uri) -OutFile '.\PowerShell.zip' }" | ||
) | ||
rem Extract the Downloaded Powershell Zip | ||
if exist .\PowerShell\pwsh.exe ( | ||
echo PowerShell already extracted | ||
) else ( | ||
echo Extracting contents of PowerShell.zip to .\PowerShell\ | ||
c:\Windows\System32\windowspowershell\v1.0\powershell.exe -Command "& { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('.\PowerShell.zip', '.\PowerShell') }" | ||
echo Done extracting PowerShell.zip to .\PowerShell\ | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#Requires -Version 7 | ||
Write-Output $PSVersionTable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
echo ==== Running Example.ps1 With pwsh.exe found under .\PowerShell\ ==== | ||
.\PowerShell\pwsh.exe -WorkingDirectory .\ -NoExit -NoProfile -NoLogo -File .\Example.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# PowerShell Standalone Example | ||
|
||
## Requirements | ||
|
||
* PowerShell 2.0 or greater | ||
* Server 2008 or greater | ||
* A little bit of Batch and PowerShell knowledge to get a PowerShell script to run | ||
|
||
## Run a PowerShell script with PowerShell 7 with out installing PowerShell 7 | ||
|
||
1. Copy the files in this repository into a folder | ||
2. Navigate to that folder | ||
3. Double click on `DownloadPowerShell.bat` | ||
4. Wait for PowerShell to download and extract into the `PowerShell\` folder | ||
5. Double click on `RunExample.bat` | ||
6. You should see the output of `$PSVersionTable` | ||
|
||
## How to use in production | ||
|
||
1. Do the steps above from 1 to 4 | ||
2. Edit and Rename `RunExample.bat` and `Example.ps1` as needed | ||
3. Delete `PowerShell.zip` and `DownloadPowerShell.bat` | ||
4. Zip your `bat`, `ps1`, and the `PowerShell` files and folders | ||
5. Move you zip file to production | ||
6. Extract and run you `bat` file |