Forum Discussion

CS_HelpDesk's avatar
CS_HelpDesk
GoTo Contributor
2 years ago

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.
 

 

  • CS_HelpDesk's avatar
    CS_HelpDesk
    GoTo Contributor

    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's avatar
    CS_HelpDesk
    GoTo Contributor

    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's avatar
    CS_HelpDesk
    GoTo Contributor

    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's avatar
    CS_HelpDesk
    GoTo Contributor

    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's avatar
    CS_HelpDesk
    GoTo Contributor

    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's avatar
    CS_HelpDesk
    GoTo Contributor

    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