Jump to content

Script to copy file based on input?


Recommended Posts

Posted

Hello,

 

I am looking to create a basic script that will display 3 options on screen. The technician will pick one and based on that option a file will copy and a .exe will launch. The file and .exe will be unique to each option.

 

Can someone who knows more about script than me please help?

 

Thanks

Posted

Something like this should work, just edit as necessary

 

$File1 = ""
$EXE1 = ""
$File2 = ""
$EXE2 = ""
$File3 = ""
$EXE3 = ""
$GetSelection = {
   $Selection = Read-Host -Prompt "Please choose an option:
       1. File 1 and EXE 1
       2. File 2 and EXE 2
       3. File 3 and EXE 3"
   switch ($Selection)
   {
       1 {
           Copy-Item $File1 -Destination "c:\CopyToHere"
           & $EXE1
       }
       2 {
           Copy-Item $File2 -Destination "c:\CopyToHere"
           & $EXE2
       }
       3 {
           Copy-Item $File3 -Destination "c:\CopyToHere"
           & $EXE3
       }
       default { .$GetSelection }
   }
}

.$GetSelection

  • Thanks 1
Posted (edited)
Something like this should work, just edit as necessary

 

$File1 = ""
$EXE1 = ""
$File2 = ""
$EXE2 = ""
$File3 = ""
$EXE3 = ""
$GetSelection = {
   $Selection = Read-Host -Prompt "Please choose an option:
       1. File 1 and EXE 1
       2. File 2 and EXE 2
       3. File 3 and EXE 3"
   switch ($Selection)
   {
       1 {
           Copy-Item $File1 -Destination "c:\CopyToHere"
           & $EXE1
       }
       2 {
           Copy-Item $File2 -Destination "c:\CopyToHere"
           & $EXE2
       }
       3 {
           Copy-Item $File3 -Destination "c:\CopyToHere"
           & $EXE3
       }
       default { .$GetSelection }
   }
}

.$GetSelection

 

 

Thanks for this. It looks ideal.

 

I am using this code

 

Copy-Item $File1 -Destination "APPDATA"

 

However it is trying to send the file to the desktop. This is where the script file is located.

 

I am expecting it to put it in:

 

"C:\Users\\AppData\Roaming\file.pb"

 

Any thoughts please? - Thanks

Edited by FN-GM

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...