Execute commands remote with PSSession

Hi,
I am trying to write a script that is executed on Server A but connects to Server B and executes the commands with remote Powershell.
I am currently just trying some simple commands since it's the first time I have tried the remote Powershell function. I connect to a server which is working fine, but if I do a simple command like:
$FoundFiles = Get-ChildItem - Path "C:\Temp"
it returns an error telling me that it cannot find the path. If I do the same and use "C:\Windows" it works.
If I enter the commands manually in a console everything also works as expected.
Lasse
/Lasse

If you do this:
Enter-PSSession -Name TestConnection
$tmpFiles = get-childitem -path "C:\temp"
you will be running  from the remote system and c:\temp will have to be on the remote system.  Either copy the file there or use invoke.
Spend some time testing the commands until you sort out how remoting works.   When you enter a sessin your prompt changes to tell you you are now running on the remote system and all references are to the remote system.
This works the same but references are local and execution is remote:
$session=New-PSSession  -ComputerName Servername
invoke-command -file c:\temp\script.ps1 -Session $session -ArgumentList '-param1 xxxx','-param2 vvvvv'
I can also alter the session:
PS C:\scripts> invoke-command -command {$newvar='hello remote'} -Session $session
PS C:\scripts> invoke-command -command {$newvar} -Session $session
hello remote
Notice the session is retained. I can load modules in one command or file and use them in another:
We can also use -AsJob for very long running scripts and invoke against a list of computers.
it is not just a telnet like session but a full remote targetable session.
¯\_(ツ)_/¯

Similar Messages

  • Execute command remotely using html?

    hi all,
    i have a script i'd like people to be able to call on my server using a web interface. can this be done in html? or do i have to learn php/javascript?
    thanks!
    - ld

    People seem to think CGI is something they have to write -- it isn't. You can configure your web server to run any program (or script) you want; the output of the program* is fed back to the client's web browser as the page content.
    CGI is a standard by which the web server provides information about the client's web browser and HTTP request to the program. The program may choose to use this information or ignore it; it is, however, the only input the program will get from the web server.
    Since the output of the program is fed back to the web browser, it is considered helpful if the program outputs HTML -- otherwise the browser may not know how to render it! It's also considered polite if the program actually terminates -- otherwise the browser will sit there waiting for the page content for an uncomfortably long time.
    * That's the "standard output" on a UNIX/Linux/OS X box; don't expect
    a program's GUI commands to get sent back to the client's browser!

  • Execute Commands on startup Enlightenment

    Hi,
    How to execute command together with startup the environment Enlightenment?
    Always startup I have execute in "Run Command":
    1- stalonetray -> For system tray
    2- nm-applet -> For Network Manager (I love this software)
    3- tpb -d -> For my thinkpad
    P.S: I use GDM.

    You just need to add these apps to your startup applications.  Left-click the screen for Menu->Settings->Settings Panel->Apps->Startup Applications.  You might need to create .desktop files for the apps you want to start using Menu->Settings->Settings Panel->Apps->New Applications.
    edit: if you didn't use gdm you could just add those apps to your .xinitrc file, iirc.
    Last edited by bgc1954 (2009-02-12 14:15:30)

  • Same command works with enter-pssession but not invoke-command

    I'm trying to run an executable remotely with powershell. Right now I'm trying to install Office 2013 SP1, but in the past I've had the same issue with other executables.
    The command I'm running is as follows:
    Invoke-Command -computername computer01 -scriptBlock {C:\windows\Temp\proplussp2013-kb2817430-fullfile-x86-en-us.exe /quiet}
    It finishes almost immediately, returning no result, having not installed anything.
    However, if I do the following, it works just fine:
    Enter-PSSession computer01
    C:\windows\Temp\proplussp2013-kb2817430-fullfile-x86-en-us.exe /quiet
    Any idea what my problem with Invoke-Command is?
    Eric Hodges

    I did an Enter-PSSession, then ran the command using start-process. It hangs indefinitely. I did have to change the command a little, because I couldn't just put the whole command in quotes - that gave me an error saying the file wasn't found. I separated
    it into -filepath and -argumentlist params. Below is what I ran:
    Enter-PsSession -computername computer01
    start-process -filepath "C:\windows\Temp\proplussp2013-kb2817430-fullfile-x86-en-us.exe" -argumentlist "/quiet"
    This resulted in the session hanging indefinitely. So here is where I'm at:
    Enter-PsSession then running the command works
    Invoke-command with the command immediately finishes, with no output and the program doesn't actually install
    Enter-PsSession then running start-process hangs indefinitely
    Invoke-Command plus start-process hangs indefinitely
    I was curious to see if this held true with other programs, so I tried installing a program from HP with a silent switch and got identical behavior throughout all four scenarios listed above. 
    Turning off on-access A/V protection made no difference.
    Finally, regarding mjolinor's question about the program running in non-interactive environments: to the best of my knowledge the program can - but I'm not positive. I would assume, however, that invoke-command would build the same sort of environment as
    Enter-PsSession does, and it works there.
    Eric Hodges

  • Execute commands on a remote server

    hello,
    1. how can i execute commands on a remote server using java (how to connect and how to execute) without having java on the remote server
    (i cannot connect with Socket object)
    2. how can i execute commands on the local computer
    please help me

    Well, for #1, if you can possibly know what commands you'd have to call you could set a perl script up on the remote machine to perform that command and return to you the results. problem is, you'll have to have a web server of some sort to do this (as far as i know).
    I know it's not a very good solution, but it's helped me plenty of times where i couldnt install Jakarta or the likes on a server and couldnt connect to it using sockets.
    Justin

  • Just installed Lion and the Magic TrackPad and I am having a problem with one click commands.  I have to hit the pad fairly hard with one finger to get it to accept the command.  Is this normal, is there another way that I am suppose to execute commands?

    Just installed Lion and the Magic TrackPad and I am having a problem with one click commands.  I have to hit the pad fairly hard with one finger to get it to accept the command.  Is this normal, is there another way that I am suppose to execute commands?

    No you just need to turn on Tap to Click. Go into System Preferences - Trackpad and click the Point to Click tab and select the first box which will say Tap to Click and you should be in business.

  • Problem in using JDBC Execute commands(Update & Delete Only) with af:Table

    HI Everyone,
    I have one issue with Updating and Deleting Row Data using JDBC Execute commands.
    Suppose In My Application i have two pages, in Page 1 I have Two Command Buttons(Delete and Save) and One Input TextBox to write the String to be stored in the Database. and Page 2 where the result Table is shown and table is binded with a ViewObject, Now When User Types some String in InTB and click Save then By Programmatically I'm searching, that string is already present in database or not, if it is already exist then Save button converts in Update button and instead of inserting it allows user to Update the String already exist in database.
    Everything is working fine but the problem comes when i put those all buttons on the same page where result table is present.After putting all things on the same page and When i click save button to insert new String it is Successfully inserting but when any of other action is performed like updating or Deleting the existing one.. then my application just hanged and then nothing I able to do.
    Please Help me to understand this problem and give me the solution for this..
    Thanks
    Fizzz...

    Hi frank,
    Thanks to reply me...
    I'm refreshing table's iterator on each command button's action to reflect the changed result... and i'm sorry i mentioned two pages in my project.. actually these are two forms in the same page..which conditionally changed its renderer properties.. its working fine when only one form is renderred and the otherside when both are rendered then it is not working.
    Hope this change will help you to understand the problem.. if something else you are looking for then please tell me..
    Thanks
    Fizzz...

  • Processing data for a remote command failed with the following error message: Error occurred during the Kerberos reponse.

    Hi!
    We have 5 Exchange 2013 servers and when I’m trying to run a script that includes the cmd-let Get-MessageTrackinglog with StartDate = the first of the month and with EndDate = the end of the month I get the following error message after
    a couple of hours. The script is run on the server SERVER01 and goes through the Message Tracking logs of all Exchange servers. I have tried the script on other servers and get the same result.
    Processing data for a remote command failed with the following error message: Error occurred during the Kerberos reponse.
    [Server=SERVER01, TimeStamp = 918/2014 19:32:34]
    For more information, see the about_Remote_Troubleshooting Help topic.
        + CategoryInfo         
    : OperationStopped: (server01.domain.com:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : JobFailure
        + PSComputerName       
    : server01.domain.com
    I have gone through “about_Remote_Troubleshooting Help topic”, but can’t find anything related to my issue. There is nothing in the Application or the Windows PowerShell log either.
    /Henrik

    Hi Henado 
    Check the time on your Exchange server(s) relative to the DCs and ensure they are in correct sync
    Use another account which is assigned the Organization Management permission and log to to the server run the command in shell and see the results
    Run 
    Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010
    Set-Adserversettings -ViewEntireForest $True and then run message tracking command and see the results
    If none of the above helps you may need to remove and re-install the WinRM and see the results
    Good Luck :)
    Remember to mark as helpful if you find my contribution useful or as an answer if it does answer your question.That will encourage me - and others - to take time out to help you Check out my latest blog posts on http://exchangequery.com

  • Error when I execute an application with the java command in a DOS prompt

    Hi:
    I have a trouble. I edit the most simple program in Java: hello.java
    In DOS prompt, I compile the program. The result is the file hello.class
    c:\> javac hello.java
    However, I try to execute this program with the command java
    c:\> java hello
    and the DOS prompt send me an error like this: Java.exe has a problem and must be closed.
    I press the option "Don't send". After this, the DOS prompt returns empty and it doesnt execute the application:
    c:\>
    By the way, in an IDE editor like Gel, the file hello.java is compiled and executed correctly without problems.
    I edited other simple Java files, I compiled them succesfully and I can't run them in a DOS pormpt. The result is the same dialog box: "Java.exe has a problem and must be closed".
    The question is: Why don't these programs run in a DOS prompt?
    My Operating System is Microsoft Windows XP and the Java compiler version is: 1.6.0_13
    Thanks in advanced.

    Hi again:
    What happens when you type "java -version"?
    Answer:
    java version "1.2"
    Classic VM (build JDK-1.2-V, native threads)
    What is the value of your %PATH%?
    Answer:
    Path=E:\oracle\product\10.2.0\db_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Archivos de programa\Archivos comunes\Adaptec Shared\System;C:\Archivos de programa\Executive Software\DiskeeperLite\;C:\Archivos de programa\QuickTime\QTSystem\;C:\Archivos de programa\Java\jdk1.6.0_13\bin;C:\Archivos de programa\Microsoft SQL Server\80\Tools\Binn\;e:\Microsoft SQL Server\90\Tools\binn\;C:\BITWARE\;C:\Archivos de programa\Archivos comunes\Ahead\Lib\
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    Have you considered running Linux?
    Answer: No, because Linux is more complex.
    Additional information:
    My Operating System is: Microsoft Windows XP Profesional Version 2002, Service Pack 3, running on an Intel Pentium 4, CPU 2.4 Ghz, RAM: 2.23 Gb

  • Error with Project Parameters when executing the package with dtexec command

    Hi,
    We have started migrating our SSIS package from 2005 version to SSIS 2012. In SSIS 2005 we were using XML configuration files and executing the packages with dtexec command from the packages folder (without deploying packages to filesystem).
    Now in SSIS 2012, we have seen Project Parameters and created couple of package parameters and used those parameters in the package. when executing this package from solution explorer it was working fine but when i try to execute the same package from command
    line with Dtexec command, it was showing an error message of 'Not able to map Project Prameters to configurations'.
    Could you please give me an idea of how to execute the packages from command line by using dtexex command. basically i would like use project parameters in 2012 similar to configurations?
    Thanks,
    Venu.

    Refer
    http://msdn.microsoft.com/en-IN/library/hh231187.aspx
    you can pass parameter like this
    /SET \Package.Variables[$Package::ParameterName];<value> /SET \Package.Variables[$Project::ParameterName];<value>
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Restart-Computer remotely with Local Admin

    Hello;
    I manage my company's server and AD infrastructure, containing hundreds of Windows 2012 R2 servers.  I also patch all of my servers monthly.  The biggest challenge in patching servers, is the fact that they need to be restarted every month, in
    order for the patches to finish installing.
    We have a certain group of servers, that need to have their restarts specifically scheduled.  The services offered by these servers are managed by a specific group of IT Pros.  However, this group of IT Pros do not have Local Administrative permissions
    on these servers (nor do they need it to do there jobs).
    I would like to enable this group to remotely restart these servers every month using the 'Restart-Computer' powershell command, without granting them Local Admin (that way, I won't need to get up at 3am every month to do this myself).  I've tried adding
    them to the following "User Rights Assignment": "Force shutdown from a remote system" and "Shut down the system".
    But, they still get an "Access Denied" error message.  What am I missing?  Is this even possible?  I've searched for hours now, but with no luck.

    Thank you for the reply, but I had already tried those suggestions.  Here's what I've tried so far:
    First, as I mentioned before, I've added the admins to the following "User Rights Assignment": "Force shutdown from a remote system" and "Shut down the system".  Then I temporarily added the admins to the "Allow log
    on locally" user rights assignment so that I may log on to the server as the admins and prove that the admins can indeed restart the local server.  From the server console, the admin was able to launch a powershell session and run the "Restart-Computer"
    command, and the server restarted perfectly. 
    So that part worked just fine.  But I would like to get the admins to remotely restart the servers, without granting them the "Allow log on locally".  Another thing I tried, was to create a new remote PSSession, and then run the Restart-Computer
    command from there.  At first, the New-PSSession gave me an access denied error message.  That's when I ran the Get-PSSessionConfiguration command, and I noticed that the "Builtin\Remote Management Users" group was allowed access. 
    So I added the Admins to that group on one of the servers.  Now the New-PSSession command worked.  But the Restart-Computer still gives me an Access Denied error message.
    Here are the commands that I am using.
    First, running the Restart-Computer from the admin's workstation:
    Restart-Computer -ComputerName SERVER01
    Second, running the Restart-Computer command from with a remote PSSession.
    New-PSSession -ComputerName SERVER01
    Enter-PSSession 2
    Restart-Computer
    Either way, I get an access denied message.

  • Help needed in executing a remote batch file

    I need to execute a batch file which is located on a remote machine through my machine. I have no idea to go about with. Please can someone help me out with can be used to execute the remote bat file. I am at present using Runtime.exec() to execute it on my machine.. But i cant use it to execute teh bat file on teh remote machine.Please help

    Below is an example server that would run on the remote host. You can connect to it using telnet from DOS prompt, it takes a Y/N to run your command in the cmd variable. I haven't included code for a client as it's really not needed for the example below.
    Change the cmd and port variables to what you need. You may need to setup firewall rules to allow your chosen port.
    Once it's running, you can test it by using "telnet localhost 1234" on your machine, localhost would obviously become the remote computer's hostname or IP.
    I am incredibly new to Java (using the forums to learn bits), so excuse any bad coding practises, I'm sure people will point them out.
    Keep in mind that this is totally insecure, so if you're using it on an untrusted network, you may want to look into encryption and providing some kind of password authentication, that, for the moment is out of my league.
    Screenshot here.
    import java.io.*;
    import java.net.*;
    class RemoteServer {
         public static int    port = 1234;           // Port to listen on
         public static String cmd  = "C:\\Test.bat"; // Command to run
         public static void main(String[] args)
              System.out.println("Waiting for connection...");
              try {
                   /* If you want the server to run forever, uncomment the while
                      loop */
                   // while (true)
                        startServer();
              } catch (IOException e) {
                   e.printStackTrace();
                   System.exit(1);
         /* Starts the server */
         private static void startServer() throws IOException
              ServerSocket server = null;
              Socket       client = null;
              String input;
              try {
                   server = new ServerSocket(port);
              } catch (IOException e) {
                   System.err.println("Unable to list on port " + port);
                   System.exit(1); // Can't listen, nothing else to do
              try {
                   client = server.accept();
                   System.out.println("Client connected... awaiting Y/N");
              } catch (IOException e) {
                   System.err.println("Unable to accept connection.");
                   System.exit(1);
              PrintWriter out = new PrintWriter(client.getOutputStream(), true);
              BufferedReader in = new BufferedReader(new InputStreamReader(
                                                     client.getInputStream()));
              out.println("You are connected, ready to launch command: <y/n>");
              while ((input = in.readLine()) != null)
                   if (input.equalsIgnoreCase("y"))
                        Runtime rt = Runtime.getRuntime();
                        rt.exec(cmd);
                        out.println("Command executed... disconnecting.");
                        System.out.println("Command executed... disconnecting client.");
                        break;
                   } else if (input.equalsIgnoreCase("n")) {
                        break;
                   } else {
                        out.println("Please enter Y/N.");
              out.close();
              in.close();
              client.close();
              server.close();
    }

  • Getting "Serialized xml is nested too deeply" when trying to restart AppFabric Cache Cluster remotely with Powershell

    Hi! I´m Getting the following error when trying to restart the AppFabric Cache Cluster:
    PS C:\temp> .\restartappfabric.ps1
    Serialized xml is nested too deeply.
    + CategoryInfo          : OperationStopped: (ServerName:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : JobFailure
        + PSComputerName        :
    ServerName
    Here's The Script:
    $ServerName="ServerName"
    $sc = {
                Import-module DistributedCacheAdministration
                Use-CacheCluster
                Restart-CacheCluster
    Invoke-Command -computername  $ServerName -scriptblock $sc
    Powershell remoting is fully enabled and working fine con remote computers. When testing the script against a TEST computer is working fine, but when executing the script against PRE & PROD servers I get the error described above.
    Running the lines within the scriptblock locally in the servers works fine.
    Any help on this would be appreciated.
    Thanks

    Thanks man for your help. Tried using the connectionstring but got the same results
    PS C:\temp> Invoke-Command -ComputerName Servername {import-Module DistributedCacheAdministration;Use-CacheCluster -P
    rovider XML -ConnectionString "\\vmbcorp.com\FS\ApplicationContent\PRE\AppFabricCache" ;Restart-CacheCluster}
    Serialized xml is nested too deeply.
        + CategoryInfo          : OperationStopped: (BBLAMTPDAFC01:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : JobFailure
        + PSComputerName        : BBLAMTPDAFC01
    PS C:\temp>
    Running the commands locally with the ConnectionString swith works as well. Running out of Ideas.. May be using psexec..

  • Could not execute command "getVersion" on the node manager

    Hi all,
    I have 2 unix machine:
    A - Admin with BankServer1 and BankWeb1 - work fine
    B - remote machine
    I did pack and unpack , after that in Weblogic I go to Environment > Machines > my_remote_machine(B) > Monitoring Tab
    The error is:
    <Error> <NodeManager> <BEA-300033> <Could not execute command "getVersion" on the node manager. Reason: "Access to domain 'Bank_Unix' for user 'hP76NCZfcy' denied".>

    Hi,
    Did u execut nmEnroll () WLST command successfully from remote box. to Enroll the NodeManager? Or did u see any WARNING/ERROR while doing this?
    Can u please double check if the Step-8 is executed successfully ...mentioned in the below link: http://weblogic-wonders.com/weblogic/2010/04/28/weblogic-clustering-in-remote-boxes/
    Thanks
    Jay SenSharma

  • How can I use apple remote with Mountain Lion? Any Front Row alternative?

    Hi All,
    I recently upgraded from Snow Leopard to Mountain Lion.
    All great except for my Apple Remote control.
    Before, I could effectively control my iMac media with Apple Remote by using Front Row (music, photos, videos, good integration with iTunes and iPhoto).
    Now, as I understand, Front Row is expired.
    So, my Apple remote still works but with very limited options (just music, forward, backward and volume), and it's a real pity.
    Any of you Guys know how to restore Front Row?
    Otherwise maybe suggest an alternative (sth similar, should allow iMac media control by Apple Remote)?
    So far I tried to restore all Front Row files by a Time Capsule Snow Leopard backup (as indicatred on some other Communities).
    To restore was easy, but then, no way to launch it.
    Any advice will help!
    Thanks in advance/all the best.
    Marco

    Thanks Klaus1 for your prompt answer, although I went again through a dated discussion.
    I also got the feeling that somehow they want to push Apple TV..
    But, respectfully speaking towards our Friends at Apple, is it fair to promise what you don't deliver?
    I have choosen apple because I percive it's different.
    At currently published link: http://store.apple.com/uk/product/MC377Z/A/apple-remote
    they do promote the following:
    Apple Remote with Mac
    The Apple Remote gives you total command of your music, photos, videos and DVDs from anywhere in the room. It works with Front Row - a menu-based, full-screen interface - to make accessing the digital content on your Mac as simple as navigating your iPod. When you press the Menu button, your desktop fades and the sleek, Front Row interface takes its place, to give you control over your music in iTunes, your photos in iPhoto, the videos in your Videos folder and your DVDs. Turn up the volume. Shuffle. Skip to the next chapter on your DVD. Play a slide show, a home video that you made in iMovie, even a film trailer.
    Compatible with Apple products introduced in 2005 or later that have a built-in infrared (IR) receiver. Not compatible with MacBook Pro with Retina display.
    Cost for this is 15£ (19€).
    Now, I have iMac and Mac Book Pro (no retina display) both with Mountain Lion installed, and I understand both of them are not compatible with Front Row.
    Actually I adore apple tv and I got 2 at home nicely working on 2 different TVs.
    So I accomplished twice their wish of selling this product to me.
    Why shall they deceive me (and many others, as I read) by killing a still promised service?
    Should I read all forums before buying a trusted-brand-product like apple, to ensure that id does what declared?
    Don't get me wrong, I'm an enthusiast user of the whole apple family, since many years, and still I am.
    Just politely complaining for this decision, which creates to Many an easy avoidable disservice.
    Cheers
    Marco

Maybe you are looking for

  • No sound through speakers or headphones in 3rd Gen iPod touch

    Sound worked perfectly on the iPod until it was plugged into a speaker set through the headphone jack. Ever since then the ipod gets really warm and whenever a sound should be heard, there's a faint sound kind of like white noise. When you try to pla

  • Physical schema vs logical schema in odi

    hi, i am new to odi.I have successfully loaded data metadata to essbase and planning . But still i am not clear why odi uses physical schema when we just uses logical schema while reversing, execution of interfaces etc in designer

  • OBYA : vendor and customer clearing in cross company code transaction

    Hi Gurus, Please can any one telll me how to clear the transactions of cross company code which is in vendor and customer. I already done a configuration in OBYA for customer - vendor. Expected a process of clearing the cross company code transaction

  • Files could not be found

    I transferred all of my iMovies and my iDVD project to a new computer. I need to reburn the iDVD and it says all of the files could not be found. How can I remedy this? Thanks!

  • Err 404 The URL could not be found on the server

    I attempted to purchase a song and got this error message, error 404 the URL could not be found on the server. Now every time I download any song, it attempts to find the song and gives me the same error message. I don't care if I lose the song. I wo