Compare commits
30 Commits
Reorg
...
VMFSIncrea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dda8cc639 | ||
|
|
99250732fb | ||
|
|
7bbec511cb | ||
|
|
b2ba87db86 | ||
|
|
7392e451c5 | ||
|
|
1489e86b66 | ||
|
|
7a38462f1a | ||
|
|
ddfb85780f | ||
|
|
06a3ea0210 | ||
|
|
172e1436c5 | ||
|
|
e1937544fb | ||
|
|
7f6482b7af | ||
|
|
f47c3a7c3b | ||
|
|
e91b0c0649 | ||
|
|
ca70d01e54 | ||
|
|
1dff599996 | ||
|
|
2e25d166a0 | ||
|
|
e709f1fdde | ||
|
|
c432a0d1fa | ||
|
|
99673b1dfa | ||
|
|
3403db0ead | ||
|
|
2f595f086d | ||
|
|
e7c968d32b | ||
|
|
8469b3a285 | ||
|
|
456bd28b45 | ||
|
|
32096f6e02 | ||
|
|
c8b2607b94 | ||
|
|
eae378822b | ||
|
|
4464bf001b | ||
|
|
06d3eed37d |
6
Modules/VMFSIncrease/LICENSE.txt.URL
Normal file
6
Modules/VMFSIncrease/LICENSE.txt.URL
Normal file
@@ -0,0 +1,6 @@
|
||||
[InternetShortcut]
|
||||
URL=https://github.com/lucdekens/LogInsight/blob/v1.0/LICENSE.txt
|
||||
IDList=
|
||||
HotKey=0
|
||||
IconFile=C:\Users\ldekens\AppData\Local\Mozilla\Firefox\Profiles\2ahnnh1i.default\shortcutCache\ec4nFcIEAQBPFmSiPtTJ2w==.ico
|
||||
IconIndex=0
|
||||
18
Modules/VMFSIncrease/VMFSIncrease.psd1
Normal file
18
Modules/VMFSIncrease/VMFSIncrease.psd1
Normal file
@@ -0,0 +1,18 @@
|
||||
@{
|
||||
ModuleToProcess = 'VMFSIncrease.psm1'
|
||||
ModuleVersion = '1.0.0.0'
|
||||
GUID = '9f167385-c5c6-4a65-ac14-949c67519001'
|
||||
Author = 'Luc Dekens '
|
||||
CompanyName = 'Community'
|
||||
Copyright = '(c) 2016. All rights reserved.'
|
||||
Description = 'Expand and Extend VMFS DatastoresModule description'
|
||||
PowerShellVersion = '3.0'
|
||||
FunctionsToExport = 'Get-VmfsDatastoreInfo','Get-VmfsDatastoreIncrease','New-VmfsDatastoreIncrease'
|
||||
PrivateData = @{
|
||||
PSData = @{
|
||||
Tags = @('VMFS','Expand','Extend','vSphere')
|
||||
LicenseUri = 'https://www.tldrlegal.com/l/mit'
|
||||
ProjectUri = 'https://github.com/lucdekens/VMFSIncrease'
|
||||
}
|
||||
}
|
||||
}
|
||||
247
Modules/VMFSIncrease/VMFSIncrease.psm1
Normal file
247
Modules/VMFSIncrease/VMFSIncrease.psm1
Normal file
@@ -0,0 +1,247 @@
|
||||
function Get-VmfsDatastoreInfo
|
||||
{
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param (
|
||||
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $True)]
|
||||
[PSObject]$Datastore
|
||||
)
|
||||
|
||||
Process
|
||||
{
|
||||
if ($Datastore -is [String])
|
||||
{
|
||||
$Datastore = Get-Datastore -Name $Datastore -ErrorAction SilentlyContinue
|
||||
}
|
||||
if ($Datastore -isnot [VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.Datastore])
|
||||
{
|
||||
Write-Error 'Invalid value for Datastore.'
|
||||
return
|
||||
}
|
||||
if ($Datastore.Type -ne 'VMFS')
|
||||
{
|
||||
Write-Error "$($Datastore.Name) is not a VMFS datastore"
|
||||
return
|
||||
}
|
||||
|
||||
# Get the Datastore System Manager from an ESXi that has the Datastore
|
||||
$esx = Get-View -Id ($Datastore.ExtensionData.Host | Get-Random | Select -ExpandProperty Key)
|
||||
$hsSys = Get-View -Id $esx.ConfigManager.StorageSystem
|
||||
|
||||
foreach ($extent in $Datastore.ExtensionData.Info.Vmfs.Extent)
|
||||
{
|
||||
$lun = $esx.Config.StorageDevice.ScsiLun | where{ $_.CanonicalName -eq $extent.DiskName }
|
||||
|
||||
$hdPartInfo = $hsSys.RetrieveDiskPartitionInfo($lun.DeviceName)
|
||||
$hdPartInfo[0].Layout.Partition | %{
|
||||
New-Object PSObject -Property ([ordered]@{
|
||||
Datastore = $Datastore.Name
|
||||
CanonicalName = $lun.CanonicalName
|
||||
Model = "$($lun.Vendor.TrimEnd(' ')).$($lun.Model.TrimEnd(' ')).$($lun.Revision.TrimEnd(' '))"
|
||||
DiskSizeGB = $hdPartInfo[0].Layout.Total.BlockSize * $hdPartInfo[0].Layout.Total.Block / 1GB
|
||||
DiskBlocks = $hdPartInfo[0].Layout.Total.Block
|
||||
DiskBlockMB = $hdPartInfo[0].Layout.Total.BlockSize/1MB
|
||||
PartitionFormat = $hdPartInfo[0].Spec.PartitionFormat
|
||||
Partition = if ($_.Partition -eq '') { '<free>' }else{ $_.Partition }
|
||||
Used = $extent.Partition -eq $_.Partition
|
||||
Type = $_.Type
|
||||
PartitionSizeGB = [math]::Round(($_.End.Block - $_.Start.Block + 1) * $_.Start.BlockSize / 1GB, 1)
|
||||
PartitionBlocks = $_.End.Block - $_.Start.Block + 1
|
||||
PartitionBlockMB = $_.Start.BlockSize/1MB
|
||||
Start = $_.Start.Block
|
||||
End = $_.End.Block
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Get-VmfsDatastoreIncrease
|
||||
{
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param (
|
||||
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $True)]
|
||||
[PSObject]$Datastore
|
||||
)
|
||||
|
||||
Process
|
||||
{
|
||||
if ($Datastore -is [String])
|
||||
{
|
||||
$Datastore = Get-Datastore -Name $Datastore -ErrorAction SilentlyContinue
|
||||
}
|
||||
if ($Datastore -isnot [VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.Datastore])
|
||||
{
|
||||
Write-Error 'Invalid value for Datastore.'
|
||||
return
|
||||
}
|
||||
|
||||
if ($Datastore.Type -ne 'VMFS')
|
||||
{
|
||||
Write-Error "$($Datastore.Name) is not a VMFS datastore"
|
||||
return
|
||||
}
|
||||
|
||||
# Get the Datastore System Manager from an ESXi that has the Datastore
|
||||
$esx = Get-View -Id ($Datastore.ExtensionData.Host | Get-Random | Select -ExpandProperty Key)
|
||||
$hsSys = Get-View -Id $esx.ConfigManager.StorageSystem
|
||||
$hdSys = Get-View -Id $esx.ConfigManager.DatastoreSystem
|
||||
|
||||
$extents = $Datastore.ExtensionData.Info.Vmfs.Extent | Select -ExpandProperty DiskName
|
||||
|
||||
$hScsiDisk = $hdSys.QueryAvailableDisksForVmfs($Datastore.ExtensionData.MoRef)
|
||||
foreach ($disk in $hScsiDisk)
|
||||
{
|
||||
$partInfo = $hsSys.RetrieveDiskPartitionInfo($disk.DeviceName)
|
||||
$partUsed = ($partInfo[0].Layout.Partition | where{ $_.Type -eq 'VMFS' } | %{ ($_.End.Block - $_.Start.Block + 1) * $_.Start.BlockSize } |
|
||||
Measure-Object -Sum | select -ExpandProperty Sum)/1GB
|
||||
if ($extents -contains $disk.CanonicalName)
|
||||
{
|
||||
$incType = 'Expand'
|
||||
$vmfsExpOpt = $hdSys.QueryVmfsDatastoreExpandOptions($Datastore.ExtensionData.MoRef)
|
||||
$PartMax = ($vmfsExpOpt[0].Info.Layout.Partition | where{ $_.Type -eq 'VMFS' } | %{ ($_.End.Block - $_.Start.Block + 1) * $_.Start.BlockSize } |
|
||||
Measure-Object -Sum | select -ExpandProperty Sum)/1GB
|
||||
}
|
||||
else
|
||||
{
|
||||
$incType = 'Extend'
|
||||
$vmfsExtOpt = $hdSys.QueryVmfsDatastoreExtendOptions($Datastore.ExtensionData.MoRef, $disk.DevicePath, $null)
|
||||
$partMax = ($vmfsExpOpt[0].Info.Layout.Partition | where{ $_.Type -eq 'VMFS' } | %{ ($_.End.Block - $_.Start.Block + 1) * $_.Start.BlockSize } |
|
||||
Measure-Object -Sum | select -ExpandProperty Sum)/1GB
|
||||
}
|
||||
New-Object PSObject -Property ([ordered]@{
|
||||
Datastore = $Datastore.Name
|
||||
CanonicalName = $disk.CanonicalName
|
||||
Model = "$($disk.Vendor.TrimEnd(' ')).$($disk.Model.TrimEnd(' ')).$($disk.Revision.TrimEnd(' '))"
|
||||
DiskSizeGB = $partInfo[0].Layout.Total.BlockSize * $partInfo[0].Layout.Total.Block / 1GB
|
||||
DiskBlocks = $partInfo[0].Layout.Total.Block
|
||||
DiskBlockMB = $partInfo[0].Layout.Total.BlockSize/1MB
|
||||
AvailableGB = [math]::Round($partMax - $partUsed, 2)
|
||||
Type = $incType
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function New-VmfsDatastoreIncrease
|
||||
{
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param (
|
||||
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $True)]
|
||||
[PSObject]$Datastore,
|
||||
[int]$IncreaseSizeGB,
|
||||
[Parameter(Position = 1)]
|
||||
[string]$CanonicalName,
|
||||
[Parameter(Mandatory = $true, ParameterSetName = 'Expand')]
|
||||
[switch]$Expand,
|
||||
[Parameter(Mandatory = $true, ParameterSetName = 'ExTend')]
|
||||
[switch]$Extend
|
||||
)
|
||||
|
||||
Process
|
||||
{
|
||||
if ($Datastore -is [String])
|
||||
{
|
||||
$Datastore = Get-Datastore -Name $Datastore -ErrorAction SilentlyContinue
|
||||
}
|
||||
if ($Datastore -isnot [VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.Datastore])
|
||||
{
|
||||
Write-Error 'Invalid value for Datastore.'
|
||||
return
|
||||
}
|
||||
|
||||
if ($Datastore.Type -ne 'VMFS')
|
||||
{
|
||||
Write-Error "$($Datastore.Name) is not a VMFS datastore"
|
||||
return
|
||||
}
|
||||
|
||||
# Get the Datastore System Manager from an ESXi that has the Datastore
|
||||
$esx = Get-View -Id ($Datastore.ExtensionData.Host | Get-Random | Select -ExpandProperty Key)
|
||||
$hsSys = Get-View -Id $esx.ConfigManager.StorageSystem
|
||||
$hdSys = Get-View -Id $esx.ConfigManager.DatastoreSystem
|
||||
|
||||
$extents = $Datastore.ExtensionData.Info.Vmfs.Extent | Select -ExpandProperty DiskName
|
||||
|
||||
$hScsiDisk = $hdSys.QueryAvailableDisksForVmfs($Datastore.ExtensionData.MoRef)
|
||||
|
||||
# Expand or Extend
|
||||
switch ($PSCmdlet.ParameterSetName)
|
||||
{
|
||||
'Expand' {
|
||||
$expOpt = $hdSys.QueryVmfsDatastoreExpandOptions($Datastore.ExtensionData.MoRef)
|
||||
if ($CanonicalName)
|
||||
{
|
||||
$dsOpt = $expOpt | where{ $_.Spec.Extent.DiskName -eq $CanonicalName }
|
||||
}
|
||||
else
|
||||
{
|
||||
$dsOpt = $expOpt | Sort-Object -Property { $_.Spec.Extent.Diskname } | select -first 1
|
||||
}
|
||||
if ($IncreaseSizeGB -ne 0)
|
||||
{
|
||||
$lun = $hScsiDisk | where{ $_.CanonicalName -eq $dsOpt.Spec.Extent.DiskName }
|
||||
$partInfo = $hsSys.RetrieveDiskPartitionInfo($lun.DeviceName)
|
||||
$partMax = ($expOpt[0].Info.Layout.Partition | where{ $_.Type -eq 'VMFS' } | %{ ($_.End.Block - $_.Start.Block + 1) * $_.Start.BlockSize } |
|
||||
Measure-Object -Sum | select -ExpandProperty Sum)/1GB
|
||||
$partUsed = ($partInfo[0].Layout.Partition | where{ $_.Type -eq 'VMFS' } | %{ ($_.End.Block - $_.Start.Block + 1) * $_.Start.BlockSize } |
|
||||
Measure-Object -Sum | select -ExpandProperty Sum)/1GB
|
||||
if (($partMax - $partUsed) -ge $IncreaseSizeGB)
|
||||
{
|
||||
$spec = $dsOpt.Spec
|
||||
$spec.Partition.Partition[0].EndSector -= ([math]::Floor(($partMax - $partUsed - $IncreaseSizeGB) * 1GB/512))
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Error "Requested expand size $($IncreaseSizeGB)GB not available on $($lun.CanonicalName)"
|
||||
return
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$spec = $dsOpt.Spec
|
||||
}
|
||||
$hdSys.ExpandVmfsDatastore($Datastore.ExtensionData.MoRef, $spec)
|
||||
}
|
||||
'Extend' {
|
||||
if ($CanonicalName)
|
||||
{
|
||||
$lun = $hScsiDisk | where{ $extents -notcontains $_.CanonicalName -and $_.CanonicalName -eq $CanonicalName }
|
||||
}
|
||||
else
|
||||
{
|
||||
$lun = $hScsiDisk | where{ $extents -notcontains $_.CanonicalName } | Sort-Object -Property CanonicalName | select -First 1
|
||||
}
|
||||
if (!$lun)
|
||||
{
|
||||
Write-Error "No valid LUN provided or found for extent"
|
||||
return
|
||||
}
|
||||
$vmfsExtOpt = $hdSys.QueryVmfsDatastoreExtendOptions($Datastore.ExtensionData.MoRef, $lun.DevicePath, $null)
|
||||
if ($IncreaseSizeGB -ne 0)
|
||||
{
|
||||
$partInfo = $hsSys.RetrieveDiskPartitionInfo($lun.DeviceName)
|
||||
$partMax = ($vmfsExpOpt[0].Info.Layout.Partition | where{ $_.Type -eq 'VMFS' } | %{ ($_.End.Block - $_.Start.Block + 1) * $_.Start.BlockSize } |
|
||||
Measure-Object -Sum | select -ExpandProperty Sum)/1GB
|
||||
if ($partMax -ge $IncreaseSizeGB)
|
||||
{
|
||||
$spec = $vmfsExtOpt[0].Spec
|
||||
$spec.Partition.Partition[0].EndSector = $spec.Partition.Partition[0].StartSector + [math]::Floor($IncreaseSizeGB * 1GB / 512)
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Error "No valid LUN for extent with $($IncreaseSizeGB)GB space found"
|
||||
return
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$spec = $vmfsExtOpt.Spec
|
||||
}
|
||||
|
||||
$hdSys.ExtendVmfsDatastore($Datastore.ExtensionData.MoRef, $spec)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Get-VmfsDatastoreInfo,Get-VmfsDatastoreIncrease,New-VmfsDatastoreIncrease
|
||||
473
Modules/VMFSIncrease/en-US/VMFSIncrease.psm1-Help.xml
Normal file
473
Modules/VMFSIncrease/en-US/VMFSIncrease.psm1-Help.xml
Normal file
@@ -0,0 +1,473 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<helpItems xmlns="http://msh" schema="maml">
|
||||
<!--Edited with: SAPIEN PowerShell HelpWriter 2015 v1.0.16-->
|
||||
<!--Generated by: SAPIEN PowerShell HelpWriter 2015 v1.0.16-->
|
||||
<!--
|
||||
Module: VMFSIncrease
|
||||
Version: 1.0.0.0
|
||||
-->
|
||||
<!--All Commands-->
|
||||
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
|
||||
<!--Command-->
|
||||
<command:details>
|
||||
<command:name>Get-VmfsDatastoreInfo</command:name>
|
||||
<maml:description>
|
||||
<maml:para>Provides partition information for all the extents in the datastore.</maml:para>
|
||||
</maml:description>
|
||||
<maml:copyright>
|
||||
<maml:para/>
|
||||
</maml:copyright>
|
||||
<command:verb>Get</command:verb>
|
||||
<command:noun>VmfsDatastoreInfo</command:noun>
|
||||
<dev:version/>
|
||||
</command:details>
|
||||
<maml:description>
|
||||
<maml:para>The function will display partition information for all the extents used by the datastore.</maml:para>
|
||||
</maml:description>
|
||||
<command:syntax>
|
||||
<!--Parameter Sets-->
|
||||
<command:syntaxItem>
|
||||
<maml:name>Get-VmfsDatastoreInfo</maml:name>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="">
|
||||
<maml:name>Datastore</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The name of the Datastore or a PowerCLI Datastore object</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
</command:syntaxItem>
|
||||
</command:syntax>
|
||||
<command:parameters>
|
||||
<!--All Parameters-->
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="">
|
||||
<maml:name>Datastore</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The name of the Datastore or a PowerCLI Datastore object</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
|
||||
<dev:type>
|
||||
<maml:name>PSObject</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
</command:parameters>
|
||||
<command:inputTypes>
|
||||
<!--Inputs-->
|
||||
<command:inputType>
|
||||
<dev:type>
|
||||
<maml:name>System.Management.Automation.PSObject
|
||||
</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<maml:description>
|
||||
<maml:para/>
|
||||
</maml:description>
|
||||
</command:inputType>
|
||||
</command:inputTypes>
|
||||
<command:returnValues>
|
||||
<!--Outputs-->
|
||||
<command:returnValue>
|
||||
<dev:type>
|
||||
<maml:name>System.Object</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<maml:description>
|
||||
<maml:para/>
|
||||
</maml:description>
|
||||
</command:returnValue>
|
||||
</command:returnValues>
|
||||
<command:examples>
|
||||
<!--Examples-->
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 1 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>Get-VmfsDatastoreInfo -Datastore MyDS</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>Will return partition information for the Datastore named MyDS</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 2 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>Get-Datastore -Name My* | Get-VmfsDatastoreInfo</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>This example will return partition information for all the Datastore objects that are returned by the Get-Datastore PowerCLI cmdlet</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
</command:examples>
|
||||
</command:command>
|
||||
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
|
||||
<!--Command-->
|
||||
<command:details>
|
||||
<command:name>Get-VmfsDatastoreIncrease</command:name>
|
||||
<maml:description>
|
||||
<maml:para>Displays the increase options for a datastore</maml:para>
|
||||
</maml:description>
|
||||
<maml:copyright>
|
||||
<maml:para/>
|
||||
</maml:copyright>
|
||||
<command:verb>Get</command:verb>
|
||||
<command:noun>VmfsDatastoreIncrease</command:noun>
|
||||
<dev:version/>
|
||||
</command:details>
|
||||
<maml:description>
|
||||
<maml:para>The function will provide all the Expand and Extend options for a specific datastore</maml:para>
|
||||
</maml:description>
|
||||
<command:syntax>
|
||||
<!--Parameter Sets-->
|
||||
<command:syntaxItem>
|
||||
<maml:name>Get-VmfsDatastoreIncrease</maml:name>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="">
|
||||
<maml:name>Datastore</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The name of the Datastore or a PowerCLI Datastore object</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
</command:syntaxItem>
|
||||
</command:syntax>
|
||||
<command:parameters>
|
||||
<!--All Parameters-->
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="">
|
||||
<maml:name>Datastore</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The name of the Datastore or a PowerCLI Datastore object</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
|
||||
<dev:type>
|
||||
<maml:name>PSObject</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
</command:parameters>
|
||||
<command:inputTypes>
|
||||
<!--Inputs-->
|
||||
<command:inputType>
|
||||
<dev:type>
|
||||
<maml:name>System.Management.Automation.PSObject
|
||||
</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<maml:description>
|
||||
<maml:para/>
|
||||
</maml:description>
|
||||
</command:inputType>
|
||||
</command:inputTypes>
|
||||
<command:returnValues>
|
||||
<!--Outputs-->
|
||||
<command:returnValue>
|
||||
<dev:type>
|
||||
<maml:name>System.Object</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<maml:description>
|
||||
<maml:para/>
|
||||
</maml:description>
|
||||
</command:returnValue>
|
||||
</command:returnValues>
|
||||
<command:examples>
|
||||
<!--Examples-->
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 1 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>Get-VmfsDatastoreIncrease -Datastore MyDS</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>The exmaple will list all Expand and Extend options available for the Datastore, named MyDS</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 2 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>Get-Datastore -Name MyDS* | Get-VmfsDatastoreIncrease</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>The Expand and Extend options for all Datastore retruned by the PowerCLI Get-Datastore will be returned.</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
</command:examples>
|
||||
</command:command>
|
||||
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
|
||||
<!--Command-->
|
||||
<command:details>
|
||||
<command:name>New-VmfsDatastoreIncrease</command:name>
|
||||
<maml:description>
|
||||
<maml:para>Increase the capacity of a Datastore</maml:para>
|
||||
</maml:description>
|
||||
<maml:copyright>
|
||||
<maml:para/>
|
||||
</maml:copyright>
|
||||
<command:verb>New</command:verb>
|
||||
<command:noun>VmfsDatastoreIncrease</command:noun>
|
||||
<dev:version/>
|
||||
</command:details>
|
||||
<maml:description>
|
||||
<maml:para>The capacity of the Datastore in increased through an Expand or an Extend.
|
||||
To allow successful completion there shall be free capacity on one of the Extents, or there shall be free LUNs available.
|
||||
With the Expand or Extend switches the caller selects which type of capacity increase is used.</maml:para>
|
||||
</maml:description>
|
||||
<command:syntax>
|
||||
<!--Parameter Sets-->
|
||||
<command:syntaxItem>
|
||||
<maml:name>New-VmfsDatastoreIncrease</maml:name>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="">
|
||||
<maml:name>Datastore</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The name of the Datastore or a PowerCLI Datastore object</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1" aliases="">
|
||||
<maml:name>CanonicalName</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The Canonical name of the LUN on which to create a new Extent, or the name of the LUN on which to apply the Expansion.
|
||||
If this parameter is not provided, the function will sort the available LUN alphanumerically on the Canonical names and slect the first one.</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
|
||||
<maml:name>IncreaseSizeGB</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The amount of GB by which to increase the size of the Datastore.
|
||||
If this parameter is not used, all of the available Expand or Extend diskspace will be used.</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">Int32</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
|
||||
<maml:name>Expand</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>A switch to indicate if the Datastore shall be Expanded</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
</command:syntaxItem>
|
||||
<command:syntaxItem>
|
||||
<maml:name>New-VmfsDatastoreIncrease</maml:name>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="">
|
||||
<maml:name>Datastore</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The name of the Datastore or a PowerCLI Datastore object</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1" aliases="">
|
||||
<maml:name>CanonicalName</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The Canonical name of the LUN on which to create a new Extent, or the name of the LUN on which to apply the Expansion.
|
||||
If this parameter is not provided, the function will sort the available LUN alphanumerically on the Canonical names and slect the first one.</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
|
||||
<maml:name>IncreaseSizeGB</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The amount of GB by which to increase the size of the Datastore.
|
||||
If this parameter is not used, all of the available Expand or Extend diskspace will be used.</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">Int32</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
|
||||
<maml:name>Extend</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>A switch to indicate if the Datastore shall be Extended</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
</command:syntaxItem>
|
||||
</command:syntax>
|
||||
<command:parameters>
|
||||
<!--All Parameters-->
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="0" aliases="">
|
||||
<maml:name>Datastore</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The name of the Datastore or a PowerCLI Datastore object</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
|
||||
<dev:type>
|
||||
<maml:name>PSObject</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
|
||||
<maml:name>IncreaseSizeGB</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The amount of GB by which to increase the size of the Datastore.
|
||||
If this parameter is not used, all of the available Expand or Extend diskspace will be used.</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">Int32</command:parameterValue>
|
||||
<dev:type>
|
||||
<maml:name>Int32</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1" aliases="">
|
||||
<maml:name>CanonicalName</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>The Canonical name of the LUN on which to create a new Extent, or the name of the LUN on which to apply the Expansion.
|
||||
If this parameter is not provided, the function will sort the available LUN alphanumerically on the Canonical names and slect the first one.</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
|
||||
<dev:type>
|
||||
<maml:name>String</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
|
||||
<maml:name>Expand</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>A switch to indicate if the Datastore shall be Expanded</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">SwitchParameter</command:parameterValue>
|
||||
<dev:type>
|
||||
<maml:name>SwitchParameter</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
|
||||
<maml:name>Extend</maml:name>
|
||||
<maml:description>
|
||||
<maml:para>A switch to indicate if the Datastore shall be Extended</maml:para>
|
||||
</maml:description>
|
||||
<command:parameterValue required="true" variableLength="false">SwitchParameter</command:parameterValue>
|
||||
<dev:type>
|
||||
<maml:name>SwitchParameter</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<dev:defaultValue>
|
||||
</dev:defaultValue>
|
||||
</command:parameter>
|
||||
</command:parameters>
|
||||
<command:inputTypes>
|
||||
<!--Inputs-->
|
||||
<command:inputType>
|
||||
<dev:type>
|
||||
<maml:name>System.Management.Automation.PSObject
|
||||
</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<maml:description>
|
||||
<maml:para/>
|
||||
</maml:description>
|
||||
</command:inputType>
|
||||
</command:inputTypes>
|
||||
<command:returnValues>
|
||||
<!--Outputs-->
|
||||
<command:returnValue>
|
||||
<dev:type>
|
||||
<maml:name>System.Object</maml:name>
|
||||
<maml:uri/>
|
||||
</dev:type>
|
||||
<maml:description>
|
||||
<maml:para/>
|
||||
</maml:description>
|
||||
</command:returnValue>
|
||||
</command:returnValues>
|
||||
<command:examples>
|
||||
<!--Examples-->
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 1 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>New-VmfsDatastoreIncrease -Datastore MyDS -Expand</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>The capacity of the Datastore, named MyDS, will be Expanded with all available free space on the first extent of the Datastore.</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 2 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>New-VmfsDatastoreIncrease -Name MyDS -Expand -IncreaseSizeGB 25</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>The capacity of the Datastore, named MyDS, will be Expanded with 25GB on the first extent of the Datastore.
|
||||
Provided if course, this amount of free space is available.</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 3 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>New-VmfsDatastoreIncrease -Datastore 'TestDS' -Expand -IncreaseSizeGB 15 -CanonicalName 'naa.600507680180732f1800000000000011'</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>The capacity of the Datastore MyDS will be increased with 15GB on the extent with the Canonicalname naa.600507680180732f1800000000000011</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 4 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>New-VmfsDatastoreIncrease -Datastore MyDS -Expand -CanonicalName 'naa.600507680180732f1800000000000012'</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>The capacity of the Datastore MyDS will be increased with all available free space on the extent with the Canonicalname naa.600507680180732f1800000000000012</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 5 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>New-VmfsDatastoreIncrease -Datastore MyDS -Extend</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>A new Extent will be added to Datastore MyDS.
|
||||
All available free space of the LUN will be allocated.
|
||||
The available LUNs are ordered alphanumerically by their Canonicalname, and the first LUN is used.</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
<command:example>
|
||||
<maml:title>-------------------------- EXAMPLE 6 --------------------------</maml:title>
|
||||
<maml:introduction>
|
||||
<maml:para>PS C:\></maml:para>
|
||||
</maml:introduction>
|
||||
<dev:code>Get-Datastore -Name MyDS | New-VmfsDatastoreIncrease -Extend -IncreaseSizeGB 50</dev:code>
|
||||
<dev:remarks>
|
||||
<maml:para>The capacity of the Datastore returned by the PowerCLI Get-Datastore cmdlet will be increased by 50GB.
|
||||
This is done by adding a new Extent to the Datastore.
|
||||
The available LUNs are ordered alphanumerically by their Canonicalname, and the first LUN is used.</maml:para>
|
||||
</dev:remarks>
|
||||
</command:example>
|
||||
</command:examples>
|
||||
</command:command>
|
||||
<!--Generated by: SAPIEN PowerShell HelpWriter 2015 v1.0.16-->
|
||||
</helpItems>
|
||||
13
Modules/VMFSIncrease/en-US/about_VMFSIncrease.help.txt
Normal file
13
Modules/VMFSIncrease/en-US/about_VMFSIncrease.help.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
TOPIC
|
||||
VMFSIncrease
|
||||
|
||||
SYNOPSIS
|
||||
The VMFSIncrease module offers the same functionality that is available
|
||||
through the Increase button in the vSphere Web Client.
|
||||
|
||||
DESCRIPTION
|
||||
The VMFSIncrease offers functionality that allows to Expand or Extend
|
||||
VMFS Datastores. The module uses the vSphere API to implement this functionality.
|
||||
|
||||
SEE ALSO
|
||||
http://www.lucd.info/2016/07/29/vmfs-datastores-expand-and-extend
|
||||
92
Pester/Get-DatastoreProvisioned.Tests.ps1
Normal file
92
Pester/Get-DatastoreProvisioned.Tests.ps1
Normal file
@@ -0,0 +1,92 @@
|
||||
# To run: "Invoke-Pester <path>\Get-DatastoreProvisioned.Tests.ps1"
|
||||
|
||||
<#
|
||||
Script name: Get-DatastoreProvisioned.Tests.ps1
|
||||
Created on: 2016/07/27
|
||||
Author: Brian Bunke, @brianbunke
|
||||
Description: Help validate that any changes to Get-DatastoreProvisioned.ps1 do not break existing functionality
|
||||
Dependencies: Pester
|
||||
|
||||
===Tested Against Environment====
|
||||
vSphere Version: 6.0 U1/U2
|
||||
PowerCLI Version: PowerCLI 6.3 R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 7/10
|
||||
#>
|
||||
|
||||
# Tests file stored separately from actual script
|
||||
# Find where this file is running from, replace parent folder 'Pester' with 'Scripts'
|
||||
$Path = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace("Pester","Scripts")
|
||||
# Remove the '.Tests.' from the file name
|
||||
$File = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
# With changes made to the path, dot-source the function for testing
|
||||
. "$Path\$File"
|
||||
|
||||
Describe 'Get-DatastoreProvisioned' {
|
||||
# Need to create a few example objects to proxy Get-Datastore pipeline input
|
||||
$1 = [PSCustomObject]@{
|
||||
Name = 'iSCSI-spin'
|
||||
CapacityGB = 38.40
|
||||
FreeSpaceGB = 15.55
|
||||
ExtensionData = @{
|
||||
Summary = @{
|
||||
Capacity = 41234567890
|
||||
FreeSpace = 16696685366
|
||||
Uncommitted = 12345678999
|
||||
}}}
|
||||
$2 = [PSCustomObject]@{
|
||||
Name = 'iSCSI-ssd'
|
||||
CapacityGB = 51.74
|
||||
FreeSpaceGB = 10.35
|
||||
ExtensionData = @{
|
||||
Summary = @{
|
||||
Capacity = 55555555555
|
||||
FreeSpace = 11111111111
|
||||
Uncommitted = 23456765432
|
||||
}}}
|
||||
$3 = [PSCustomObject]@{
|
||||
Name = 'FC-ssd'
|
||||
CapacityGB = 10.35
|
||||
FreeSpaceGB = 4.14
|
||||
ExtensionData = @{
|
||||
Summary = @{
|
||||
Capacity = 11111111111
|
||||
FreeSpace = 4444444444
|
||||
Uncommitted = 2222222222
|
||||
}}}
|
||||
|
||||
It "Doesn't change existing functionality" {
|
||||
$StillWorks = $1,$2,$3 | Get-DatastoreProvisioned
|
||||
$StillWorks | Should Not BeNullOrEmpty
|
||||
($StillWorks | Measure-Object).Count | Should Be 3
|
||||
($StillWorks | Get-Member -MemberType NoteProperty).Count | Should Be 6
|
||||
'Name','FreeSpaceGB','CapacityGB','ProvisionedGB','UsedPct','ProvisionedPct' | ForEach-Object {
|
||||
($StillWorks | Get-Member -MemberType NoteProperty).Name -contains $_ | Should Be $true
|
||||
}
|
||||
}
|
||||
|
||||
It 'Still calculates correctly' {
|
||||
$calc = $1 | Get-DatastoreProvisioned
|
||||
$calc | Should Not BeNullOrEmpty
|
||||
$calc.ProvisionedGB | Should Be 34.35
|
||||
$calc.UsedPct | Should Be 59.51
|
||||
$calc.ProvisionedPct | Should Be 89.45
|
||||
}
|
||||
|
||||
# Get-Datastore | Get-DatastoreProvisioned | Format-Table -AutoSize
|
||||
It 'Follows Help Example 1' {
|
||||
$Help1 = $1,$2,$3 | Get-DatastoreProvisioned
|
||||
$Help1 | Should Not BeNullOrEmpty
|
||||
($Help1 | Measure-Object).Count | Should Be 3
|
||||
# not testing Format-Table
|
||||
}
|
||||
|
||||
# Get-Datastore -Name '*ssd' | Get-DatastoreProvisioned | Where-Object ProvisionedPct -ge 100
|
||||
It 'Follows Help Example 2' {
|
||||
$Help2 = $1,$2,$3 | Where Name -like '*ssd' | Get-DatastoreProvisioned | Where ProvisionedPct -ge 100
|
||||
$Help2 | Should Not BeNullOrEmpty
|
||||
($Help2 | Measure-Object).Count | Should Be 1
|
||||
$Help2.Name | Should BeExactly 'iSCSI-ssd'
|
||||
$Help2.ProvisionedPct | Should BeGreaterThan 100
|
||||
}
|
||||
}
|
||||
44
Pester/Test Connection to VC.ps1
Normal file
44
Pester/Test Connection to VC.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
<#
|
||||
Script name: Test Connection to VC.ps1
|
||||
Created on: 07/15/2016
|
||||
Author: Alan Renouf, @alanrenouf
|
||||
Description: The purpose of this pester test is to ensure the PowerCLI modules are imported and a connection and disconnection can be made to a vCenter
|
||||
Dependencies: Pester Module
|
||||
Example run:
|
||||
|
||||
Invoke-Pester -Script @{ Path = '.\Test Connection to VC.ps1'; Parameters = @{ VCNAME="VC01.local"; VCUSER="Administrator@vsphere.local"; VCPASS="Admin!23"} }
|
||||
|
||||
#>
|
||||
|
||||
$VCUSER = $Parameters.Get_Item("VCUSER")
|
||||
$VCPASS = $Parameters.Get_Item("VCPASS")
|
||||
$VCNAME = $Parameters.Get_Item("VCNAME")
|
||||
|
||||
Describe "PowerCLI Tests" {
|
||||
It "Importing PowerCLI Modules" {
|
||||
Get-Module VMware* | Foreach {
|
||||
Write-Host "Importing Module $($_.name) Version $($_.Version)"
|
||||
$_ | Import-Module
|
||||
Get-Module $_ | Should Be $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Connect-VIServer Tests" {
|
||||
|
||||
$connection = Connect-VIServer $VCName -User $VCUser -password $VCPass
|
||||
It "Connection is active" {
|
||||
$Global:DefaultVIServer[0].isconnected | Should Be $true
|
||||
}
|
||||
|
||||
It "Checking connected server name is $VCName" {
|
||||
$Global:DefaultVIServer[0].name | Should Be $VCName
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Disconnect-VIServer Tests" {
|
||||
It "Disconnect from $VCName" {
|
||||
Disconnect-VIServer $VCName -confirm:$false
|
||||
$Global:DefaultVIServer | Should Be $null
|
||||
}
|
||||
}
|
||||
187
README.md
187
README.md
@@ -5,6 +5,9 @@
|
||||
* [Table of Contents](https://github.com/vmware/PowerCLI-Example-Scripts#table-of-contents)
|
||||
* [Content Restrictions](https://github.com/vmware/PowerCLI-Example-Scripts#content-restrictions)
|
||||
* [Type of Content](https://github.com/vmware/PowerCLI-Example-Scripts#type-of-content)
|
||||
* [Getting Started](https://github.com/vmware/PowerCLI-Example-Scripts#getting-started)
|
||||
* [Accessing the Repository](https://github.com/vmware/PowerCLI-Example-Scripts#accessing-the-repository)
|
||||
* [Adding Resources](https://github.com/vmware/PowerCLI-Example-Scripts#adding-resources)
|
||||
* [Meta Information](https://github.com/vmware/PowerCLI-Example-Scripts#meta-information)
|
||||
* [Required Information](https://github.com/vmware/PowerCLI-Example-Scripts#required-information)
|
||||
* [Suggested Information](https://github.com/vmware/PowerCLI-Example-Scripts#suggested-information)
|
||||
@@ -19,9 +22,6 @@
|
||||
* [Maintenance Ownership](https://github.com/vmware/PowerCLI-Example-Scripts#maintenance-ownership)
|
||||
* [Filing issues](https://github.com/vmware/PowerCLI-Example-Scripts#filing-isssues)
|
||||
* [Resolving issues](https://github.com/vmware/PowerCLI-Example-Scripts#resolving-issues)
|
||||
* [Getting Started](https://github.com/vmware/PowerCLI-Example-Scripts#getting-started)
|
||||
* [Accessing the Repository](https://github.com/vmware/PowerCLI-Example-Scripts#accessing-the-repository)
|
||||
* [Adding Resources](https://github.com/vmware/PowerCLI-Example-Scripts#adding-resources)
|
||||
* [Additional Resources](https://github.com/vmware/PowerCLI-Example-Scripts#additional-resources)
|
||||
* [Discussions](https://github.com/vmware/PowerCLI-Example-Scripts#discussions)
|
||||
* [VMware Sample Exchange](https://github.com/vmware/PowerCLI-Example-Scripts#vmware-sample-exchange)
|
||||
@@ -41,79 +41,6 @@ The repository has been provided to allow the community to share resources that
|
||||
* Pester Tests
|
||||
* Tools built with PowerShell
|
||||
|
||||
## Meta Information
|
||||
This section will provide guidance on information which should be included with each submitted PowerCLI resource. Information listed in the Suggested Information will not be required for commit of a pull request to the repo, but will certainly increase ease of use for users of the resource.
|
||||
### Required Information
|
||||
The following information must be included with each submitted scripting resource. Please include the information in the appropriate location based upon the submitted scripting resource.
|
||||
|
||||
* Author Name
|
||||
* This can include full name, Twitter profile, or other identifiable piece of information that would allow interested parties to contact author with questions.
|
||||
* Date
|
||||
* Date the resource was written
|
||||
* Minimal/High Level Description
|
||||
* What does the resource do
|
||||
* Any KNOWN limitations or dependencies
|
||||
* vSphere version, required modules, etc.
|
||||
|
||||
#### Note Placement Examples:
|
||||
Script: Top few lines
|
||||
Module: Module manifest
|
||||
|
||||
#### Script Note Example:
|
||||
`<#`
|
||||
`Script name: script_name.ps1`
|
||||
`Created on: 07/07/2016`
|
||||
`Author: Author Name, @TwitterHandle`
|
||||
`Description: The purpose of the script is to …`
|
||||
`Dependencies: None known`
|
||||
`#>`
|
||||
|
||||
### Suggested Information
|
||||
The following information should be included when possible. Inclusion of information provides valuable information to consumers of the resource.
|
||||
* vSphere version against which the script was developed/tested
|
||||
* PowerCLI build against which the script was developed/tested
|
||||
* PowerShell version against which the script was developed/tested
|
||||
* OS platform version against which the script was tested/developed
|
||||
* Keywords that make it easier to find a script, for example: VDS, health check
|
||||
|
||||
## Suggested Quality Management
|
||||
This section describes guidelines put in place to maintain a standard of quality while also promoting broader contribution.
|
||||
### General Best Practices
|
||||
### Resource Naming
|
||||
* Give the resource a name that is indicitive of the actions and/or results of its running
|
||||
|
||||
### Fault Handling
|
||||
* Every submitted resource should include basic fault handling. One of many good write-ups can be found via Microsoft’s Hey, Scripting Guy! Blog: https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/09/handling-errors-the-powershell-way/
|
||||
|
||||
### Alias Usage
|
||||
* Avoid any alias usage within all submitted resources.
|
||||
|
||||
### Global Variable Usage
|
||||
* Avoid changing any global variables
|
||||
|
||||
### Help Information
|
||||
* All resources shall have inline documentation.
|
||||
|
||||
### Scripts
|
||||
* The script should be easy to read and understand
|
||||
* Place user-defined variables towards the top of the script
|
||||
|
||||
### Modules
|
||||
* The module file, PSM1, should contain only functions. A module manifest file, PSD1, should also be created and included. A module formatting file (format.ps1xml) is desirable but not a requirement.
|
||||
* Use only standard verbs
|
||||
|
||||
### Security
|
||||
* Usage of PowerShell’s strict mode is preferred, but not required.
|
||||
* Remove any information related to one’s own environment (examples: Passwords, DNS/IP Addresses, custom user credentials, etc)
|
||||
|
||||
## Resource Maintenance
|
||||
### Maintenance Ownership
|
||||
Ownership of any and all submitted resources are maintained by the submitter. This ownership also includes maintenance of any and all submitted resources.
|
||||
### Filing Issues
|
||||
Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.
|
||||
### Resolving Issues
|
||||
Any community member can resolve issues within the repository, however only the owner or a board member can approve the update. Once approved, assuming the resolution involves a pull request, only a board member will be able to merge and close the request.
|
||||
|
||||
## Getting Started
|
||||
### Accessing the Repository
|
||||
#### Downloading the Repository for Local Access
|
||||
@@ -144,6 +71,95 @@ Any community member can resolve issues within the repository, however only the
|
||||
5. Click “Propose new file”
|
||||
6. On the “Open a pull request” page, click “Create pull request”
|
||||
|
||||
## Meta Information
|
||||
This section will provide guidance on information which should be included with each submitted PowerCLI resource. Information listed in the Suggested Information will not be required for commit of a pull request to the repo, but will certainly increase ease of use for users of the resource.
|
||||
### Required Information
|
||||
The following information must be included with each submitted scripting resource. Please include the information in the appropriate location based upon the submitted scripting resource.
|
||||
|
||||
* Author Name
|
||||
* This can include full name, Twitter profile, or other identifiable piece of information that would allow interested parties to contact author with questions.
|
||||
* Date
|
||||
* Date the resource was written
|
||||
* Minimal/High Level Description
|
||||
* What does the resource do
|
||||
* Any KNOWN limitations or dependencies
|
||||
* vSphere version, required modules, etc.
|
||||
|
||||
#### Note Placement Examples:
|
||||
Script: Top few lines
|
||||
Module: Module manifest
|
||||
|
||||
#### Required Script Note Example:
|
||||
`<#`
|
||||
`Script name: script_name.ps1`
|
||||
`Created on: 07/07/2016`
|
||||
`Author: Author Name, @TwitterHandle`
|
||||
`Description: The purpose of the script is to …`
|
||||
`Dependencies: None known`
|
||||
`#>`
|
||||
|
||||
### Suggested Information
|
||||
The following information should be included when possible. Inclusion of information provides valuable information to consumers of the resource.
|
||||
* vSphere version against which the script was developed/tested
|
||||
* PowerCLI build against which the script was developed/tested
|
||||
* PowerShell version against which the script was developed/tested
|
||||
* OS platform version against which the script was tested/developed
|
||||
* Keywords that make it easier to find a script, for example: VDS, health check
|
||||
|
||||
#### Suggested Script Note Example:
|
||||
`<#`
|
||||
`Script name: script_name.ps1`
|
||||
`Created on: 07/07/2016`
|
||||
`Author: Author Name, @TwitterHandle`
|
||||
`Description: The purpose of the script is to …`
|
||||
`Dependencies: None known`
|
||||
|
||||
`===Tested Against Environment====`
|
||||
`vSphere Version: 6.0`
|
||||
`PowerCLI Version: PowerCLI 6.3 R1`
|
||||
`PowerShell Version: 5.0`
|
||||
`OS Version: Windows 10`
|
||||
`Keyword: VM`
|
||||
`#>`
|
||||
|
||||
## Suggested Quality Management
|
||||
This section describes guidelines put in place to maintain a standard of quality while also promoting broader contribution.
|
||||
### General Best Practices
|
||||
### Resource Naming
|
||||
* Give the resource a name that is indicitive of the actions and/or results of its running
|
||||
|
||||
### Fault Handling
|
||||
* Read and apply the following basic fault handling where applicable: Microsoft’s Hey, Scripting Guy! Blog: https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/09/handling-errors-the-powershell-way/
|
||||
|
||||
### Alias Usage
|
||||
* Avoid any alias usage within all submitted resources.
|
||||
|
||||
### Global Variable Usage
|
||||
* Avoid changing any global variables
|
||||
|
||||
### Help Information
|
||||
* All resources should have inline documentation.
|
||||
|
||||
### Scripts
|
||||
* The script should be easy to read and understand
|
||||
* Place user-defined variables towards the top of the script
|
||||
|
||||
### Modules
|
||||
* The module file, PSM1, should contain only functions. A module manifest file, PSD1, should also be created and included. A module formatting file (format.ps1xml) is desirable but not a requirement.
|
||||
* Use only standard verbs
|
||||
|
||||
### Security
|
||||
* Usage of PowerShell’s strict mode is preferred, but not required.
|
||||
* Remove any information related to one’s own environment (examples: Passwords, DNS/IP Addresses, custom user credentials, etc)
|
||||
|
||||
## Resource Maintenance
|
||||
### Maintenance Ownership
|
||||
Ownership of any and all submitted resources are maintained by the submitter. This ownership also includes maintenance of any and all submitted resources.
|
||||
### Filing Issues
|
||||
Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.
|
||||
### Resolving Issues
|
||||
Any community member can resolve issues within the repository, however only the owner or a board member can approve the update. Once approved, assuming the resolution involves a pull request, only a board member will be able to merge and close the request.
|
||||
|
||||
## Additional Resources
|
||||
### Discussions
|
||||
Join in on the discussion within the VMware Code Slack team's PowerCLI channel: <https://code.vmware.com/slack/>
|
||||
@@ -161,13 +177,16 @@ The VMware Technnology Preview License Agreement: <https://github.com/vmware/Pow
|
||||
* Approval of Additions
|
||||
|
||||
## Board Members
|
||||
* Josh Atwell
|
||||
* Mathieu Buisson
|
||||
* Luc Dekens
|
||||
* Jonathan Medd
|
||||
* Alan Renouf
|
||||
* Kyle Ruddy
|
||||
* Rynardt Spies
|
||||
|
||||
Board members are volunteers from the PowerCLI community and VMware staff members, board members are not held responsible for any issues which may occur from running of scripts inside this repository.
|
||||
|
||||
Members:
|
||||
* Josh Atwell (Community Member)
|
||||
* Luc Dekens (Community Member)
|
||||
* Jonathan Medd (Community Member)
|
||||
* Alan Renouf (VMware)
|
||||
* Kyle Ruddy (VMware)
|
||||
* Rynardt Spies (Community Member)
|
||||
|
||||
## Approval of Additions
|
||||
Items added to the repository require 2 votes from the board members before being added to the repository. The approving members will have ideally downloaded and tested the item. When two “Approved for Merge” comments are added from board members, the pull can then be committed to the repository.
|
||||
Items added to the repository, including items from the Board members, require 2 votes from the board members before being added to the repository. The approving members will have ideally downloaded and tested the item. When two “Approved for Merge” comments are added from board members, the pull can then be committed to the repository.
|
||||
|
||||
67
Scripts/Get-DatastoreProvisioned.ps1
Normal file
67
Scripts/Get-DatastoreProvisioned.ps1
Normal file
@@ -0,0 +1,67 @@
|
||||
<#
|
||||
Script name: Get-DatastoreProvisioned.ps1
|
||||
Created on: 2016/07/27
|
||||
Author: Brian Bunke, @brianbunke
|
||||
Description: Augments Get-Datastore with thin provisioned info
|
||||
Note to future contributors: Test changes with Pester file Get-DatastoreProvisioned.Tests.ps1
|
||||
|
||||
===Tested Against Environment====
|
||||
vSphere Version: 6.0 U1/U2
|
||||
PowerCLI Version: PowerCLI 6.3 R1
|
||||
PowerShell Version: 5.0
|
||||
OS Version: Windows 7/10
|
||||
#>
|
||||
|
||||
function Get-DatastoreProvisioned {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Retrieve the total thin provisioned space on each datastore.
|
||||
|
||||
.DESCRIPTION
|
||||
Intended to reveal provisioned space alongside total/free space, to assist with svMotion decisions.
|
||||
-Name should be supplied from the pipeline via Get-Datastore.
|
||||
|
||||
.EXAMPLE
|
||||
Get-Datastore | Get-DatastoreProvisioned | Format-Table -AutoSize
|
||||
View all datastores and view their capacity statistics in the current console.
|
||||
|
||||
.EXAMPLE
|
||||
Get-Datastore -Name '*ssd' | Get-DatastoreProvisioned | Where-Object -Property ProvisionedPct -ge 100
|
||||
For all datastores ending in 'ssd', return the capacity stats of those at least 100% provisioned.
|
||||
|
||||
.INPUTS
|
||||
[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl]
|
||||
Object type supplied by PowerCLI function Get-Datastore
|
||||
|
||||
.LINK
|
||||
https://github.com/vmware/PowerCLI-Example-Scripts
|
||||
|
||||
.LINK
|
||||
https://twitter.com/brianbunke
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
# Specifies the datastore names to check. Tested only with pipeline input (see examples).
|
||||
[Parameter(ValueFromPipeline = $true)]
|
||||
$Name
|
||||
)
|
||||
|
||||
PROCESS {
|
||||
ForEach ($DS in $Name) {
|
||||
# Calculate total provisioned space from the exposed properties
|
||||
$Provisioned = ($DS.ExtensionData.Summary.Capacity -
|
||||
$DS.ExtensionData.Summary.FreeSpace +
|
||||
$DS.ExtensionData.Summary.Uncommitted) / 1GB
|
||||
|
||||
# Return info, wrapping it in the Math.Round method to trim to two decimal places
|
||||
[PSCustomObject]@{
|
||||
Name = $DS.Name
|
||||
FreeSpaceGB = [math]::Round($DS.FreeSpaceGB, 2)
|
||||
CapacityGB = [math]::Round($DS.CapacityGB, 2)
|
||||
ProvisionedGB = [math]::Round($Provisioned, 2)
|
||||
UsedPct = [math]::Round((($DS.CapacityGB - $DS.FreeSpaceGB) / $DS.CapacityGB) * 100, 2)
|
||||
ProvisionedPct = [math]::Round(($Provisioned / $DS.CapacityGB) * 100, 2)
|
||||
} #pscustomobject
|
||||
} #foreach
|
||||
} #process
|
||||
} #function
|
||||
41
Scripts/Get-VMID.ps1
Normal file
41
Scripts/Get-VMID.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
function Get-VMID {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Markus Kraus
|
||||
Organization: Private
|
||||
Personal Blog: mycloudrevolution.com
|
||||
Twitter: @vMarkus_K
|
||||
===========================================================================
|
||||
.DESCRIPTION
|
||||
This will quickly return all IDs of VMs
|
||||
.Example
|
||||
Get-VMID -myVMs (Get-VM) | ft
|
||||
.Example
|
||||
$SampleVMs = Get-VM "tst*"
|
||||
Get-VMID -myVMs $SampleVMs
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipeline=$True,
|
||||
Position=0)]
|
||||
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]
|
||||
$myVMs
|
||||
)
|
||||
Process {
|
||||
|
||||
$MyView = @()
|
||||
ForEach ($myVM in $myVMs){
|
||||
$UUIDReport = [PSCustomObject] @{
|
||||
Name = $myVM.name
|
||||
UUID = $myVM.extensiondata.Config.UUID
|
||||
InstanceUUID = $myVM.extensiondata.config.InstanceUUID
|
||||
LocationID = $myVM.extensiondata.config.LocationId
|
||||
MoRef = $myVM.extensiondata.Moref.Value
|
||||
}
|
||||
$MyView += $UUIDReport
|
||||
}
|
||||
$MyView
|
||||
}
|
||||
}
|
||||
116
Scripts/vRealize Operations Maintenance Mode.ps1
Normal file
116
Scripts/vRealize Operations Maintenance Mode.ps1
Normal file
@@ -0,0 +1,116 @@
|
||||
Connect-VIServer vc-l-01a.corp.local -User administrator@vsphere.local -Password VMware1!
|
||||
Connect-OMServer vrops.corp1.local -User admin -Password VMware1!
|
||||
|
||||
function Enable-OMMaintenance {
|
||||
<#
|
||||
.NOTES
|
||||
Script name: vRealize Operations Maintenance Mode.ps1
|
||||
Created on: 07/26/2016
|
||||
Author: Alan Renouf, @alanrenouf
|
||||
Dependencies: PowerCLI 6.0 R2 or later
|
||||
.DESCRIPTION
|
||||
Places a vSphere Inventory object into maintenance mode in vRealize Operations
|
||||
.Example
|
||||
Set All VMs with a name as backup as being in maintenance mode for 20 minutes:
|
||||
|
||||
Get-VM backup* | Enable-OMMaintenance -MaintenanceTime 20
|
||||
|
||||
Name Health ResourceKind Description
|
||||
---- ------ ------------ -----------
|
||||
backup-089e13fd-7d7a-0 Grey VirtualMachine
|
||||
backup-d90e0b39-2618-0 Grey VirtualMachine
|
||||
backup-e48ca842-316a-0 Grey VirtualMachine
|
||||
backup-77da3713-919a-0 Grey VirtualMachine
|
||||
backup-c32f4da8-86c4-0 Grey VirtualMachine
|
||||
backup-c3fcb95c-cfe2-0 Grey VirtualMachine
|
||||
backup-4318bb1e-614a-0 Grey VirtualMachine
|
||||
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]
|
||||
$Resource,
|
||||
|
||||
[Parameter(Position=1, Mandatory=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Int]
|
||||
$MaintenanceTime
|
||||
)
|
||||
process {
|
||||
Foreach ($Entry in $resource) {
|
||||
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
} Else {
|
||||
$Item.ExtensionData.MarkResourceAsBeingMaintained($MaintenanceTime)
|
||||
Get-Inventory -Name $Entry | Get-OMResource
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Disable-OMMaintenance {
|
||||
<#
|
||||
.NOTES
|
||||
Script name: vRealize Operations Maintenance Mode.ps1
|
||||
Created on: 07/26/2016
|
||||
Author: Alan Renouf, @alanrenouf
|
||||
Dependencies: PowerCLI 6.0 R2 or later
|
||||
.DESCRIPTION
|
||||
Removes a vSphere Inventory object from maintenance mode in vRealize Operations
|
||||
.Example
|
||||
Disable maintenance mode for all VMs with a name of backup
|
||||
|
||||
Get-VM backup* | Disable-OMMaintenance
|
||||
|
||||
Name Health ResourceKind Description
|
||||
---- ------ ------------ -----------
|
||||
backup-089e13fd-7d7a-0 Grey VirtualMachine
|
||||
backup-d90e0b39-2618-0 Grey VirtualMachine
|
||||
backup-e48ca842-316a-0 Grey VirtualMachine
|
||||
backup-77da3713-919a-0 Grey VirtualMachine
|
||||
backup-c32f4da8-86c4-0 Yellow VirtualMachine
|
||||
backup-c3fcb95c-cfe2-0 Yellow VirtualMachine
|
||||
backup-4318bb1e-614a-0 Yellow VirtualMachine
|
||||
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]
|
||||
$Resource
|
||||
)
|
||||
process {
|
||||
Foreach ($Entry in $resource) {
|
||||
$Item = Get-Inventory -Name $Entry | Get-OMResource
|
||||
if (-not $Item) {
|
||||
throw "$Entry not found"
|
||||
} Else {
|
||||
$Item.ExtensionData.UnmarkResourceAsBeingMaintained()
|
||||
Get-Inventory -Name $Entry | Get-OMResource
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Enable a single host as being in maintenance mode for 1 minute"
|
||||
Enable-OMMaintenance -Resource ESX-01a* -MaintenanceTime 1
|
||||
|
||||
Write-Host "List All Host Resources and their state"
|
||||
Get-OMResource ESX-* | Select Name, State | FT
|
||||
|
||||
Write-Host "Set All VMs with a name as backup as being in maintenance mode for 20 minutes"
|
||||
Get-VM backup* | Enable-OMMaintenance -MaintenanceTime 20
|
||||
|
||||
Write-Host "List All Backup VM Resources and their state"
|
||||
Get-VM backup* | Get-OMResource | Select Name, State | FT
|
||||
|
||||
Write-Host "Disable maintenance mode for all VMs with a name as backup as we have completed our scheduled work"
|
||||
Get-VM backup* | Disable-OMMaintenance
|
||||
|
||||
Write-Host "List All VM Resources and their state"
|
||||
Get-VM backup* | Get-OMResource | Select Name, State | FT
|
||||
|
||||
Reference in New Issue
Block a user