30 Commits

Author SHA1 Message Date
lucdekens
3dda8cc639 VMFSIncrease - bug fix
Fixed bug in New-VmfsDatastoreIncrease -Datastore <ds> -Expand -IncreaseSizeGB <size>
2018-05-30 19:53:01 +02:00
lucdekens
99250732fb Add files via upload 2016-07-29 15:39:10 +02:00
lucdekens
7bbec511cb Create about_VMFSIncrease.help.txt 2016-07-29 15:38:56 +02:00
lucdekens
b2ba87db86 Delete en-US 2016-07-29 15:38:13 +02:00
lucdekens
7392e451c5 Create en-US 2016-07-29 15:37:35 +02:00
lucdekens
1489e86b66 Add files via upload 2016-07-29 15:37:11 +02:00
lucdekens
7a38462f1a Create VMFSIncrease.psd1 2016-07-29 15:34:15 +02:00
Kyle Ruddy
ddfb85780f Merge pull request #16 from Zsoldier/patch-1
Update README.md
2016-07-28 10:10:20 -04:00
Chris Nakagaki
06a3ea0210 Update README.md
Spelling correction.
2016-07-28 09:58:00 -04:00
Kyle Ruddy
172e1436c5 Merge pull request #15 from brianbunke/bb-DatastoreProv
Add Get-DatastoreProvisioned
2016-07-28 08:32:11 -04:00
brianbunke
e1937544fb Add Get-DatastoreProvisioned
Script returns thin provisioned info on datastores. Pester file is a way
to validate that future changes made to the script don't break existing
functionality
2016-07-27 23:32:28 -07:00
Alan Renouf
7f6482b7af Merge pull request #14 from mycloudrevolution/DEV-vMarkus_K
Get-VMID
2016-07-27 15:18:12 -07:00
Alan Renouf
f47c3a7c3b Merge pull request #12 from alanrenouf/master
Pester Test for VC and vROPs Maintenance mode functions
2016-07-27 15:15:50 -07:00
mycloudrevolution
e91b0c0649 Get-VMID
This will quickly return all IDs of VMs
2016-07-27 23:42:23 +02:00
Alan Renouf
ca70d01e54 Update pester and add vrops script
Updated Pester test so it can be called with parameters and included
vROPS Maintenance Mode Script
2016-07-26 22:35:41 -07:00
Alan Renouf
1dff599996 Merge remote-tracking branch 'refs/remotes/vmware/master' 2016-07-26 22:02:53 -07:00
Kyle Ruddy
2e25d166a0 Update README.md
Updating the board members
2016-07-26 09:04:38 -04:00
Alan Renouf
e709f1fdde Pester Tests for VC Connection
Pester Tests for VC Connection
2016-07-15 16:47:08 -07:00
Alan Renouf
c432a0d1fa Merge remote-tracking branch 'refs/remotes/vmware/master' 2016-07-15 16:46:11 -07:00
Alan Renouf
99673b1dfa removed pester test so it gets approval 2016-07-15 16:45:03 -07:00
Alan Renouf
3403db0ead Pester VC Connection test
Connection and modules tests for VC in pester
2016-07-15 16:43:32 -07:00
Alan Renouf
2f595f086d Updated Readme
Updated Readme
2016-07-15 15:50:43 -07:00
Alan Renouf
e7c968d32b Updated Readme
Updated Readme
2016-07-15 15:49:19 -07:00
Alan Renouf
8469b3a285 Update README.md 2016-07-15 15:31:02 -07:00
Kyle Ruddy
456bd28b45 Merge pull request #11 from vmware/Reorg
Readme Update
2016-07-15 15:10:06 -07:00
Kyle Ruddy
32096f6e02 Merge pull request #10 from vmware/Reorg
ReadMe Updates
2016-07-15 15:05:11 -07:00
Kyle Ruddy
c8b2607b94 Merge pull request #9 from vmware/Reorg
Readme Updates
2016-07-15 15:02:35 -07:00
Kyle Ruddy
eae378822b Merge pull request #8 from vmware/Reorg
Readme Updates
2016-07-15 15:00:11 -07:00
Kyle Ruddy
4464bf001b Merge pull request #7 from vmware/Reorg
Readme Updates
2016-07-15 14:55:57 -07:00
Kyle Ruddy
06d3eed37d Merge pull request #6 from vmware/Reorg
Reorg
2016-07-15 14:50:37 -07:00
11 changed files with 1220 additions and 84 deletions

View 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

View 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'
}
}
}

View 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

View 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:\&gt;</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:\&gt;</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:\&gt;</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:\&gt;</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:\&gt;</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:\&gt;</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:\&gt;</maml:para>
</maml:introduction>
<dev:code>New-VmfsDatastoreIncrease -Datastore &apos;TestDS&apos; -Expand -IncreaseSizeGB 15 -CanonicalName &apos;naa.600507680180732f1800000000000011&apos;</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:\&gt;</maml:para>
</maml:introduction>
<dev:code>New-VmfsDatastoreIncrease -Datastore MyDS -Expand -CanonicalName &apos;naa.600507680180732f1800000000000012&apos;</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:\&gt;</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:\&gt;</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>

View 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

View 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
}
}

View 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
View File

@@ -5,6 +5,9 @@
* [Table of Contents](https://github.com/vmware/PowerCLI-Example-Scripts#table-of-contents) * [Table of Contents](https://github.com/vmware/PowerCLI-Example-Scripts#table-of-contents)
* [Content Restrictions](https://github.com/vmware/PowerCLI-Example-Scripts#content-restrictions) * [Content Restrictions](https://github.com/vmware/PowerCLI-Example-Scripts#content-restrictions)
* [Type of Content](https://github.com/vmware/PowerCLI-Example-Scripts#type-of-content) * [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) * [Meta Information](https://github.com/vmware/PowerCLI-Example-Scripts#meta-information)
* [Required Information](https://github.com/vmware/PowerCLI-Example-Scripts#required-information) * [Required Information](https://github.com/vmware/PowerCLI-Example-Scripts#required-information)
* [Suggested Information](https://github.com/vmware/PowerCLI-Example-Scripts#suggested-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) * [Maintenance Ownership](https://github.com/vmware/PowerCLI-Example-Scripts#maintenance-ownership)
* [Filing issues](https://github.com/vmware/PowerCLI-Example-Scripts#filing-isssues) * [Filing issues](https://github.com/vmware/PowerCLI-Example-Scripts#filing-isssues)
* [Resolving issues](https://github.com/vmware/PowerCLI-Example-Scripts#resolving-issues) * [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) * [Additional Resources](https://github.com/vmware/PowerCLI-Example-Scripts#additional-resources)
* [Discussions](https://github.com/vmware/PowerCLI-Example-Scripts#discussions) * [Discussions](https://github.com/vmware/PowerCLI-Example-Scripts#discussions)
* [VMware Sample Exchange](https://github.com/vmware/PowerCLI-Example-Scripts#vmware-sample-exchange) * [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 * Pester Tests
* Tools built with PowerShell * 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 Microsofts 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 PowerShells strict mode is preferred, but not required.
* Remove any information related to ones 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 repositorys 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 ## Getting Started
### Accessing the Repository ### Accessing the Repository
#### Downloading the Repository for Local Access #### 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” 5. Click “Propose new file”
6. On the “Open a pull request” page, click “Create pull request” 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: Microsofts 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 PowerShells strict mode is preferred, but not required.
* Remove any information related to ones 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 repositorys 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 ## Additional Resources
### Discussions ### Discussions
Join in on the discussion within the VMware Code Slack team's PowerCLI channel: <https://code.vmware.com/slack/> 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 * Approval of Additions
## Board Members ## Board Members
* Josh Atwell
* Mathieu Buisson 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.
* Luc Dekens
* Jonathan Medd Members:
* Alan Renouf * Josh Atwell (Community Member)
* Kyle Ruddy * Luc Dekens (Community Member)
* Rynardt Spies * Jonathan Medd (Community Member)
* Alan Renouf (VMware)
* Kyle Ruddy (VMware)
* Rynardt Spies (Community Member)
## Approval of Additions ## 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.

View 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
View 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
}
}

View 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