Skip to content

Instantly share code, notes, and snippets.

@kyle-herzog
Created October 19, 2012 19:49
Show Gist options
  • Save kyle-herzog/3920297 to your computer and use it in GitHub Desktop.
Save kyle-herzog/3920297 to your computer and use it in GitHub Desktop.
Common Powershell Functions
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)
}
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)
}
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