Created
October 19, 2012 19:49
-
-
Save kyle-herzog/3920297 to your computer and use it in GitHub Desktop.
Common Powershell Functions
This file contains hidden or 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
function Expand-Item | |
{ | |
param | |
( | |
[Parameter(Mandatory=$true)] [string] $zipFile, | |
[Parameter(Mandatory=$true)] [string] $destinationDirectory | |
) | |
if (!(Test-Path -Path $zipFile -PathType Leaf)) | |
{ | |
throw ("Specified zipFile is invalid: " + $zipFile) | |
} | |
if (!(Test-Path -Path $destinationDirectory -PathType Container)) | |
{ | |
New-Item $destinationDirectory -ItemType Directory | Out-Null | |
} | |
$shell_app = new-object -com shell.application | |
$zip_file = $shell_app.namespace($zipFile) | |
$destination = $shell_app.namespace($destinationDirectory) | |
$destination.Copyhere($zip_file.items(), 0x14) | |
} |
This file contains hidden or 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
function Get-DownloadFile | |
{ | |
param | |
( | |
[Parameter(Mandatory=$true)] [string] $url, | |
[Parameter(Mandatory=$true)] [string] $localPath | |
) | |
$localDirectory = Split-Path $localPath | |
if(!(Test-Path $localDirectory)) | |
{ | |
New-Item $localDirectory -Type Directory | Out-Null | |
} | |
$webClient = New-Object System.Net.WebClient | |
$webClient.DownloadFile($url, $localPath) | |
} |
This file contains hidden or 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
function Test-ElevatedShell | |
{ | |
$user = [Security.Principal.WindowsIdentity]::GetCurrent() | |
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment