cancel
Showing results for 
Search instead for 
Did you mean: 
CS_HelpDesk
GoTo 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.
 

 

27 REPLIES 27
CS_HelpDesk
GoTo Contributor

Shutdown Script

Stop-Computer –force

CS_HelpDesk
GoTo Contributor

Executable file run  script

Upload an .EXE file. You must set the file to run silently and without user input. 

 

$arguments = $null 

$file = $resolve_Files[0]; 

if ($arguments) 

{ 

    $process = Start-Process $file -Args $arguments -Wait -NoNewWindow -PassThru; 

} 

else  

{ 

    $process = Start-Process $file -Wait -NoNewWindow -PassThru; 

} 

Exit $process.ExitCode 

CS_HelpDesk
GoTo Contributor

File Distribution script

Upload files and set their destination. 

File location is an example. 

--

$destination = 'C:\DistributedFiles' 

$overwrite = $false 

If (-Not (Test-Path -Path $destination -PathType Container)) 

{ 

    New-Item -Path $destination -ItemType Container 

} 

$resolve_Files | % { Move-Item -Path $_ -Destination $destination -Force:$overwrite } 

CS_HelpDesk
GoTo Contributor

File Download

Downloads file from a given URL to the working directory or to a specified folder. 

 

$url = $null 

$destination = 'C:\DistributedFiles' 

$fileName = $null 

$outFile = $fileName; 

if (-Not $outFile) 

{ 

    $outFile = $url.Split('/')[-1]; 

    $outFile = $outFile.Split('?')[0]; 

} 

If (-Not (Test-Path -Path $destination -PathType Container)) 

{ 

    New-Item -Path $destination -ItemType Container 

} 

$outPath = Join-Path -Path $destination -ChildPath $outFile 

$wc = New-Object System.Net.WebClient 

$wc.DownloadFile($url, $outPath) 

CS_HelpDesk
GoTo Contributor

File Copy

Copy a file to a destination.

---

$source = $null 

$destination = $null 

$overwrite = $false 

If (-Not (Test-Path -Path $destination -PathType Container)) 

{ 

    New-Item -Path $destination -ItemType Directory 

} 

$exclude = If($overwrite) { {} } else { Get-ChildItem $destination } 

Copy-Item $source -Destination $destination -Exclude $exclude.FullName -Force:$overwrite –Verbose 

CS_HelpDesk
GoTo Contributor

File Move

Move a file to a destination.

---

$source = $null 

$destination = $null 

$overwrite = $false 

If (-Not (Test-Path -Path $destination -PathType Container)) 

{ 

    New-Item -Path $destination -ItemType Container 

} 

Move-Item $source -Destination $destination -Force:$overwrite –Verbose 

CS_HelpDesk
GoTo Contributor

File Delete

To delete a file.

---

$filePath = $null 

if (Test-Path -Path $filePath -PathType Leaf) 

{ 

  Remove-Item $filePath -Force 

} 

else 

{ 

  Write-error -Message "$filePath doesn't exist" -Category InvalidArgument 

} 

CS_HelpDesk
GoTo Contributor

Folder Creation

To create a folder at a given destination.

---

$name = $null 

If (-Not (Test-Path -Path $name -PathType Container)) 

{ 

    New-Item -Path $name -ItemType Directory 

} 

CS_HelpDesk
GoTo Contributor

Folder Copy

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