PowerCLI

 View Only
  • 1.  Run Batch in Guest Remotely via PowerCLI

    Posted May 30, 2013 06:44 AM

    Hi All,

    I'm sure I've come across a script that can execute a batch file within Windows guests remotely using PowerCLI, but for the life of me I can't find it.

    I have 4 Windows VMs, which have the same login credentials, they have a test.bat file in the same location, I need a way of executing the batch remotely via PowerCLI simultaneously, is this possible?



  • 2.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted May 30, 2013 06:50 AM

    You can do that with the Invoke-VMScript cmdlet



  • 3.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted May 30, 2013 08:09 AM

    Thanks Luc,

    It seems to be almost working but I get the following output (see image)

    I should also point out I connected PowerCLI directly to the host not vCenter, the batch file I'm trying to run is an SQLIO.exe with the following:

    @ECHO OFF

    sqlio -kR -t8 -s120 -frandom -o32 -b4 -BH -LS -Fparam.txt



  • 4.  RE: Run Batch in Guest Remotely via PowerCLI
    Best Answer

    Posted May 30, 2013 08:14 AM

    It looks as if the sqlio command is not found. Could be that the directory is not in the Path variable in that OS.

    Try with the full path to the sqlio executable.



  • 5.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted May 30, 2013 11:17 AM

    Hi Luc,

    Rather than running the batch this seems to work.

    Invoke-VMScript -VM VM1 -ScriptText "C:\SQLIO\SQLIO.EXE -s120 -kR -frandom -b4 -t4 -o32 -LS -BH e:\Testfile.dat" -GuestUser administrator -GuestPassword password

    Can you help me with having this executed simultaneously on multiple guest VMs ?



  • 6.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted May 30, 2013 11:19 AM

    Hi Luc,

    I think I acutually almost have it, I'm just having trouble specifying the GuestCredential

    $guestvms = "flash1,flash2,flash3"

    $guestCredential = ?????

    $myscript = "C:\SQLIO\SQLIO.EXE -s120 -kR -frandom -b4 -t4 -o32 -LS -BH e:\Testfile.dat"

    Invoke-VMScript -VM $guestvms -ScriptText $myscript -GuestCredential $guestCredential



  • 7.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted May 30, 2013 12:41 PM

    If you want to be prompted for the credentials, you can use the Get-Credential cmdlet,

    Otherwise you can do something like this

    $username = "MyUserName"

    $password = ConvertTo-SecureString "MyPassword" -AsPlainText -Force

    $cred = New-Object -TypeName System.Management.Automation.PSCredential -Argumentlist $username,$password



  • 8.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted May 31, 2013 01:58 AM

    Hi Luc,

    Any chance you might be able to see where I'm going wrong here, I need to overwrite a txt file within a guest with this value "e:\testfile.dat 8 0x0 11000"

    $guestvms = "flash3"

    $myscript = "e:\testfile.dat 8 0x0 11000 | Out-File C:\SQLIO\param.txt"

    Invoke-VMScript -VM $guestvms -ScriptText $myscript -GuestUser administrator -GuestPassword Password



  • 9.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted May 31, 2013 05:50 AM

    The default ScriptType for Windows guest OS is PowerShell.

    So you probably have an error saying that there is an "unexpected token" or something along that line.

    You will have to make sure that PowerShell sees that first part as a [string], so place it between quotes.

    Something like this

    $guestvms = "flash3"
    $myscript = '"e:\testfile.dat 8 0x0 11000" | Out-File C:\SQLIO\param.txt'
    Invoke-VMScript -VM $guestvms -ScriptText $myscript -GuestUser administrator -GuestPassword Password

    Those are single quotes on the outside double quotes around the [string].



  • 10.  RE: Run Batch in Guest Remotely via PowerCLI

    Posted Jun 03, 2013 01:18 AM

    HI LuC,

    I need to maintain the Inventory of the Infrastructure so I need tha data Of  VMs in the  following format in the Excel please suggest the script

    This for Virtual Machine Inventory

    NAME  |  FQDN  | HDD(Assigned HDD Space)  |  Operating System  |  RAM|  CPU  |  NIC  |  IP ADDRESS   | DNS NAME

    This is for Host Inventory

    Server Name |FQDN | Operating System| Server IP Address | iDRAC IP Address | Domain| Model | Service Tag | Waranty status End Date

    Thanks

    PravinU.