Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download PowerActions Shared Scripts
$uri = "https://github.com/alanrenouf/PowerActions/archive/master.zip"
$file = $Env:Temp + "\master.zip"
$destination = ($Env:ProgramData + "\VMware\myNGC\Scripts\")
If (! (Test-Path $destination)) {
Write-Host "Creating new folder"
New-Item $destination -type directory | Out-Null
}
Write-Host "Downloading to $file"
# Download the file
$WebClient = New-Object -TypeName System.Net.WebClient
$WebClient.DownloadFile($uri, $file)
if (Test-Path $file) {
$Date = Get-Date
$BackupFolder = $env:USERPROFILE + "\Documents\" + $Date.month + "-" + $Date.day + "-" + $Date.Year + "-" + $Date.Hour + "-" + $Date.Minute + "\"
Write-Host "Backing up the current Shared Scripts folder to $BackupFolder"
MD $BackupFolder | Out-Null
Get-ChildItem $destination -Recurse | Copy-Item -Destination $BackupFolder | Out-Null
Write-Host "Download complete, extracting to $destination"
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
$destinationfolder = $shell.NameSpace($destination)
$destinationfolder.CopyHere($zip.Items())
If (Test-Path ($destination + "\PowerActions-master\")) {
Write-Host "Moving extracted scripts to Shared Scripts at $destination"
Get-Item -path ($destination + "\PowerActions-master\*.*") | Move-Item -Destination ($Env:ProgramData + "\VMware\myNGC\Scripts\") -Force
Write-Host "Restarting PowerActions Service to register new scripts"
Restart-Service P2PSSrv
Write-Host "Tidying up"
Remove-Item -Path $file -Confirm:$false -Force | Out-Null
Remove-Item ($destination + "\PowerActions-master") -Confirm:$false -Recurse -Force | Out-Null
Write-Host "Please restart any open browsers with access to the web client to see all new and updated scripts"
} Else {
Write-Host "Extract of files failed"
}
} Else {
Write-Host "Download failed"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment