Using a Variable to Substitute the path\filename of a Batch file in the Start_Process Command

I am trying to write a script that will execute a batch file on a remote Windows server.
This line below is basically what I'm trying to do and it works without error, however I would like to use a variable for the path\filename of the batch file.
invoke-command -computername QSC-A-ICE01 -scriptblock {Start-Process "\\qsc-a-ice01\D$\Test\RunThis.bat" }
If I try to use a variable as in this example below I receive the error below. The error seems to indicate it's it expecting a "FilePath" parameter. Is this true? How would I change this script to make it work when substituting a variable.
$MyProcess =  "\\qsc-a-ice01\D$\Test\RunThis.bat"
Write-Host $MyProcess
invoke-command -computername QSC-A-ICE01 -scriptblock {Start-Process "$MyProcess"}
This is the error text I receive when using a variable:
 PS C:\Windows\system32> D:\Test\ThisWorks.ps1
\\qsc-a-ice01\D$\Test\RunThis.bat
Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Supply an argument that is not null or
empty and then try the command again.
    + CategoryInfo          : InvalidData: (:) [Start-Process], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand
    + PSComputerName        : QSC-A-ICE01
PS C:\Windows\system32>

Mike,
Thanks for providing the link, it was very informative. The link described how to use the args in a ScriptBlock and provided me with an explaination as to why it works the way it does on a remote server. This is my 1st post to the forum and I don't know
how the points system works yet.
I would like to split the points , but I don't see that this is possible.
You're very welcome, I'm glad that the information was helpful.
You can mark as many posts as answers as you'd like, there's not a restriction on only having a single answer per thread. You certainly don't have to though, David's answer is more than sufficient to help any future people who find this thread.
Also, on a side note, you may want to post in the thread below. Posting there will get your account verified so you'll be able to post links and images.
http://social.technet.microsoft.com/Forums/en-US/200c33c9-abe9-494a-953a-bf53fccb3c76/verify-your-account-11?forum=reportabug
(Future people - don't use that link.
Click here and look for the current thread as a sticky.)
Don't retire TechNet! -
(Don't give up yet - 12,575+ strong and growing)

Similar Messages

  • Use of variables in "FOR XML PATH"

    Other than using dynamic sql (which we don't want to use) is there a way to use a variable in For XML Path, e.g.
    select
    FOR XML PATH (@BookName), ROOT('Book'), TYPE
    TIA,
    edm2

    In terms of general XML design this is poor.  An element is normally a 'thing', and the attributes are normally the properties of that thing.  Therefore in your case you would have a Book property with a 'name' attribute.  It would be impossible
    to create an XSD for your xml, and makes it awkward for readers of your xml - how do they know the book name beforehand?  Creating this xml in the normal fashion would also make it easy to create without any messing around ( string manipulation,
    other hacks ), eg
    DECLARE @BookName NVARCHAR(20) = 'SomeBook'
    SELECT
    @BookName "@name"
    -- Other book attributes
    FOR XML PATH ('Book'), ROOT('Books'), TYPE
    So now you have a Book item(s) within a Books collection.  Easy!  : )

  • How to feed a query using a variable defined as Replacement Path-Query

    Scenario description : BI NetW 2004S - InfoCube with the following characteristics Customer, OrderDate, OrderYear and the following KeyFigure Number of Pieces.
    Objective: I need a query "QB" that shows how many pieces a set of customers has ordered in the year 2008. The set of customers is defined as all customers that in the previous years (the user can select one or more years) have ordered more than 500 pieces within the same year.
    Implementation: In general terms the idea is to build a query "QB" with the characteristic "Customer"  that is restricted (filtered) using a variable that is fed by another query "QA" (Replacement Path-Query).
    In order to have the selection of customers that for each of previous years (2007, 2006, 2005,...) have ordered more than 500 pieces, in the query "QA":
    - I put OrderYear as filter and defined a variable in order to ask the user which year/s he wants to analyse to define the selection
    - I put Customer and OrderYear in row
    - I put the KeyFigure Number of Pieces in column
    - I've defined the following condition: Number of Pieces > 500 with the option Caracteristic Assignment = All Characteristics in the Drilldown Indipendently
    Now if I run the query "QA" it works correctly showing me all customers that in the selected years have ordered more than 500 pieces within of the same year.
    If I run the query "QB" it shows a correct result only if I enter only one year (for example 2006) in the OrderYear field (coming from the query "QA"); if I enter more than one year (for example 2006 and 2007) the selection of customers showed is not the same defined by the first query "QB": I was expecting to see all customers defined from the first query less all customers that have no ordered any piece in 2008.
    Questions
    1) Why is query "QA" working on a different selection of customers when the user selects more than one year?
    2) Cosidering the scenario and the objective described above do you have any other idea?
    Thanks
    Ciao
    Roberto

    Hi Christophe,
         it's ok for me if I consider the customer only once in the final selection of customers that feeds the final query, this is my objective.
    However as test I've created 2 "input" queries, one related to 2006 and one related to 2007, and then in my destination query I've tried to restrict the customer using 2 variables of type replacement path-query (one attached to the 2006 query and one attached to the 2007 query). Unfortunately when I try to check and save the destination query, Query Designer tells me it is not possible to restrict the characteristic in this way.
    Could you please describe me steps you run in to order to restrict a characteristic using more than one variable of type replacement path-query?
    Thank you in advance for your answer.
    Ciao,
    Roberto

  • How do I make a batch file if the .class file uses a foreign package?

    I am trying to make an MS-DOS batch file using the bytecode file from the Java source file, called AddFields.java. This program uses the package BreezySwing; which is not standard with the JDK. I had to download it seperately. I will come back to this batch file later.
    But first, in order to prove the concept, I created a Java file called Soap.java in JCreator. It is a very simple GUI program that uses the javax.swing package; which does come with the JDK. The JDK is currently stored in the following directory: C:\Program Files\Java\jdk1.6.0_07. I have the PATH environment variable set to the 'bin' folder of the JDK. I believe that it is important that this variable stay this way because C:\Program Files\Java\jdk1.6.0_07\bin is where the file 'java.exe' and 'javac.exe' are stored. Here is my batch file so far for Soap:
    @echo off
    cd \acorn
    set path=C:\Program Files\Java\jdk1.6.0_07\bin
    set classpath=.
    java Soap
    pause
    Before I ran this file, I compiled Soap.java in my IDE and then ran it successfully. Then I moved the .class file to the directory C:\acorn. I put NOTHING ELSE in this folder. then I told the computer where to find the file 'java.exe' which I know is needed for execution of the .class file. I put the above text in Notepad and then saved it as Soap.bat onto my desktop. When I double click on it, the command prompt comes up in a little green box for a few seconds, and then the GUI opens and says "It Works!". Now that I know the concept of batch files, I tried creating another one that used the BreezySwing package.
    After I installed my JDK, I installed BreezySwing and TerminalIO which are two foreign packages that make building code much easier. I downloaded the .zip file from Lambert and Osborne called BreezySwingAndTerminalIO.zip. I extracted the files to the 'bin' folder of my JDK. Once I did this, and set the PATH environment variable to the 'bin' folder of my JDK, all BreezySwing and TerminalIO programs that I made worked. Now I wanted to make a batch file from the program AddFields.java. It is a GUI program that imports two packages, the traditional GUI javax.swing package and the foreign package BreezySwing. The user enters two numbers in two DoubleField objects and then selects one of four buttons; one for each arithmetic operation (add, subtract, multiply, or divide). Then the program displays the solution in a third DoubleField object. This program both compiles and runs successfully in JCreator. So, next I moved the .class file from the MyProjects folder that JCreator uses to C:\acorn. I put nothing else in this folder. The file Soap.class was still in there, but I did not think it would matter. Then I created the batch file:
    @echo off
    cd \acorn
    set path=C:\Program Files\Java\jdk1.6.0_07\bin
    set classpath=.
    java AddFields
    pause
    As you can see, it is exactly the same as the one for Soap. I made this file in Notepad and called it AddFields.bat. Upon double clicking on the file, I got this error message from command prompt:
    Exception in thread "main" java.lang.NoClassDefFoundError: BreezySwing/GBFrame
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    4)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    Caused by: java.lang.ClassNotFoundException: BreezySwing.GBFrame
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    ... 12 more
    Press any key to continue . . .
    I know that most of this makes no sense; but that it only means that it cannot find the class BreezySwing or GBFrame (which AddFields extends). Notice, however that it does not give an error for javax.swing. If I change the "set path..." command to anything other than the 'bin' folder of my JDK, I get this error:
    'java' is not recognized as an internal or external command,
    operable program or batch file.
    Press any key to continue . . .
    I know this means that the computer cannot find the file 'java.exe' which I believe holds all of the java.x.y.z style packages (native packages); but not BreezySwing or any other foreign packages. Remember, I do not get this error for any of the native Java packages. I decided to compare the java.x.y.z packages with BreezySwing:
    I see that all of the native packages are not actually visible in the JDK's bin folder. I think that they are all stored in one of the .exe files in there because there are no .class files in the JDK's bin folder.
    However, BreezySwing is different, there is no such file called "BreezySwing.exe"; there are just about 20 .class files all with names like "GBFrame.class", and "GBActionListener.class". As a last effort, I moved all of these .class files directly into the bin folder (they were originally in a seperate folder called BreezySwingAndTerminalIO). This did nothing; even with all of the files in the same folder as java.exe.
    So my question is: What do I need to do to get the BreezySwing package recognized on my computer? Is there possibly a download for a file called "BreezySwing.exe" somewhere that would be similar to "java.exe" and contain all of the BreezySwing packages?

    There is a lot of detail in your posts. I won't properly quote everything you put (too laborious). Instead I'll just put your words inside quotes (").
    "..there are some things about the interface that I do not like."
    Like +what?+ This is not a help desk, and I would appreciate you participating in this discussion by providing details of what it is about the 'interface' of webstart that you 'do not like'. They are probably misunderstandings on your part.
    "Some of the .jar files I made were so dangerously corrupt, that I had to restart my computer before I could delete them."
    Corrupt?! I have never once had the Java tools produce a corrupt Jar. OTOH, the 'cannot delete' problem might relate to the JRE gaining a file lock on the archive at run-time. If the file lock persisted after ending the app., it suggests that the JRE was not properly shut down. This is a bug in the code and should be fixed. Deploying as .class files will only 'hide' the problem (from casual inspection - though the Task Manager should show the orphaned 'java' process).
    "I then turned to batch files for their simple structure and portability (I managed to successfully transport a java.util containing batch file from my computer to another). This was what I did:
    - I created a folder called Task
    - Then I copied three things into this folder: 1. The file "java.exe" from my JDK. 2. The program's .class file (Count.class). and 3. The original batch file.
    - Then I moved the folder from a removable disk to the second computer's C drive (C:\Task).
    - Last, I changed the code in the batch file...:"
    That is the +funniest+ thing I've heard on the forums in the last 72 hours. You say that is easy?! Some points.
    - editing batch files is not scalable to 100+ machines, let alone 10000+.
    - The fact that Java worked on the target machine was because it was +already installed.+ Dragging the 'java.exe' onto a Windows PC which has no Java will not magically make it 'Java enabled'.
    And speaking of Java on the client machine. Webstart has in-built mechanisms to ensure that the end user has the minimum required Java version to run the app. - we can also use the [deployJava.js|http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit] on the original web page, to check for minimum Java before it puts the link to download/install the app. - if the user does not have the required Java, the script should guide them through installing it.
    Those nice features in deployJava.js are available to applets and apps. launched using webstart, but they are not available for (plain) Jar's or loose class files. So if 'ensuring the user has Java' is one of the requirements for your launch, you are barking up the wrong tree by deploying loose class files.
    Note also that if you abandon webstart, but have your app. set up to work from a Jar, the installation process would be similar to above (though it would not need a .bat file, or editing it). This basic strategy is one way that I provide [Appleteer (as a downloadable ZIP archive)|http://pscode.org/appleteer/#download]. Though I side-step your part 1 by putting the stuff into a Jar with the path Appleteer/ - when the user expands the ZIP, the parts of the app. are already in the Appleteer directory.
    Appleteer is also provided as a webstart launched application (and as an applet). Either of those are 'easier' to use than the downloadable ZIP, but I thought I would provide it in case the end user wants to save it to disk and transport the app. to a machine with no internet connection, but with Java (why they would be testing applets on a PC with no internet connection, I am not sure - but the option is there).
    "I know that .jar and .exe files are out because I always get errors and I do not like their interfaces. "
    What on earth are you talking about? Once the app. is on-screen, the end user would not be able to distinguish between
    1) A Jar launched using a manifest.
    2) A Jar launched using webstart.
    3) Loose class files.
    Your fixation on .bat files sounds much like the adage that 'If the only tool you have is a hammer, every job starts to look like a nail'.
    Get over them, will you? +Using .bat files is not a practical way to provide a Java app. to the end user+ (and launching an app. from a .bat looks quite crappy and 'second hand' to +this+ user).
    Edit 1:
    The instructions for running Appleteer as a Jar are further up the page, in the [Running Appleteer: Application|http://pscode.org/appleteer/#application] section.
    Edited by: AndrewThompson64 on May 19, 2009 12:06 PM

  • What is the best way to find a file on the servers disk without using web.xml?

              What is the best way to find a file on the servers disk without using web.xml?
              I want to find a configuration file not contained within the war file I have
              created. Is there a way to pass information into the ServletContext with out
              rebuilding the ear or war files? Tomcat 4.0 can do this in its server configuration
              files. Does BEA have the equivalent?
              Regards,
              Eric
              

    You can specify the path to the file as a system property
              eg
              java -Dconfig.file.location=./mydirecotry/myfile.txt com.test.MyApp
              "Eric White" <[email protected]> wrote in message
              news:[email protected]..
              >
              > What is the best way to find a file on the servers disk without using
              web.xml?
              > I want to find a configuration file not contained within the war file I
              have
              > created. Is there a way to pass information into the ServletContext with
              out
              > rebuilding the ear or war files? Tomcat 4.0 can do this in its server
              configuration
              > files. Does BEA have the equivalent?
              >
              > Regards,
              > Eric
              

  • I am trying to remove the older version of iTunes but an error message appears saying that it cannot find the path to 'iTunes64.msi", and I tried the search option to find it on my computer but no such luck. Please help me

    I am trying to remove the older version of iTunes but an error message appears saying that it cannot find the path to 'iTunes64.msi", and I tried the search option to find it on my computer but no such luck. Please help me

    Go to Microsoft website to fix install and Unistall problems. Click "Run now" from Fix it to remove all iTunes &amp; related installer files:
    http://support.microsoft.com/mats/Program_Install_and_Uninstall
    Be aware that Windows Installer CleanUp Utility will not remove the actual program from your computer. However, it will remove the installation files so that you can start the installation, upgrade, or uninstall over.

  • IPhoto is changing the sequence of the photos I have in my file for the book I want to create. Help?

    iPhoto is changing the sequence of the photos I have in my file for the book I want to create. Help?

    The problem has been solved. As it turns out, I was highlighting the photos in the album I wished to create. And then generating the request for a book. This caused the photo images when loaded into the book format to revert to the sequence used when I originally loaded them into the album. Not the edited sequence. Turns out that I did not need to highlight the photos. By eliminating this step, they remained in the edited sequence.
    Thank you for responding. Warmly, Janice huseby

  • What is the max size of a zip file with the JDK1.5 ?

    Hello everybody,
    I'm a french student and for a project, I need to create a zip file, but I don't know in advance the number and the size of files to include in my zip.
    I wish to know if someone have the answer to my question : what is the max size of a zip file with the JDK1.5 ? I believe that with the JDK1.3, the limit size of a zip was about 2Go, wasn't ?
    Thank you for all answer !
    Good day !
    PS : sorry for my very poor english ;-)

    Here is all I have found for the moment :
    ...Okay, what about my suggestion of creating your own 10GB file?
    Try this:import java.io.File;
    import java.io.RandomAccessFile;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    import java.util.Random;
    class Main {
        public static void main(String[] args) {
            long start = System.currentTimeMillis();
            int mbs = 1024;
            writeFile("E:/Temp/data/1GB.dat", mbs);
            long end = System.currentTimeMillis();
            System.out.println("Done writing "+mbs+" MB's to disk in "+
                    ((end-start)/1000)+" seconds.");
        private static void writeFile(String fileName, int numMegaBytes) {
            try {
                int numBytes = numMegaBytes*1024*1024;
                File file = new File(fileName);
                FileChannel rwChannel =
                        new RandomAccessFile(file, "rw").getChannel();
                ByteBuffer buffer = rwChannel.map(
                        FileChannel.MapMode.READ_WRITE, 0, numBytes);
                Random rand = new Random();
                for(int i = 1; i <= numMegaBytes; i++) {
                    for(int j = 1; j <= 1024; j++) {
                        byte[] bytes = new byte[1024];
                        rand.nextBytes(bytes);
                        buffer.put(bytes);
                rwChannel.close();
            } catch(Exception e) {
                e.printStackTrace();
    }On my machine it took me 43 seconds to create a 1GB file, so it shouldn't take too long to create your own 10GB. Then try zipping that file.
    Good luck.

  • How can I check the open-mode of an opened file from the file refNum?

    How can I check the open-mode of an opened file from the file refNum?
    Especially whether a file is opened as read-only or write-only? I haven't found any VI in the panel with file VIs.
    Thanks for any hints!

    Check this post. Probably you can use a kernel.dll call.
    http://forums.ni.com/t5/LabVIEW/file-date-created/m-p/109836

  • Preview: In a group of PDF files in the same window, going to the next or a previous PDF file displays the bottom of PDF by default, not the top. How do you change this?

    Preview: In a group of PDF files in the same window, going to the next or a previous PDF file displays the bottom of PDF page by default, not the top of the PDF page. How do you change this? In Mac OS 10.9 and previous, going to the next or previous PDF file displays the top of the PDF by default. Is there a way to change this back? When I go to the next or previous PDF file, I want to first view the top of the page, not the bottom. This really doesn't make any sense. Any help? Thanks!
    MacBook Air (13-inch, Mid 2012)
    2 GHz Intel Core i7
    8 GB 1600 MHz DDR3
    500 GB Flash Storage
    Preview Version 8.0 (859)
    Mac OS 10.10.1

    That to me seems like a bug in Yosemite.
    Apple Feedback http://www.apple.com/feedback/
    Bug Reporter https://bugreport.apple.com/

  • I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    By doing a Google search. 

  • Like an idiot I changed the location of my iTunes Media File in the Advanced section of my Preferences - now half my songs won't play as they can't be found....I know they are there as I played these songs yesterday.....help !!!....

    Like an idiot I changed the location of my iTunes Media File in the Advanced section of my Preferences - now half my songs won't play as they can't be found....I know they are there as I played these songs yesterday.....help !!!....
    .....what folder do I need to reset it to so I can play my entire library??
    Frankie C

    You can also reset the location fo the media folder in the advanced tab.

  • The harddrive holding my itunes library is damaged and I would like to purchase the icloud.  Can I restore files to the icloud without the disk/libraries?

    the harddrive holding my itunes library is damaged and I would like to purchase the icloud.  Can I restore files to the icloud without the disk/libraries?  Thanks!

    iCloud does not provide a service like Dropbox where you can save random files to it as a way of having external storage.  As for the HD damage, don't you have a backup of the itunes library elsewhere?  If so, copy it to the replacement hard drive, along with any other important files that were on the damaged HD.

  • How to run batch files in the backround ??????

    please anyone tell me how to run the batch files in the background i dont want anyone to interfere the batch file..The batch file has to run for a long time even days so it will be safe if the batch file is running in the bachgroung somewhere ..
    please help me in this regards
    Thanking u
    Regards
    Santhosh

    The easiest way is to write a native application which starts the batch file in hidden mode (the target batch file could be an argument).
    Under Windows it would be done with the API call
    ShellExecute(NULL, "open", "C:\mybatch.bat", NULL, NULL, SW_HIDE);
    Then compile the native tool as windows application with no user interface. Now you are able to execute applications in invisible mode.

  • Just had help installing cc 2014. get this dialog box when i open the app. One or more files in the adobe folder necessary for running photoshop are missing. Help

    Just had help installing cc 2014. get this dialog box when i open the app. One or more files in the adobe folder necessary for running photoshop are missing. Help

    Please Run the Cleaner tool to remove Ps CC 2014 :http://www.adobe.com/support/contact/cscleanertool.html .
    Restart your system and then try installing Ps CC 2014 again.
    Regards,
    Ashutosh

Maybe you are looking for

  • My hard drive crashed! How do I replace the hard drive?

    My mid 2010 MacBook Pro 13" started making a horrible skipping/clicking noise when I insterted a disk. It wouldn't eject the disk so I powered it down to restart it, but when it came back on, all that appeared was a grey screen with a flashing file f

  • Water damaged iphone 4

    The phone was brought as a pay-as-you-go & is not insured, Suffered minor splash of water & is playing up abit, turns off every now & then. Screen & everything seems fine but dont think its charging though. Any ideas or am i screwed!? Ive left it nea

  • Macbook Pro – Some Keys Not Working!

    Hi I'm running a 15-inch ( mid 2010 ) Macbook Pro with OS X 10.8.5. Some of my keys have stopped working. I've been throughout his forum but found nothing that helps. The 't' key sometimes does nothing and sometimes this... IORTUY other keys that don

  • I have lost my sent box and can't send any e.mails

    I can't send any e.mails out It would appear that I have lost everything to do with my sent box

  • IPhone app crach on simulator 'run' but not in 'debugger'

    Hi, I am currently doing some development on the iPhone simulator and seem to be stuck with a problem. When running my code directly from the simulator or from the xcode 'run' feature, the application I am writing will crash (seems to be a socket sel