Welcome to the Remote Execution - Powershell Script Repository!
Stop-Computer –force
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
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 }
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)
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
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
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
}
To create a folder at a given destination.
---
$name = $null
If (-Not (Test-Path -Path $name -PathType Container))
{
New-Item -Path $name -ItemType Directory
}
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