Skip to content

Instantly share code, notes, and snippets.

@alanrenouf
Last active August 7, 2019 15:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alanrenouf/3f262b6c787ee26f7381 to your computer and use it in GitHub Desktop.
Save alanrenouf/3f262b6c787ee26f7381 to your computer and use it in GitHub Desktop.
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