Options

Powershell script for vmware linux guests

dalesdales Member Posts: 225
Hi all,

Wondering if I could ask for some advice please. I have a simple script that outputs linux guests date/time (checking for the time drift issue), I've got it to output to a file but its not much use at the moment because I'm not sure how to get it to also echo out the current vm name. Does anyone know if this is possible from within the invoke-vmscript commandlet or even if I pipe it in someway before passing it to the txt file.

Script currently looks like this!

Invoke-VMScript -VM (Get-VM) -GuestCredential (Get-Credential) -HostCredential (Get-Credential) -ScriptText "date" -ScriptType Bash | out-file list.txt


Output currently looks like this!

Wed May 19 14:17:18 BST 2010

Wed May 19 14:17:24 BST 2010

Wed May 19 14:17:52 BST 2010


thanks in advance
Dale
Kind Regards
Dale Scriven

Twitter:dscriven
Blog: vhorizon.co.uk

Comments

  • Options
    sambuca69sambuca69 Member Posts: 262
    dales wrote: »
    Hi all,

    Wondering if I could ask for some advice please. I have a simple script that outputs linux guests date/time (checking for the time drift issue), I've got it to output to a file but its not much use at the moment because I'm not sure how to get it to also echo out the current vm name. Does anyone know if this is possible from within the invoke-vmscript commandlet or even if I pipe it in someway before passing it to the txt file.

    Script currently looks like this!

    Invoke-VMScript -VM (Get-VM) -GuestCredential (Get-Credential) -HostCredential (Get-Credential) -ScriptText "date" -ScriptType Bash | out-file list.txt


    Output currently looks like this!

    Wed May 19 14:17:18 BST 2010

    Wed May 19 14:17:24 BST 2010

    Wed May 19 14:17:52 BST 2010


    thanks in advance
    Dale

    So you want it to write to a file, lets say and then work with the object again and echo it on screen?

    You can use tee-object for that.. so you have your script, then pipe it something like: script here | tee-object C:\scripts\MyReport.txt | write-host , etc
  • Options
    ClaymooreClaymoore Member Posts: 1,637
    Any reason why you want to document the time drift rather than fix it?

    Synchronizing the Time in the Guest with the Host Operating System
  • Options
    dalesdales Member Posts: 225
    Yes looking to fix the time drift issue but as we still have servers to p2v it would be a script that I would like to run every once in a while just to keep a check on things. Thanks sambuca for the suggestions I'll have a fiddle with that tomorrow when I get back to work.
    Kind Regards
    Dale Scriven

    Twitter:dscriven
    Blog: vhorizon.co.uk
  • Options
    astorrsastorrs Member Posts: 3,139 ■■■■■■□□□□
    dales wrote: »
    Does anyone know if this is possible from within the invoke-vmscript commandlet or even if I pipe it in someway before passing it to the txt file.
    While you could do it a number of different ways using PowerCLI, why not just change the date command (-ScriptText parameter) you're invoking on the Linux VMs to hostname; date or if that doesn't work try echo 'hostname; date'
Sign In or Register to comment.