PowerCLI

  • 1.  Upgrade tools based on a CSV File

    Posted Sep 30, 2008 05:47 PM

    Basically I have defined outage windows for various servers. These windows are record in my SMS enviroment as it uses them to push patches to the servers during the windows. I have a script that dumps the contents of each windows collection in SMS to .CSV files. I would like to run a routine that would do a tools upgrade on the guest during it window as well. I am having no luck with the code at the moment. I am a good vbscripter but very new to power shell and I need some help.

    Get-VC Vcenter | Impot-CSV c:\serverlist1.csv| Get-VM| Update-Tools

    Sample of serverlist1.csv

    Name

    server1

    Server2

    server3

    Basically Get-VM keeps comming back saying it cant use the piped information



  • 2.  RE: Upgrade tools based on a CSV File

    Posted Sep 30, 2008 05:57 PM

    Basically I have defined outage windows for various servers. These windows are record in my SMS enviroment as it uses them to push patches to the servers during the windows. I have a script that dumps the contents of each windows collection in SMS to .CSV files. I would like to run a routine that would do a tools upgrade on the guest during it window as well. I am having no luck with the code at the moment. I am a good vbscripter but very new to power shell and I need some help.

    Get-VC Vcenter | Impot-CSV c:\serverlist1.csv| Get-VM| Update-Tools

    Sample of serverlist1.csv

    Name

    server1

    Server2

    server3

    Basically Get-VM keeps comming back saying it cant use the piped information

    Hi,

    First is that we recommend using Connect-VIServer rather than Get-VC, also it should be on its own line.

    Import-CSV will return a list. You can pipe this into a foreach loop like this:

    connect-viserver YOURSERVER
    import-csv YOURFILE | foreach {
       Get-VM $_.Name | Update-Tools
    }
    

    This assumes that your CSV file has a column called Name that specifies the VM's name.