The GoTo Community is currently experiencing some technical issues affecting new posts and comments. We are actively working with our service provider and apologize for the frustration.
Forum Discussion
CS_HelpDesk
3 years agoGoTo Contributor
Remote Execution - PowerShell Script Repository
Welcome to the Remote Execution - Powershell Script Repository!
What is it? A library of scripts to help you execute automated tasks and manage your Central computers without having to access them manually.
How does it work? Simply browse the replies below, copy and paste to the Remote Execution job screen in your Central console.
How can you help? We encourage you to share your own scripts and/or help review the scripts of others-- just "Kudo" your favorites or reply with your comments.
Use of these scripts is at your own risk so please test them on a small number of systems before deploying at scale. The scripts are provided “as is” without any warranty of any kind and GoTo , Inc disclaims any and all liability regarding any use of the scripts. Please see the following Terms and Conditions for more information.
Remember: The currently running Remote Execution script ends when either the host service stops or the script includes computer shutdown or reboot tasks.
- Shutdown Script
- Executable file run script
- File Distribution script
- File Copy
- File Move
- File Delete
- Folder Creation
- Folder Copy
- Folder Move
- Folder Delete
- Compress to zip
- Extract from Zip
- Display a message box
- MSI installation
- MSI Uninstall
- Winget Install
- Microsoft Defender- Quick Scan
- Microsoft Defender - Full Scan
- Microsoft Defender - Custom Scan
- Microsoft Defender update
- Service - Start
- Service - Stop
- Service - Restart
- Registry Import
- Clear DNS cache
27 Replies
- CS_HelpDesk3 years agoGoTo Contributor
Install application from the web by the application's ID and version.
Without specifying the version, winget installs the latest version of the application.
You can find the ID of the app via the 'winget search' command.
---
$appId = $null$version = $null
$PlatformString = if([Environment]::Is64BitOperatingSystem){"x64"} else{"x86"}
function IsVistualMachine{try{if((Get-CimInstance win32_computersystem).model -like "*virtual*"){return $true}}catch{}$false}
function Get-RegUninstallKey{param ([string]$DisplayName)
$ErrorActionPreference = 'Continue'$uninstallKeys = @("registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall")if($PlatformString -eq "x64"){$uninstallKeys += "registry::HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"}$softwareTable = @()foreach ($key in $uninstallKeys){$softwareTable += Get-Childitem $key | Get-ItemProperty | where displayname | Sort-Object -Property displayname}if ($DisplayName){$softwareTable | where displayname -Like "*$DisplayName*"}else{$softwareTable | Sort-Object -Property displayname -Unique}}
function IsVisualCppRedistrubutable2019OrLaterInstalled{$keys = Get-RegUninstallKey -DisplayName "Microsoft Visual C++ * Redistributable ($PlatformString)"foreach ($key in $keys){if([System.Version]$key.BundleVersion -ge [System.Version]"14.29.0.0"){return $true} # version 2015-2019}$false}
function Install-VisualC {$WebClient = New-Object System.Net.WebClient$WebClient.DownloadFile($url, "$env:Temp\vc_redist.exe")$WebClient.Dispose()start-process "$env:temp\vc_redist.exe" -argumentlist "/q /norestart" -Wait}
# If Visual C++ Redist. not installed, install itif ((IsVistualMachine) -and -not (IsVisualCppRedistrubutable2019OrLaterInstalled)){Write-Host -message "Suitable version of Visual C++ not found. Attempting to install"try {Install-VisualC}Catch [System.InvalidOperationException]{Write-Host -message "Error installing Visual C++ redistributable. Attempting install once more"Start-Sleep -Seconds 5Install-VisualC}Catch {Write-Host -message "Failed to install Visual C++ redistributable!"Write-Host -message $_exit 1}if (-not (IsVisualCppRedistrubutable2019OrLaterInstalled)){Write-Host -message "Suitable version of Visual C++ Redistributable not found!" ; exit 1}else {Write-Host -message "Successfully installed Microsoft Visual C++ Redistributable ($PlatformString)"}}
function GetWingetPath{$WingetPath = (Get-ChildItem "$env:programfiles\WindowsApps" -Recurse -File| where { $_.name -like "AppInstallerCLI.exe" -or $_.name -like "Winget.exe" }| select -ExpandProperty fullname| Sort-Object -Property @{Expression={[Version][RegEx]::Match($_, "_(\d+.\d+.\d+.\d+)_").Groups[1].Value}; Descending=$true})if ($WingetPath.count -gt 1) { $WingetPath = $WingetPath[0] }$WingetPath}
$winget = GetWingetPath
if($null -eq $winget){Write-Host "Winget not found!"exit 1}
if($version){&$winget install --id $appId -v $version --accept-package-agreements --accept-source-agreements --silent}else{&$winget install --id $appId --accept-package-agreements --accept-source-agreements --silent} - CS_HelpDesk3 years agoGoTo Contributor
Upload the .msi file for the app you want to uninstall. It will be run silently in the background.
---
$customArguments = $null
$msiPath = $resolve_Files[0];
$arguments = @();$arguments += "/uninstall";$arguments += '"' + $msiPath + '"';$arguments += "/quiet";
if ($noRestart){$arguments += "/norestart";}
$logFileId = New-Guid;$logFilePath = "$logFileId.log";$arguments += "/l*";$arguments += '"' + $logFilePath + '"';
if ($customArguments){$arguments += $customArguments;}
$msiExec = "msiexec.exe";$process = Start-Process $msiExec -ArgumentList $arguments -Wait -NoNewWindow -PassThru;
if (Test-Path $logFilePath){Get-Content -Path $logFilePath;}
Exit $process.ExitCode; - CS_HelpDesk3 years agoGoTo Contributor
Upload an .msi file that will be run silently in the background.
---
$customArguments = $null
$msiPath = $resolve_Files[0];
$arguments = @();$arguments += "/i";$arguments += '"' + $msiPath + '"';$arguments += "/quiet";
if ($noRestart){$arguments += "/norestart";}
$logFileId = New-Guid;$logFilePath = "$logFileId.log";$arguments += "/l*";$arguments += '"' + $logFilePath + '"';
if ($customArguments){$arguments += $customArguments;}
$msiExec = "msiexec.exe";$process = Start-Process $msiExec -ArgumentList $arguments -Wait -NoNewWindow -PassThru;
if (Test-Path $logFilePath){Get-Content -Path $logFilePath;}
Exit $process.ExitCode; - CS_HelpDesk3 years agoGoTo Contributor
$caption = $null
$text = $null
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show($text, $caption)
- CS_HelpDesk3 years agoGoTo Contributor
Extract all files and folders from a compressed ZIP archive to a selected folder.
---
$source = $null
$destination = $null
$overwrite = $false
Expand-Archive -Path $source -DestinationPath $destination -Force:$overwrite
- CS_HelpDesk3 years agoGoTo Contributor
Compress a file or folder to a ZIP archive.
---
$source = $null
$destination = $null
$includeRootFolder = $false
$overwrite = $false
$parent = Split-Path $destination
If (-Not (Test-Path -Path $parent -PathType Container))
{
New-Item -Path $parent -ItemType Container
}
$isFile = Test-Path -Path $source -PathType Leaf
if (-Not $includeRootFolder -and -Not $isFile)
{
$source = Join-Path $source "*"
}
Compress-Archive -Path $source -DestinationPath $destination -Force:$overwrite
- CS_HelpDesk3 years agoGoTo Contributor
To delete a folder at a given destination.
---
Delete
$folderPath = $null
if (Test-Path -Path $folderPath -PathType Container)
{
Remove-Item -Path $folderPath -Force -Recurse
}
else
{
Write-error -Message "$folderPath doesn't exist" -Category InvalidArgument
}
- CS_HelpDesk3 years agoGoTo Contributor
To move a folder from one location to another.
---
$source = $null
$destination = $null
$overwrite = $false
If (-Not (Test-Path -Path $destination -PathType Container))
{
New-Item -Path $destination -ItemType Container
}
Move-Item -Path $source -Destination $destination -Force:$overwrite –Verbose
- CS_HelpDesk3 years agoGoTo Contributor
Copy a folder to a given destination.
---
$source = $null
$destination = $null
$overwrite = $false
If (-Not (Test-Path -Path $destination -PathType Container))
{
New-Item -Path $destination -ItemType Container
}
Copy-Item -Path $source -Destination $destination -Recurse -Force:$overwrite –Verbose
- CS_HelpDesk3 years agoGoTo Contributor
To create a folder at a given destination.
---
$name = $null
If (-Not (Test-Path -Path $name -PathType Container))
{
New-Item -Path $name -ItemType Directory
}