Hi All
I am new to the forum and also newbie to PowerShell. I have compiled a script that will open up file explorer to choose a file ( printer package which is .exe file) then it will copy to the remote machine. Here is my code for it…
Blockquote
$computername = read-host -Prompt “Enter Computer Name to install the printer”
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”) | Out-Null
After PS-Remoting Enabled, Now run the copied .exe file on remote machine
here I am having challege to choose the selected file in $inputfile
if I chose the file manually the code should be
Invoke-Command -ComputerName $computername -ScriptBlock {& cmd.exe /c “c:\Temp\MH18P03_X5855.exe”} - this is not working for some reason, it worked at one point and I lost the track. Now I am getting error message like this…
‘c:\temp\Printer.exe’ is not recognized as an internal or external command,
+ CategoryInfo : NotSpecified: ('c:\temp\Printe…ternal command,:String) , RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : j2xd0169184
operable program or batch file.
After it run the .exe file , I want to disable the PS-Remoting on remote computer by this…
You’ve probably already noticed that the formatting of your post is obviously messed up a lot. Please go back, edit your existing post and fix the formatting of your code, console output and error messages.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Hi All
My previous post about this powershell scripts got messed up so I am reposting this again, hope to get some help . It is working fine now but would like to add some error checking and most importantly I want to replace the manula Printerpackage.exe file in Invoke command to automate from the dialogue box. I would apprecitate to get some Help.
I actually don’t get what you’re asking. If you use a command what’s error prone you could add a try catch block to handle potentially upcomming errors.
What I meant is that I choose the file form the dialogue box and it copy to the remote machine and run the file on the remote machine by using following command.
Currently I have to manually input the .exe file name in the invoke-command. I want to input the file name automatically from the chosen file that I took from the dialogue box. Hope I was able to explain.
Might be reading the script wrong, but would it not be the $path, as that is where the file will reside in the remote machine? Which is a UNC path, so you might get into issues running the file.
You might need to handle where the files is stored on the destination machine and use a file path?