Merge branch 'master' into master

This commit is contained in:
praveenmathamsetty
2017-05-17 23:21:53 +05:30
committed by GitHub
3 changed files with 304 additions and 0 deletions

View File

@@ -8711,10 +8711,13 @@ function Get-HVPodSession {
.PARAMETER HvServer
Reference to Horizon View Server to query the virtual machines from. If the value is not passed or null then
first element from global:DefaultHVServers would be considered inplace of hvServer
.EXAMPLE
Get-HVPodSession
.OUTPUTS
Returns list of objects of type GlobalSessionPodSessionCounter
.NOTES
Author : Rasmus Sjoerslev
Author email : rasmus.sjorslev@vmware.com

View File

@@ -0,0 +1,103 @@
<#
.SYNOPSIS
Set a given LUN ID to Perennially Reserved.
.DESCRIPTION
A description of the file.
.PARAMETER vCenter
Set vCenter server to connect to
.PARAMETER Username
Set username to use
.PARAMETER Password
Set password to be used
.PARAMETER VirtualMachine
Name of the virtual machine which has the RDM
.NOTES
===========================================================================
Created on: 20/03/2017 15:05
Created by: Alessio Rocchi <arocchi@vmware.com>
Organization: VMware
Filename: SetLunReservation.ps1
===========================================================================
#>
param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
[ValidateNotNullOrEmpty()]
[String]$vCenter,
[Parameter(Mandatory = $false,
ValueFromPipeline = $true,
HelpMessage = 'Set vCenter Username')]
[AllowNull()]
[String]$Username,
[Parameter(Mandatory = $false,
ValueFromPipeline = $true,
HelpMessage = 'Set vCenterPassword')]
[AllowNull()]
[String]$Password,
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[String]$VirtualMachine
)
Import-Module -Name VMware.VimAutomation.Core -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null
try
{
if ([String]::IsNullOrEmpty($Username) -or [String]::IsNullOrEmpty($Password))
{
$vcCredential = Get-Credential
Connect-VIServer -Server $vCenter -Credential $vcCredential -WarningAction SilentlyContinue -ErrorAction Stop | Out-Null
}
else
{
Connect-VIServer -Server $vCenter -User $Username -Password $Password -WarningAction SilentlyContinue -ErrorAction Stop | Out-Null
}
}
catch
{
Write-Error("Error connecting to vCenter: {0}" -f $vCenter)
exit
}
$rDms = Get-HardDisk -DiskType rawPhysical -Vm (Get-VM -Name $VirtualMachine)
$clusterHosts = Get-Cluster -VM $VirtualMachine | Get-VMHost
$menu = @{ }
for ($i = 1; $i -le $rDms.count; $i++)
{
Write-Host("{0}) {1}[{2}]: {3}" -f ($i, $rDms[$i - 1].Name, $rDms[$i - 1].CapacityGB, $rDms[$i - 1].ScsiCanonicalName))
$menu.Add($i, ($rDms[$i - 1].ScsiCanonicalName))
}
[int]$ans = Read-Host 'Which Disk you want to configure?'
$selection = $menu.Item($ans)
write-host("Choosed Disk: {0}" -f $selection)
$current = 0
foreach ($vmHost in $clusterHosts)
{
Write-Progress -Activity "Processing Cluster." -CurrentOperation $vmHost.Name -PercentComplete (($counter / $clusterHosts.count) * 100)
$esxcli = Get-EsxCli -V2 -VMHost $vmHost
$deviceListArgs = $esxcli.storage.core.device.list.CreateArgs()
$deviceListArgs.device = $selection
$esxcli.storage.core.device.list.Invoke($deviceListArgs) | Select-Object Device, IsPerenniallyReserved
$deviceSetArgs = $esxcli.storage.core.device.setconfig.CreateArgs()
$deviceSetArgs.device = $selection
$deviceSetArgs.perenniallyreserved = $true
$esxcli.storage.core.device.setconfig.Invoke($deviceSetArgs)
$counter++
}
Disconnect-VIServer -WarningAction SilentlyContinue -Server $vCenter -Force -Confirm:$false

198
SetDatastoreTag.ps1 Executable file
View File

@@ -0,0 +1,198 @@
<#
.SYNOPSIS
A brief description of the file.
.DESCRIPTION
Given a list of Datastore Names, this script will assign a Tag to them
.PARAMETER csvFile
String representing the full path of the file
The file must be structured like this:
-----------------------------
Tag1,Tag2,Tag3,Tag4
IPv4-iSCSI-SiteA,Tag1,Tag3
IPv4-NFS-SiteA,Tag2,Tag4
...
-----------------------------
.NOTES
===========================================================================
Created on: 31/03/2017 11:16
Created by: Alessio Rocchi <arocchi@vmware.com>
Organization: VMware
Filename: SetDatastoreTag.ps1
===========================================================================
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[System.String]$csvFile,
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[String]$vCenter,
[Parameter(ValueFromPipeline = $true,
Position = 2)]
[AllowNull()]
[String]$Username,
[Parameter(Position = 3)]
[AllowNull()]
[String]$Password
)
Import-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null
class vcConnector : System.IDisposable
{
[String]$Username
[String]$Password
[String]$vCenter
[PSObject]$server
static [vcConnector]$instance
vcConnector($Username, $Password, $vCenter)
{
Import-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null
$this.Username = $Username
$this.Password = $Password
$this.vCenter = $vCenter
$this.connect()
}
vcConnector($vcCredential, $vCenter)
{
Import-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null
$this.vcCredential = $vcCredential
$this.vCenter = $vCenter
$this.connect()
}
[void] hidden connect()
{
try
{
if ([String]::IsNullOrEmpty($this.Username) -or [String]::IsNullOrEmpty($this.Password))
{
$vcCredential = Get-Credential
Connect-VIServer -Server $this.vCenter -Credential $this.vcCredential -WarningAction SilentlyContinue -ErrorAction Stop | Out-Null
}
else
{
Connect-VIServer -Server $this.vCenter -User $this.Username -Password $this.Password -WarningAction SilentlyContinue -ErrorAction Stop
}
Write-Debug("Connected to vCenter: {0}" -f $this.vCenter)
}
catch
{
Write-Error($Error[0].Exception.Message)
exit
}
}
[void] Dispose()
{
Write-Debug("Called Dispose Method of Instance: {0}" -f ($this))
Disconnect-VIServer -WarningAction SilentlyContinue -Server $this.vCenter -Force -Confirm:$false | Out-Null
}
static [vcConnector] GetInstance()
{
if ([vcConnector]::instance -eq $null)
{
[vcConnector]::instance = [vcConnector]::new()
}
return [vcConnector]::instance
}
}
class Content{
[System.Collections.Generic.List[System.String]]$availableTags
[System.Collections.Generic.List[System.String]]$elements
Content()
{
}
Content([String]$filePath)
{
if ((Test-Path -Path $filePath) -eq $false)
{
throw ("Cannot find file: {0}" -f ($filePath))
}
try
{
# Cast the Get-Content return type to Generic List of Strings in order to avoid fixed-size array
$this.elements = [System.Collections.Generic.List[System.String]](Get-Content -Path $filePath -ea SilentlyContinue -wa SilentlyContinue)
$this.availableTags = $this.elements[0].split(',')
# Delete the first element aka availableTags
$this.elements.RemoveAt(0)
}
catch
{
throw ("Error reading the file: {0}" -f ($filePath))
}
}
}
try
{
$vc = [vcConnector]::new($Username, $Password, $vCenter)
$csvContent = [Content]::new($csvFile)
Write-Host("Available Tags: {0}" -f ($csvContent.availableTags))
foreach ($element in $csvContent.elements)
{
[System.Collections.Generic.List[System.String]]$splittedList = $element.split(',')
# Get the Datastore Name
[System.String]$datastoreName = $splittedList[0]
# Removing Datastore Name
$splittedList.RemoveAt(0)
# Create a List of Tags which will be assigned to the Datastore
[System.Collections.Generic.List[PSObject]]$tagsToAssign = $splittedList | ForEach-Object { Get-Tag -Name $_ }
Write-Host("Tags to assign to Datastore: {0} are: {1}" -f ($datastoreName, $tagsToAssign))
# Get Datastore object by the given Datastore Name, first field of the the line
$datastore = Get-Datastore -Name $datastoreName -ea Stop
# Iterate the assigned Datastore Tags
foreach ($tag in ($datastore | Get-TagAssignment))
{
# Check if the current tag is one of the available ones.
if ($tag.Tag.Name -in $csvContent.availableTags)
{
# Remove the current assigned Tag
Write-Host("Removing Tag: {0}" -f ($tag))
Remove-TagAssignment -TagAssignment $tag -Confirm:$false
}
}
# Finally add the new set of tags to the Datastore
foreach ($tag in $tagsToAssign)
{
Write-Host("Trying to assign Tag: {0} to Datastore: {1}" -f ($tag.Name, $datastoreName))
# Assign the Tag
New-TagAssignment -Entity $datastore -Tag $tag
}
}
}
catch [VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException]
{
Write-Error("VIException: {0}" -f ($Error[0].Exception.Message))
exit
}
catch
{
Write-Error $Error[0].Exception.Message
exit
}
finally
{
# Let be assured that the vc connection will be disposed.
$vc.Dispose()
}