vSphere PowerCLI安装及命令

本周一晚新公司部门部分人员聚餐,圆桌九人围坐,80后占其八,皆五年以上IT龄,老大为长者。

席间玩一游戏,找众将之共同点,

一人曰,有白发者喝酒,众将皆举杯,皆尽。
 


 

  • 首先到官方网站下载VMware vSphere PowerCLI的软件包,

     

  • 安装软件到本机,

  • 运行后提示:”无法加载文件c:\program Files\vmware\infrastructure\vsphere powerCLI\script\initialize-vitoolkitenviroment.ps1,因为在此系统中禁止执行脚本。有关信息,请查阅“get-help about_signing”.

  • 通过get-executionpolicy查看本地执行策略

  • 更改执行策略

  • 更改为RemoteSigned执行策略

备注:

Restricted 执行策略不允许任何脚本运行。 
AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。

  • 再次运行VMware vSphere PowerCLI,提示”Welcome“界面,工具正常启动。

  • 输入Connect-VIServer ,连接上vCenter服务器

  • 输入vCenter的登录用户名和密码。

  • 接下来输入Get-vm,可以看到vCenter下管理的所有虚机得名称,运行状态,CPU的数量,内存大小参数。

  • 再实现下虚拟机的启动命令,这里选择”WinServer01_1”这台虚拟服务器,输入Get-VM WinServer01_1 | start-vm,5S之后可以从vCenter控制台的任务栏中看出虚拟机正在启动中

 

  • 通过Get-vmguest winserver01_1 | fc 查看服务器参数未能得出结果,

  • 更换vCenter虚拟机试下这个命令 Get-vmguest vcenter | fc ,从而得到下面一长串虚拟机信息参数。

class VMGuestImpl
{
  OSFullName = Microsoft Windows Server 2003 (64 位)
  IPAddress =
    [
      10.X.X.X.
    ]

  State = ShuttingDown
  Disks =
    [
      class DiskInfoImpl
      {
        Path = C:\
        Capacity = 32201936896
        FreeSpace = 17221709824
      }
    ]

  HostName = vcenter.view.test
  Nics =
    [
      class NicInfoImpl
      {
        Connected = True
        Device =
          class NetworkAdapterImpl
          {
            MacAddress = 00:0c:00:00:00:00

            WakeOnLanEnabled = True
            NetworkName = VM Network
            Type = Vmxnet
            ConnectionState =
              class ConnectInfoImpl
              {
                AllowGuestControl = True
                Connected = True
                StartConnected = True
              }
            Id = VirtualMachine-vm-16/4000
            Name = 网络适配器 1
          }
        IPAddress =
          [
            10.X.X.X          ]

        MacAddress = 00:0c:00:00:00:00

        NetworkName = VM Network
      }
    ]

  ScreenDimensions =
    class Size
    {
      IsEmpty = False
      Width = 800
      Height = 600
    }
  VmId =
    class MoId
    {
      Id = VirtualMachine-vm-16
    }
  VmName = vCenter
}

class VMGuestImpl
{
  OSFullName = Microsoft Windows Server 2003 (64 位)
  IPAddress =
    [
      x.x.x.y   ]

  State = Running
  Disks =
    [
      class DiskInfoImpl
      {
        Path = C:\
        Capacity = 32201936896
        FreeSpace = 15573364736
      }
    ]

  HostName = vcenter.view.test
  Nics =
    [
      class NicInfoImpl
      {
        Connected = True
        Device =
          class NetworkAdapterImpl
          {
            MacAddress = 00:0c:,,,
            WakeOnLanEnabled = True
            NetworkName = VM Network
            Type = Vmxnet
            ConnectionState =
              class ConnectInfoImpl
              {
                AllowGuestControl = True
                Connected = True
                StartConnected = True
              }
            Id = VirtualMachine-vm-121/4000
            Name = 网络适配器 1
          }
        IPAddress =
          [
            x.x.x.y          ]

        MacAddress = 00:0c:…

        NetworkName = VM Network
      }
    ]

  ScreenDimensions =
    class Size
    {
      IsEmpty = False
      Width = 800
      Height = 600
    }
  VmId =
    class MoId
    {
      Id = VirtualMachine-vm-121
    }
  VmName = vCenter
}

  • 新建虚拟机的命令

New-vm -vmhost esxi01.vmanager.cn -name svr01 -template win2008r2 win2008r2_template -datastore datastore1 -oscustomizationspec win2008r2_template

-vmhost:VM生成的目标ESXi主机;
-Name:生成的VM的名字;
-Template:用于生成VM的模板主机;
-Datastore:生成的虚拟机的存放数据存储;
-OSCustomizationspec:定制化部署VM的prep目录;

(网上看到虚拟人的文档,谢啦)

以上都是些比较单一的命令,其功能强大之处体现在批量执行脚本,达到大规模配置的目的,后面会更新批量部署脚本的记录,谢谢。

你可能感兴趣的:(vSphere PowerCLI安装及命令)