VMware vSphere

 View Only
  • 1.  powershell command to take remote session and execute .bat file``

    Posted Apr 16, 2013 11:12 AM

    I'm automating  Vcenter 5.1 on specified host.For that i need to invoke .bat file on command prompt of destination host.so how can i take session of destination windows VM and execute batch file on cmd through powershell script.



  • 2.  RE: powershell command to take remote session and execute .bat file``

    Posted Apr 16, 2013 01:56 PM

    If you just need to execute a bat file remotely, look at PsExec from Microsoft.

    http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

    If you must use PowerShell, you can use the invoke-command cmdlet, but PowerShell Remoting must be enabled on the remote system.

    Invoke-Command -ComputerName servername -ScriptBlock {c:\folder\script.bat}



  • 3.  RE: powershell command to take remote session and execute .bat file``

    Posted Apr 17, 2013 09:05 AM

    i want a persistant session..

    can u jst explain me in detail.

    i supposed to do as -Take win2k R2 session and on that command prompt i need to invoke sso.bat file.



  • 4.  RE: powershell command to take remote session and execute .bat file``

    Posted Apr 17, 2013 09:21 AM

    I've enables ps remoting using command

    enable-pssremoting

    after that used command as

    PS C:\> Invoke-Command -ComputerName WIN-1A65ARCI1NO -ScriptBlock {c:\sso.bat}

    i Got error as:

    [win-1a65arci1no] Connecting to remote server failed with the following error message : The WinRM client cannot process
    the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a dom
    ain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setti
    ng. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. Y
    ou can get more information about that by running the following command: winrm help config. For more information, see t
    he about_Remote_Troubleshooting Help topic.
        + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
        + FullyQualifiedErrorId : PSSessionStateBroken



  • 5.  RE: powershell command to take remote session and execute .bat file``

    Posted Apr 19, 2013 02:48 PM

    From the get-help about_remote_troubleshooting that was referenced in your error message:


        HOW TO CONNECT REMOTELY FROM A WORKGROUP-BASED COMPUTER
        -------------------------------------------------------
            ERROR:  The WinRM client cannot process the request. If the
            authentication scheme is different from Kerberos, or if the client
            computer is not joined to a domain, then HTTPS transport must be used
            or the destination machine must be added to the TrustedHosts
            configuration setting.


        When the local computer is not in a domain, the following procedure is required
        for remoting.

        1. Configure the computer for HTTPS transport or add the names of the
           remote computers to the TrustedHosts list on the local computer.

           For instructions, see "How to Add a Computer to the TrustedHosts
           List" below.


        2. Verify that a password is set on the workgroup-based computer. If a
           password is not set or the password value is empty, you cannot run
           remote commands.

           To set password for your user account, use User Accounts in Control
           Panel.


        3. Use the Credential parameter in all remote commands.

           This is required even when you are submitting the credentials
           of the current user.


        HOW TO ADD A COMPUTER TO THE TRUSTED HOSTS LIST
        -----------------------------------------------

        The TrustedHosts item can contain a comma-separated list of computer
        names, IP addresses, and fully-qualified domain names. Wildcards
        are permitted.

        To view or change the trusted host list, use the WSMan: drive. The
        TrustedHost item is in the WSMan:\localhost\Client node.

        Only members of the Administrators group on the computer have permission
        to change the list of trusted hosts on the computer.

        Caution: The value that you set for the TrustedHosts item affects all
                 users of the computer.


        To view the list of trusted hosts, use the following command:

            get-item wsman:\localhost\Client\TrustedHosts

        You can also use the Set-Location cmdlet (alias = cd) to navigate
        though the WSMan: drive to the location.
        For example: "cd WSMan:\localhost\Client; dir".

        To add all computers to the list of trusted hosts, use the following
        command, which places a value of * (all) in the ComputerName

            set-item wsman:localhost\client\trustedhosts -value *

        You can also use a wildcard character (*) to add all computers in a
        particular domain to the list of trusted hosts. For example, the following
        command adds all of the computers in the Fabrikam domain to the list of
        trusted hosts.

            set-item wsman:localhost\client\trustedhosts *.fabrikam.com

        To add the names of particular computers to the list of trusted hosts, use
        the following command format:

            set-item wsman:\localhost\Client\TrustedHosts -value <ComputerName>[,<ComputerName>]

        where each value <ComputerName> must have the following format:

            <Computer>.<Domain>.<Company>.<top-level-domain>


        For example:

            set-item wsman:\localhost\Client\TrustedHosts -value Server01.Domain01.Fabrikam.com

        To add a computer name to an existing list of trusted hosts, first save
        the current value in a variable, and then set the value to a
        comma-separated list that includes the current and new values.

        For example, to add the Server01 computer to an existing list of trusted
        hosts, use the following command

            $curValue = (get-item wsman:\localhost\Client\TrustedHosts).value

            set-item wsman:\localhost\Client\TrustedHosts -value "$curValue, Server01.Domain01.Fabrikam.com"

        To add the IP addresses of particular computers to the list of trusted hosts,
        use the following command format:

            set-item wsman:\localhost\Client\TrustedHosts -value <IP Address>

        For example:

            set-item wsman:\localhost\Client\TrustedHosts -value 172.16.0.0

        To add a computer to the TrustedHosts list of a remote computer, use the
        Connect-WSMan cmdlet to add a node for the remote computer to the WSMan: drive
        on the local computer. Then use a Set-Item command to add the computer.

        For more information about the Connect-WSMan cmdlet, see Connect-WSMan.




  • 6.  RE: powershell command to take remote session and execute .bat file``

    Posted Apr 25, 2013 06:18 AM

    I'M able to take the remote session.now need to invoke powershell script for remote installation of Vcenter5.1.For SSO installation we’ve written logic somewhat like this:

    $username = "Administrator"

    $password = "crt@123"

    $Server = "10.211.34.2"

    $secstr = New-Object -TypeName System.Security.SecureString

    $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}

    $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr

    $session=New-PSsession -Computername $Server -Credential $cred

    Invoke-Command -Session $session -ScriptBlock {&"c:\batch_files\inventory.bat"}

    In above code we’re taking username and password from xml file. It is taking remote session successfully & on local m/c ‘s console it is showing contents of the bat file and get stucked there only. We searched for Remote installation of bat file commands they are using ‘Invoke-Command’ only. But in our case neither the installation get started nor it is showing error.