_void Posted October 16, 2017 Posted October 16, 2017 I am trying to create a script which uploads a file to a computer, I want the script called "payload.txt" to check if the file has been uploaded to the directory specified on the computer. Quote
_void Posted October 16, 2017 Author Posted October 16, 2017 I want it to check inside the %tmp% folder Quote
PoSHMagiC0de Posted October 17, 2017 Posted October 17, 2017 How are the files being upload? Is it a quack command, bat file, vbs or Powershell? If there are no subfolders and they all end up in the root the the %tmp% folder then in Powershell the command to check is first create an array of the files that should be there. $myfiles = @("file1.exe", "file2.exe", "file3.txt") # Then loop through checking them with test-path, in Powershell $env:tmp is the same as %tmp%. foreach ($file in $myfiles) { if(Test-Path "$env:tmp\$file") { # Do something if file exists. Write-Host ("File {0} exists." -f @($file)) } else { # Do something if file is missing. Write-Host ("File {0} is not present" -f @($file)) } } If you use Powershell to do the copying then you can copy each file and and have a condition when it fails to copy a file that way you can check while copying. $myfiles = @("file1.exe", "file2.exe", "file3.txt") foreach ($file in $files) { Copy-Item -Path "$rootpathtofiles\$file" -Destination "$env:tmp\$file" -ErrorAction "SilentlyContinue" -ErrorVariable myerror if($myerror) { # Do something about that file not being copied. Write-Host ("File {0} did not copy." -f @($file)) } #Else is optional for files that copied, if you just want to continue on then leave out else. else { # Do something when file is successfully copied. Write-Host ("File {0} copied successfully" -f @($file)) } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.