1.Get-VIPermission
功能:检索在指定的清单对象中定义的权限。
语法:
Get-VIPermission [[-Entity] <VIObject[]>] [-Principal <VIAccount[]>] [-Server <VIServer[]>] [<CommonParameters>]
例子:
Get-VIPermission -Entity (Get-Datacenter) -Principal Administrator
2.New-VIPermission
功能:为清单对象中提供的用户和角色创建新的权限
语法:
New-VIPermission [-Entity] <VIObject[]> [-Principal] <VIAccount[]> [-Role] <Role> [-Propagate [<Boolean>]] [-Server <VIServer>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
New-VIRole -Name Role -Server $server -Privilege (Get-VIPrivilege -PrivilegeGroup) $permission = New-VIPermission -Role Role -Principal Administrator -Entity (Get-Datacenter)
3.Remove-VIPermission
功能:删除指定的权限。
语法:
Remove-VIPermission [-Permission] <Permission[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Remove-VIPermission -Permission $permission -Confirm:$false
4.Set-VIPermission
功能:修改指定的权限的属性。
语法:
Set-VIPermission [-Permission] <Permission[]> [-Role <Role>] [-Propagate [<Boolean>]] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Set-VIPermission -Permission $permission -Role Role -Propagate:$false
5.Get-VIPrivilege
功能:检索权限组所提供的服务和项目。
语法:
Get-VIPrivilege [-PrivilegeGroup] [-PrivilegeItem] [[-Name] <String[]>] [-Server <VIServer[]>] [<CommonParameters>]
Get-VIPrivilege [[-Name] <String[]>] [-Role] <Role[]> [<CommonParameters>]
Get-VIPrivilege [[-Name] <String[]>] [-Group] <PrivilegeGroup[]> [<CommonParameters>]
例子:
(1)
Get-VIPrivilege -Name "Host*"
(2)
Get-VIPrivilege –PrivilegeGroup
6.New-VIProperty
功能:新建一个指定对象类型的新扩展属性。
语法:
New-VIProperty [-Name] <String> [-ObjectType] <String[]> [-Value] <ScriptBlock> [-Force] [-BasedOnExtensionProperty <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-VIProperty [-Name] <String> [-ObjectType] <String[]> [-Force] [-ValueFromExtensionProperty] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)
New-VIProperty -ObjectType VirtualMachine -Name CommittedSpaceMB -Value { $vm = $args[0]; $sum = 0; $vm.ExtensionData.Storage.PerDatastoreUsage | foreach { $sum += $_.Committed} ; $sum = [int]($sum / 1024 / 1024); return $sum } Get-VM | select Name, CommittedSpaceMB
(2)
New-VIProperty -ObjectType VirtualMachine -Name CommittedSpaceMB -Value { $vm = $args[0]; $sum = 0; $vm.ExtensionData.Storage.PerDatastoreUsage | foreach { $sum += $_.Committed} ; $sum = [int]($sum / 1024 / 1024); return $sum } -BasedOnExtensionProperty 'Storage.PerDatastoreUsage.Committed' -Force Get-VM | select Name, CommittedSpaceMB
(3)
New-VIProperty -ObjectType VirtualMachine -Name CommittedSpace -ValueFromExtensionProperty 'SUM Storage.PerDatastoreUsage.Committed'
(4)
New-VIProperty -ObjectType InventoryItem -Name OverallStatus -ValueFromExtensionProperty 'OverallStatus' Get-VM | select Name, OverallStatus Get-VMHost | select Name, OverallStatus
(5)
New-VIProperty -ObjectType VIObjectCore -Value { if ( $args[0].UId -match "/VIserver=[\w]+@(.*):.*" ) { $matches[1] } else { " } } -Name VIServerName Get-Inventory | select Name, VIServerName
7.Remove-VIProperty
功能:移除指定的对象类型的扩展属性。
语法:
Remove-VIProperty [-Name] <String[]> [-ObjectType] <String[]> [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)
Remove-VIProperty -Name * -ObjectType *
(2)
Remove-VIProperty -Name * -ObjectType VirtualMachine
(3)
Remove-VIProperty -Name OverallStatus, ConfigStatus -ObjectType VirtualMachine
(4)
Remove-VIProperty -Name OverallStatus -ObjectType VirtualMachine, Datacenter
(5)
Remove-VIProperty -Name *status* -ObjectType Virt*
8.Get-VIRole
功能:检索所所有角色提供的服务
语法:
Get-VIRole [[-Name] <String[]>] [-Server <VIServer[]>] [<CommonParameters>]
例子:
Get-VIRole -Server $server -Name "Admin*"
9.New-VIRole
功能:创建一个指定的服务上新的角色和应用提供特权。
语法:
New-VIRole [-Name] <String> [[-Privilege] <Privilege[]>] [-Server <VIServer>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
New-VIRole -Name Role -Privilege (Get-VIPrivilege -PrivilegeGroup)
10.Remove-VIRole
功能:删除指定的角色。
语法:
Remove-VIRole [-Role] <Role[]> [-Force] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Get-VIRole -Server $server -Name "Customer*" | Remove-VIRole
11.Set-VIRole
功能:修改所提供的角色的特权。
语法:
Set-VIRole [-Role] <Role[]> [-Name <String>] [-AddPrivilege <Privilege[]>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-VIRole [-Role] <Role[]> [-Name <String>] [-RemovePrivilege <Privilege[]>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Set-VIRole -Role Role -AddPrivilege (Get-VIPrivilege -Name 'Create Datacenter')
12.Connect-VIServer
功能:连接到vSphere服务器。
语法:
Connect-VIServer [[-Server] <String[]>] [-Port <Int32>] [-Protocol <String>] [-Credential <PSCredential>] [-User <String>] [-Password <String>] [-Session <String>] [-NotDefault] [-SaveCredentials] [<CommonParameters>]
Connect-VIServer -Menu [<CommonParameters>]
例子:
(1)
Connect-VIServer -Server 10.23.112.235 -Protocol https -User admin -Password pass
(2)
$srv = Connect-VIServer 10.23.115.133 -User admin -Password pass Connect-VIServer 10.23.115.133 -Session $srv.SessionId
13.Disconnect-VIServer
功能:从vSphere的服务器断开。
语法:
Disconnect-VIServer [[-Server] <VIServer[]>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
(1)
$Server = Connect-VIServer 10.23.112.235 Disconnect-VIServer -Server $Server
(2)
Disconnect-VIServer -Server $global:DefaultVIServers –Force
(3)
Disconnect-VIServer -Server * –Force
14.Add-VMHost
功能:添加一个由一个vSphere服务器托管主机。
语法:
Add-VMHost [-Name] <String> [-Port <Int32>] [-Location] <VIContainer> [-Credential <PSCredential>] [-User <String>] [-Password <String>] [-Force] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Add-VMHost 10.23.113.24 -Location Datacenter -User root -Password pass
15.Get-VMHost
功能:检索在vSphere服务器上的主机。
语法:
Get-VMHost [-Datastore <Datastore[]>] [-State <VMHostState[]>] [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]
Get-VMHost [-VM <VirtualMachine[]>] [-ResourcePool <ResourcePool[]>] [-Datastore <Datastore[]>] [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]
Get-VMHost [-DistributedSwitch <DistributedSwitch[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]
例子:
Get-VMHost -Location Datacenter -VM VM | fl
16.Remove-VMHost
功能:从清单中删除指定的主机。
语法:
Remove-VMHost [-VMHost] <VMHost[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
例子:
Remove-VMHost 10.22.112.235
17.Get-VMHostStorage
功能:检索主机上的vSphere服务器存储。
语法:
Get-VMHostStorage [-VMHost] <VMHost[]> [-Refresh] [-RescanAllHba] [-RescanVmfs] [-Server <VIServer[]>] [<CommonParameters>]
例子:
(1)
Get-VmHostStorage -VMHost 10.23.112.234 –Refresh
(2)
Get-VMHostStorage | select -expandproperty scsilun | fl *