Worked through PSScriptAnalyzer low hanging fruit

This commit is contained in:
Matt Frey
2019-08-06 14:28:16 -05:00
parent 337dc077a9
commit cbf397df24

View File

@@ -482,7 +482,6 @@ function Get-UserId ($User) {
$defn = New-Object VMware.Hv.QueryDefinition $defn = New-Object VMware.Hv.QueryDefinition
$defn.queryEntityType = 'ADUserOrGroupSummaryView' $defn.queryEntityType = 'ADUserOrGroupSummaryView'
[VMware.Hv.QueryFilter[]]$filters = $null
$groupfilter = New-Object VMware.Hv.QueryFilterEquals -Property @{ 'memberName' = 'base.group'; 'value' = $false } $groupfilter = New-Object VMware.Hv.QueryFilterEquals -Property @{ 'memberName' = 'base.group'; 'value' = $false }
$userNameFilter = New-Object VMware.Hv.QueryFilterEquals -Property @{ 'memberName' = 'base.name'; 'value' = $user } $userNameFilter = New-Object VMware.Hv.QueryFilterEquals -Property @{ 'memberName' = 'base.name'; 'value' = $user }
$treeList = @() $treeList = @()
@@ -668,7 +667,7 @@ function Connect-HVEvent {
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
$DbPassword = $null, [SecureString]$DbPassword = $null,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
$HvServer = $null, $HvServer = $null,
@@ -705,12 +704,10 @@ function Connect-HVEvent {
if (!$dbPassword) { $dbPassword = Read-Host 'Database Password for' $dbUserName@$dbServer -AsSecureString } if (!$dbPassword) { $dbPassword = Read-Host 'Database Password for' $dbUserName@$dbServer -AsSecureString }
if ($dbType -eq "SQLSERVER") { if ($dbType -eq "SQLSERVER") {
if ($dbPassword.GetType().name -eq 'String'){ if ($dbPassword.GetType().name -eq 'SecureString') {
$password = ConvertTo-SecureString $dbPassword -AsPlainText -Force
} elseif ($dbPassword.GetType().name -eq 'SecureString') {
$password = $dbPassword $password = $dbPassword
} else { } else {
Write-Error "Unsupported type recieved for dbPassword: [$dbPassword]. dbpassword should either be String or SecureString type. " Write-Error "Unsupported type recieved for dbPassword: [$dbPassword]. dbpassword should SecureString type."
break break
} }
$connectionString = "Data Source=$dbServer, $dbPort; Initial Catalog=$dbName;" $connectionString = "Data Source=$dbServer, $dbPort; Initial Catalog=$dbName;"
@@ -1117,10 +1114,7 @@ function Get-HVFarm {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -1231,10 +1225,7 @@ function Get-HVFarmSummary {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -1337,7 +1328,7 @@ function Find-HVFarm {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$farmList = $queryResults.results | where $scriptBlock $farmList = $queryResults.results | Where-Object $scriptBlock
} }
Return $farmList Return $farmList
} }
@@ -1419,10 +1410,7 @@ function Get-HVPool {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -1558,10 +1546,7 @@ function Get-HVPoolSummary {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -1675,7 +1660,7 @@ function Find-HVPool {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$poolList = $queryResults.results | where $scriptBlock $poolList = $queryResults.results | Where-Object $scriptBlock
} }
Return $poolList Return $poolList
} }
@@ -1918,8 +1903,7 @@ function Get-HVQueryResult {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding(SupportsShouldProcess = $true, [CmdletBinding()]
ConfirmImpact = 'High')]
param( param(
[Parameter(Position = 0,Mandatory = $true)] [Parameter(Position = 0,Mandatory = $true)]
[ValidateSet('ADUserOrGroupSummaryView','ApplicationIconInfo','ApplicationInfo','DesktopSummaryView', [ValidateSet('ADUserOrGroupSummaryView','ApplicationIconInfo','ApplicationInfo','DesktopSummaryView',
@@ -2835,11 +2819,12 @@ function New-HVFarm {
$farmSpecObj.ManualFarmSpec = $FarmManualFarmSpec $farmSpecObj.ManualFarmSpec = $FarmManualFarmSpec
} }
# Please uncomment below code, if you want to save the json file If ($DebugPreference -ne 'SilentlyContinue') {
<# $myDebug = convertto-json -InputObject $farmSpecObj -depth 12
$myDebug = convertto-json -InputObject $farmSpecObj -depth 12 $DebugOutput = "c:\temp\copiedfarm.json"
$myDebug | out-file -filepath c:\temp\copiedfarm.json $myDebug | Out-File -filepath $DebugOutput
#> Write-Debug "Output Farm Spec to $DebugOutput."
}
if (!$confirmFlag -OR $pscmdlet.ShouldProcess($farmSpecObj.data.name)) { if (!$confirmFlag -OR $pscmdlet.ShouldProcess($farmSpecObj.data.name)) {
$Id = $farm_service_helper.Farm_Create($services, $farmSpecObj) $Id = $farm_service_helper.Farm_Create($services, $farmSpecObj)
@@ -3139,7 +3124,7 @@ function Get-HVFarmCustomizationSetting {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$instantCloneEngineDomainAdministrator = $insDomainAdministrators | Where $scriptBlock $instantCloneEngineDomainAdministrator = $insDomainAdministrators | Where-Object $scriptBlock
If ($null -ne $instantCloneEngineDomainAdministrator) { If ($null -ne $instantCloneEngineDomainAdministrator) {
$instantCloneEngineDomainAdministrator = $instantCloneEngineDomainAdministrator[0].id $instantCloneEngineDomainAdministrator = $instantCloneEngineDomainAdministrator[0].id
} elseif ($null -ne $insDomainAdministrators) { } elseif ($null -ne $insDomainAdministrators) {
@@ -3167,7 +3152,7 @@ function Get-HVFarmCustomizationSetting {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$ViewComposerDomainAdministratorID = $lcDomainAdministrators | Where $scriptBlock $ViewComposerDomainAdministratorID = $lcDomainAdministrators | Where-Object $scriptBlock
if ($null -ne $ViewComposerDomainAdministratorID) { if ($null -ne $ViewComposerDomainAdministratorID) {
$ViewComposerDomainAdministratorID = $ViewComposerDomainAdministratorID[0].id $ViewComposerDomainAdministratorID = $ViewComposerDomainAdministratorID[0].id
} elseif ($null -ne $lcDomainAdministrators) { } elseif ($null -ne $lcDomainAdministrators) {
@@ -5108,7 +5093,7 @@ function Get-HVHostOrClusterID {
if ($hoctn.container) { if ($hoctn.container) {
foreach ($node in $hoctn.treeContainer.children) { foreach ($node in $hoctn.treeContainer.children) {
$id = Get-HVHostOrClusterID $node $id = Get-HVHostOrClusterID $node
if ($id -ne $null) { if ($null -ne $id) {
return $id return $id
} }
} }
@@ -5146,7 +5131,7 @@ function Get-HVResourcePoolID {
} }
foreach ($child in $rpi.children) { foreach ($child in $rpi.children) {
$id = Get-HVResourcePoolID $child $id = Get-HVResourcePoolID $child
if ($id -ne $null) { if ($null -ne $id) {
return $id return $id
} }
} }
@@ -5191,7 +5176,7 @@ function Get-HVAccessGroupID {
} }
foreach ($child in $element.children) { foreach ($child in $element.children) {
$id = Get-HVAccessGroupID $child $id = Get-HVAccessGroupID $child
if ($id -ne $null) { if ($null -ne $id) {
return $id return $id
} }
} }
@@ -5364,7 +5349,7 @@ function Get-HVPoolCustomizationSetting {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$instantCloneEngineDomainAdministrator = $insDomainAdministrators | Where $scriptBlock $instantCloneEngineDomainAdministrator = $insDomainAdministrators | Where-Object $scriptBlock
If ($null -ne $instantCloneEngineDomainAdministrator) { If ($null -ne $instantCloneEngineDomainAdministrator) {
$instantCloneEngineDomainAdministrator = $instantCloneEngineDomainAdministrator[0].id $instantCloneEngineDomainAdministrator = $instantCloneEngineDomainAdministrator[0].id
} elseif ($null -ne $insDomainAdministrators) { } elseif ($null -ne $insDomainAdministrators) {
@@ -5394,7 +5379,7 @@ function Get-HVPoolCustomizationSetting {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$ViewComposerDomainAdministratorID = $lcDomainAdministrators | Where $scriptBlock $ViewComposerDomainAdministratorID = $lcDomainAdministrators | Where-Object $scriptBlock
If ($null -ne $ViewComposerDomainAdministratorID) { If ($null -ne $ViewComposerDomainAdministratorID) {
$ViewComposerDomainAdministratorID = $ViewComposerDomainAdministratorID[0].id $ViewComposerDomainAdministratorID = $ViewComposerDomainAdministratorID[0].id
} elseif ($null -ne $lcDomainAdministrators) { } elseif ($null -ne $lcDomainAdministrators) {
@@ -5523,7 +5508,7 @@ function Test-HVPoolSpec {
if (! (($PoolObject.AutomatedDesktopSpec.UserAssignment.UserAssignment -eq "FLOATING") -or ($PoolObject.AutomatedDesktopSpec.UserAssignment.UserAssignment -eq "DEDICATED")) ) { if (! (($PoolObject.AutomatedDesktopSpec.UserAssignment.UserAssignment -eq "FLOATING") -or ($PoolObject.AutomatedDesktopSpec.UserAssignment.UserAssignment -eq "DEDICATED")) ) {
Throw "UserAssignment must be FLOATING or DEDICATED" Throw "UserAssignment must be FLOATING or DEDICATED"
} }
if ($PoolObject.AutomatedDesktopSpec.ProvisioningType -eq $null) { if ($null -eq $PoolObject.AutomatedDesktopSpec.ProvisioningType) {
Throw "Pool Provisioning type is empty, need to be configured" Throw "Pool Provisioning type is empty, need to be configured"
} }
$provisionTypeArray = @('VIRTUAL_CENTER', 'VIEW_COMPOSER', 'INSTANT_CLONE_ENGINE') $provisionTypeArray = @('VIRTUAL_CENTER', 'VIEW_COMPOSER', 'INSTANT_CLONE_ENGINE')
@@ -7441,7 +7426,7 @@ function Find-HVMachine {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$machineList += $queryResults.results | where $scriptBlock $machineList += $queryResults.results | Where-Object $scriptBlock
$GetNext = $true $GetNext = $true
} while ($queryResults.remainingCount -gt 0) } while ($queryResults.remainingCount -gt 0)
$query_service_helper.QueryService_Delete($services, $queryResults.id) $query_service_helper.QueryService_Delete($services, $queryResults.id)
@@ -7514,10 +7499,7 @@ function Get-HVMachine {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -7637,10 +7619,7 @@ function Get-HVMachineSummary {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -7915,7 +7894,7 @@ function Get-DataStoreName {
) )
$dataStoresObj = @() $dataStoresObj = @()
$entityId = New-Object VMware.Hv.EntityId $entityId = New-Object VMware.Hv.EntityId
$datastores | % { $datastores | ForEach-Object {
$entityId.Id = $_.datastore.Id $entityId.Id = $_.datastore.Id
$dataStoresObj += , (New-Object PsObject -Property @{ $dataStoresObj += , (New-Object PsObject -Property @{
datastore = Get-HVInternalName -EntityId $entityId; datastore = Get-HVInternalName -EntityId $entityId;
@@ -7958,10 +7937,7 @@ function Get-HVInternalName {
PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1 PowerCLI Version : PowerCLI 6.5, PowerCLI 6.5.1
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
@@ -8004,15 +7980,15 @@ function Get-HVInternalName {
return $Info.Base.Username return $Info.Base.Username
} }
'BaseImageVm' { 'BaseImageVm' {
$info = $services.BaseImageVm.BaseImageVm_List($VcId) | where { $_.id.id -eq $EntityId.id } $info = $services.BaseImageVm.BaseImageVm_List($VcId) | Where-Object { $_.id.id -eq $EntityId.id }
return $info.name return $info.name
} }
'BaseImageSnapshot' { 'BaseImageSnapshot' {
$info = $services.BaseImageSnapshot.BaseImageSnapshot_List($BaseImageVmId) | where { $_.id.id -eq $EntityId.id } $info = $services.BaseImageSnapshot.BaseImageSnapshot_List($BaseImageVmId) | Where-Object { $_.id.id -eq $EntityId.id }
return $info.name return $info.name
} }
'VmTemplate' { 'VmTemplate' {
$info = $services.VmTemplate.VmTemplate_List($VcId) | where { $_.id.id -eq $EntityId.id } $info = $services.VmTemplate.VmTemplate_List($VcId) | Where-Object { $_.id.id -eq $EntityId.id }
return $info.name return $info.name
} }
'ViewComposerDomainAdministrator' { 'ViewComposerDomainAdministrator' {
@@ -8045,10 +8021,7 @@ function Get-HVInternalName {
function Get-UserInfo { function Get-UserInfo {
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[ValidatePattern("^.+?[@\\].+?$")] [ValidatePattern("^.+?[@\\].+?$")]
@@ -8370,10 +8343,7 @@ function Get-HVEntitlement {
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[ValidatePattern("^.+?[@\\].+?$")] [ValidatePattern("^.+?[@\\].+?$")]
@@ -8438,7 +8408,7 @@ function Get-HVEntitlement {
} }
$AndFilter = Get-HVQueryFilter -And -Filters $AndFilter $AndFilter = Get-HVQueryFilter -And -Filters $AndFilter
$results = (Get-HVQueryResult -EntityType EntitledUserOrGroupLocalSummaryView -Filter $AndFilter -HvServer $HvServer) $results = (Get-HVQueryResult -EntityType EntitledUserOrGroupLocalSummaryView -Filter $AndFilter -HvServer $HvServer)
$results = $results | where {$_.localData.desktops -ne $null} $results = $results | Where-Object {$null -ne $_.localData.desktops}
} }
"Application" { "Application" {
if ($ResourceName) { if ($ResourceName) {
@@ -8452,7 +8422,7 @@ function Get-HVEntitlement {
} }
$AndFilter = Get-HVQueryFilter -And -Filters $AndFilter $AndFilter = Get-HVQueryFilter -And -Filters $AndFilter
$results = (Get-HVQueryResult -EntityType EntitledUserOrGroupLocalSummaryView -Filter $AndFilter -HvServer $HvServer) $results = (Get-HVQueryResult -EntityType EntitledUserOrGroupLocalSummaryView -Filter $AndFilter -HvServer $HvServer)
$results = $results | where {$_.localData.applications -ne $null} $results = $results | Where-Object {$null -ne $_.localData.applications}
} }
"URLRedirection" { "URLRedirection" {
$localFilter = @() $localFilter = @()
@@ -8473,11 +8443,11 @@ function Get-HVEntitlement {
} }
$localFilter = Get-HVQueryFilter -And -Filters $localFilter $localFilter = Get-HVQueryFilter -And -Filters $localFilter
$localResults = Get-HVQueryResult -EntityType EntitledUserOrGroupLocalSummaryView -Filter $localFilter -HvServer $HvServer $localResults = Get-HVQueryResult -EntityType EntitledUserOrGroupLocalSummaryView -Filter $localFilter -HvServer $HvServer
$results += ($localResults | where {$_.localData.urlRedirectionSettings -ne $null}) $results += ($localResults | Where-Object {$null -ne $_.localData.urlRedirectionSettings})
if ($cpaEnabled) { if ($cpaEnabled) {
$globalFilter = Get-HVQueryFilter -And -Filters $globalFilter $globalFilter = Get-HVQueryFilter -And -Filters $globalFilter
$globalResults = Get-HVQueryResult -EntityType EntitledUserOrGroupGlobalSummaryView -Filter $globalFilter -HvServer $HvServer $globalResults = Get-HVQueryResult -EntityType EntitledUserOrGroupGlobalSummaryView -Filter $globalFilter -HvServer $HvServer
$globalResults = $globalResults | where {$_.globalData.urlRedirectionSettings -ne $null} $globalResults = $globalResults | Where-Object {$null -ne $_.globalData.urlRedirectionSettings}
$results += $globalResults $results += $globalResults
} }
} }
@@ -8497,7 +8467,7 @@ function Get-HVEntitlement {
} }
$AndFilter = Get-HVQueryFilter -And -Filters $AndFilter $AndFilter = Get-HVQueryFilter -And -Filters $AndFilter
$results = (Get-HVQueryResult -EntityType EntitledUserOrGroupGlobalSummaryView -Filter $AndFilter -HvServer $HvServer) $results = (Get-HVQueryResult -EntityType EntitledUserOrGroupGlobalSummaryView -Filter $AndFilter -HvServer $HvServer)
$results = $results| where {$_.globalData.globalApplicationEntitlements -ne $null} $results = $results| Where-Object {$null -ne $_.globalData.globalApplicationEntitlements}
} }
"GlobalEntitlement" { "GlobalEntitlement" {
if (! $cpaEnabled) { if (! $cpaEnabled) {
@@ -8515,7 +8485,7 @@ function Get-HVEntitlement {
} }
$AndFilter = Get-HVQueryFilter -And -Filters $AndFilter $AndFilter = Get-HVQueryFilter -And -Filters $AndFilter
$results = (Get-HVQueryResult -EntityType EntitledUserOrGroupGlobalSummaryView -Filter $AndFilter -HvServer $HvServer) $results = (Get-HVQueryResult -EntityType EntitledUserOrGroupGlobalSummaryView -Filter $AndFilter -HvServer $HvServer)
$results = $results | where {$_.globalData.globalEntitlements -ne $null} $results = $results | Where-Object {$null -ne $_.globalData.globalEntitlements}
} }
} }
if (! $results) { if (! $results) {
@@ -9213,7 +9183,7 @@ function Find-HVGlobalEntitlement {
} }
$whereClause = [string]::Join(' -and ', $strFilterSet) $whereClause = [string]::Join(' -and ', $strFilterSet)
$scriptBlock = [Scriptblock]::Create($whereClause) $scriptBlock = [Scriptblock]::Create($whereClause)
$GeList = $queryResults.results | where $scriptBlock $GeList = $queryResults.results | Where-Object $scriptBlock
} }
Return $GeList Return $GeList
} }
@@ -9257,10 +9227,7 @@ function Get-HVGlobalEntitlement {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
@@ -9613,10 +9580,7 @@ The get-hvglobalsession gets all local session by using view API service object(
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -9755,23 +9719,25 @@ function Set-HVApplicationIcon {
break break
} }
$ApplicationIconHelper = New-Object VMware.Hv.ApplicationIconService If ($Force -or $PSCmdlet.ShouldProcess($ApplicationName)) {
try { $ApplicationIconHelper = New-Object VMware.Hv.ApplicationIconService
$ApplicationIconId = $ApplicationIconHelper.ApplicationIcon_CreateAndAssociate($services, $spec) try {
} catch { $ApplicationIconId = $ApplicationIconHelper.ApplicationIcon_CreateAndAssociate($services, $spec)
if ($_.Exception.InnerException.MethodFault.GetType().name.Equals('EntityAlreadyExists')) { } catch {
# This icon is already part of LDAP and associated with some other application(s). if ($_.Exception.InnerException.MethodFault.GetType().name.Equals('EntityAlreadyExists')) {
# In this case, call updateAssociations # This icon is already part of LDAP and associated with some other application(s).
$applicationIconId = $_.Exception.InnerException.MethodFault.Id # In this case, call updateAssociations
Write-Host "Some application(s) already have an association for the specified icon." $applicationIconId = $_.Exception.InnerException.MethodFault.Id
$ApplicationIconHelper.ApplicationIcon_UpdateAssociations($services, $applicationIconId, @($appInfo.Id)) Write-Host "Some application(s) already have an association for the specified icon."
Write-Host "Successfully updated customized icon association for Application:[$ApplicationName]." $ApplicationIconHelper.ApplicationIcon_UpdateAssociations($services, $applicationIconId, @($appInfo.Id))
break Write-Host "Successfully updated customized icon association for Application:[$ApplicationName]."
} break
Write-Host "Error in associating customized icon for Application:[$ApplicationName] $_" }
break Write-Host "Error in associating customized icon for Application:[$ApplicationName] $_"
break
}
Write-Host "Successfully associated customized icon for Application:[$ApplicationName]."
} }
Write-Host "Successfully associated customized icon for Application:[$ApplicationName]."
} }
end { end {
@@ -9860,13 +9826,17 @@ Function Remove-HVApplicationIcon {
break break
} }
try { if ($Force -or $PSCmdlet.ShouldProcess($ApplicationName)) {
$ApplicationIconHelper.ApplicationIcon_RemoveAssociations($services, $brokerIcon, @($appInfo.Id))
} catch { try {
Write-Error "Error in removing the customized icon association for Application:[$ApplicationName] $_ " $ApplicationIconHelper.ApplicationIcon_RemoveAssociations($services, $brokerIcon, @($appInfo.Id))
break } catch {
Write-Error "Error in removing the customized icon association for Application:[$ApplicationName] $_ "
break
}
Write-Host "Successfully removed customized icon association for Application:[$ApplicationName]."
} }
Write-Host "Successfully removed customized icon association for Application:[$ApplicationName]."
} }
end { end {
@@ -9903,10 +9873,7 @@ function Get-HVGlobalSettings {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -10252,9 +10219,15 @@ function Set-HVGlobalSettings {
$updates += Get-MapEntry -key 'securityData.enableIPSecForSecurityServerPairing' -Value $enableIPSecForSecurityServerPairing $updates += Get-MapEntry -key 'securityData.enableIPSecForSecurityServerPairing' -Value $enableIPSecForSecurityServerPairing
} }
$global_settings_helper = New-Object VMware.Hv.GlobalSettingsService if ($Force -or $PSCmdlet.ShouldProcess($HVServer.Name)) {
$global_settings_helper.GlobalSettings_Update($services,$updates) $global_settings_helper = New-Object VMware.Hv.GlobalSettingsService
$global_settings_helper.GlobalSettings_Update($services,$updates)
Write-Host "Global settings updated."
}
} }
@@ -10263,19 +10236,19 @@ function Set-HVGlobalSettings {
} }
} }
function get-HVlocalsession { function Get-HVLocalSession {
<# <#
.SYNOPSIS .SYNOPSIS
Provides a list with all sessions on the local pod (works in CPA and non-CPA) Provides a list with all sessions on the local pod (works in CPA and non-CPA)
.DESCRIPTION .DESCRIPTION
The get-hvlocalsession gets all local session by using view API service object(hvServer) of Connect-HVServer cmdlet. The Get-HVLocalSession gets all local session by using view API service object(hvServer) of Connect-HVServer cmdlet.
.PARAMETER HvServer .PARAMETER HvServer
View API service object of Connect-HVServer cmdlet. View API service object of Connect-HVServer cmdlet.
.EXAMPLE .EXAMPLE
Get-hvlocalsession Get-HVLocalSession
Get all local sessions Get all local sessions
.NOTES .NOTES
@@ -10289,10 +10262,7 @@ The get-hvlocalsession gets all local session by using view API service object(h
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
@@ -10363,35 +10333,46 @@ function Reset-HVMachine {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding(
SupportsShouldProcess = $true, SupportsShouldProcess = $true,
ConfirmImpact = 'High' ConfirmImpact = 'High'
)] )]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string] [string]
$MachineName, $MachineName,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
$HvServer = $null $HvServer = $null
) )
Begin {
$services = Get-ViewAPIService -hvServer $hvServer $services = Get-ViewAPIService -hvServer $hvServer
if ($null -eq $services) {
Write-Error "Could not retrieve ViewApi services from connection object"
break
}
$machineList = Find-HVMachine -Param $PSBoundParameters if ($null -eq $services) {
if (!$machineList) { Write-Error "Could not retrieve ViewApi services from connection object"
Write-Host "Reset-HVMachine: No Virtual Machine(s) Found with given search parameters" break
break }
$machineList = Find-HVMachine -Param $PSBoundParameters
if (!$machineList) {
Write-Host "Reset-HVMachine: No Virtual Machine(s) Found with given search parameters"
break
}
} }
foreach ($machine in $machinelist){ Process {
$services.machine.Machine_ResetMachines($machine.id) if ($Force -or $PSCmdlet.ShouldProcess($MachineName)) {
foreach ($machine in $machinelist){
$services.machine.Machine_ResetMachines($machine.id)
}
}
}
End {
[System.gc]::collect()
} }
} }
function Remove-HVMachine { function Remove-HVMachine {
@@ -10439,138 +10420,143 @@ function Remove-HVMachine {
#> #>
[CmdletBinding( [CmdletBinding(
SupportsShouldProcess = $true, SupportsShouldProcess = $true,
ConfirmImpact = 'High' ConfirmImpact = 'High'
)] )]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[array] [array]
$MachineNames, $MachineNames,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[switch]$DeleteFromDisk = $true, [switch]$DeleteFromDisk,
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
$HVServer = $null $HVServer = $null
) )
#Connect to HV Server Begin {
$services = Get-ViewAPIService -HVServer $HVServer #Connect to HV Server
$services = Get-ViewAPIService -HVServer $HVServer
if ($null -eq $services) {
Write-Error "Could not retrieve ViewApi services from connection object"
break
}
#Connect to Query Service
$queryService = New-Object 'Vmware.Hv.QueryServiceService'
#QUery Definition
$queryDefinition = New-Object 'Vmware.Hv.QueryDefinition'
#Query Filter
$queryDefinition.queryEntityType = 'MachineNamesView'
#Create Filter Set so we can populate it with QueryFilterEquals data
[VMware.Hv.queryfilter[]]$filterSet = @()
foreach($machine in $machineNames){
#queryfilter values
$queryFilterEquals = New-Object VMware.Hv.QueryFilterEquals
$queryFilterEquals.memberName = "base.name"
$queryFilterEquals.value = "$machine"
$filterSet += $queryFilterEquals
}
#Or Filter
$orFilter = New-Object VMware.Hv.QueryFilterOr
$orFilter.filters = $filterSet
#Set Definition filter to value of $orfilter
$queryDefinition.filter = $orFilter
#Retrieve query results. Returns all machines to be deleted
$queryResults = $queryService.QueryService_Query($services,$queryDefinition)
#Assign VM Object to variable
$deleteThisMachine = $queryResults.Results
#Machine Service
$machineService = new-object VMware.Hv.MachineService
#Get Machine Service machine object
$deleteMachine = $machineService.Machine_GetInfos($services,$deleteThisMachine.Id)
#If sessions exist on the machines we are going to delete than force kill those sessions.
#The deleteMachines method will not work if there are any existing sessions so this step is very important.
write-host "Attemtping log off of machines"
if($deleteMachine.base.session.id){
$trys = 0
do{
foreach($session in $deleteMachine.base.session){
$sessions = $null
[VMware.Hv.SessionId[]]$sessions += $session
}
try{
write-host "`n"
write-host "Attemtping log off of machines"
write-host "`n"
$logOffSession = new-object 'VMware.Hv.SessionService'
$logOffSession.Session_LogoffSessionsForced($services,$sessions)
#Wait more for Sessions to end
Start-Sleep -Seconds 5
}
catch{
Write-Host "Attempted to Log Off Sessions from below machines but recieved an error. This doesn't usually mean it failed. Typically the session is succesfully logged off but takes some time"
write-host "`n"
write-host ($deleteMachine.base.Name -join "`n")
start-sleep -seconds 5
if ($null -eq $services) {
Write-Error "Could not retrieve ViewApi services from connection object"
break
} }
if(($trys -le 10)){ #Connect to Query Service
$queryService = New-Object 'Vmware.Hv.QueryServiceService'
#QUery Definition
$queryDefinition = New-Object 'Vmware.Hv.QueryDefinition'
#Query Filter
$queryDefinition.queryEntityType = 'MachineNamesView'
}
Process {
#Create Filter Set so we can populate it with QueryFilterEquals data
[VMware.Hv.queryfilter[]]$filterSet = @()
foreach($machine in $machineNames){
write-host "`n" #queryfilter values
write-host "Retrying Logoffs: $trys times" $queryFilterEquals = New-Object VMware.Hv.QueryFilterEquals
#Recheck existing sessions $queryFilterEquals.memberName = "base.name"
$deleteMachine = $machineService.Machine_GetInfos($services,$deleteThisMachine.Id) $queryFilterEquals.value = "$machine"
$filterSet += $queryFilterEquals
}
#Or Filter
$orFilter = New-Object VMware.Hv.QueryFilterOr
$orFilter.filters = $filterSet
#Set Definition filter to value of $orfilter
$queryDefinition.filter = $orFilter
#Retrieve query results. Returns all machines to be deleted
$queryResults = $queryService.QueryService_Query($services,$queryDefinition)
#Assign VM Object to variable
$deleteThisMachine = $queryResults.Results
if ($Force -or $PSCmdlet.ShouldProcess($deleteThisMachine)) {
#Machine Service
$machineService = new-object VMware.Hv.MachineService
#Get Machine Service machine object
$deleteMachine = $machineService.Machine_GetInfos($services,$deleteThisMachine.Id)
#If sessions exist on the machines we are going to delete than force kill those sessions.
#The deleteMachines method will not work if there are any existing sessions so this step is very important.
write-host "Attempting log off of machines"
if($deleteMachine.base.session.id){
$trys = 0
do{
foreach($session in $deleteMachine.base.session){
$sessions = $null
[VMware.Hv.SessionId[]]$sessions += $session
}
try{
write-host "`n"
write-host "Attempting log off of machines"
write-host "`n"
$logOffSession = new-object 'VMware.Hv.SessionService'
$logOffSession.Session_LogoffSessionsForced($services,$sessions)
#Wait more for Sessions to end
Start-Sleep -Seconds 5
}
catch{
Write-Host "Attempted to Log Off Sessions from below machines but recieved an error. This doesn't usually mean it failed. Typically the session is succesfully logged off but takes some time"
write-host "`n"
write-host ($deleteMachine.base.Name -join "`n")
start-sleep -seconds 5
}
if(($trys -le 10)){
write-host "`n"
write-host "Retrying Logoffs: $trys times"
#Recheck existing sessions
$deleteMachine = $machineService.Machine_GetInfos($services,$deleteThisMachine.Id)
}
$trys++
} }
$trys++ until((!$deleteMachine.base.session.id) -or ($trys -gt 10))
}
#Create delete spec for the DeleteMachines method
$deleteSpec = [VMware.Hv.MachineDeleteSpec]::new()
$deleteSpec.DeleteFromDisk = $DeleteFromDisk
$deleteSpec.ArchivePersistentDisk = $false
#Delete the machines
if($DeleteFromDisk){write-host "Attempting to Delete:"}else{write-host "Attempting to remove from inventory:"}
Write-Output ($deleteMachine.base.Name -join "`n")
$machineService.Machine_DeleteMachines($services,$deleteMachine.id,$deleteSpec)
} }
}
until((!$deleteMachine.base.session.id) -or ($trys -gt 10)) End {
[System.gc]::collect()
} }
#Create delete spec for the DeleteMachines method
$deleteSpec = [VMware.Hv.MachineDeleteSpec]::new()
$deleteSpec.DeleteFromDisk = $DeleteFromDisk
$deleteSpec.ArchivePersistentDisk = $false
#Delete the machines
if($DeleteFromDisk){write-host "Attempting to Delete:"}else{write-host "Attempting to remove from inventory:"}
Write-Output ($deleteMachine.base.Name -join "`n")
$bye = $machineService.Machine_DeleteMachines($services,$deleteMachine.id,$deleteSpec)
[System.gc]::collect()
} }
function Get-HVHealth { function Get-HVHealth {
@@ -10610,10 +10596,7 @@ function Get-HVHealth {
PowerShell Version : 5.0 PowerShell Version : 5.0
#> #>
[CmdletBinding( [CmdletBinding()]
SupportsShouldProcess = $true,
ConfirmImpact = 'High'
)]
param( param(
@@ -10772,7 +10755,7 @@ function remove-hvpodfederation {
[System.gc]::collect() [System.gc]::collect()
} }
function get-hvpodfederation { function Get-HVPodFederation {
<# <#
.Synopsis .Synopsis
Returns information about a Horizon View Pod Federation (Cloud Pod Architecture) Returns information about a Horizon View Pod Federation (Cloud Pod Architecture)
@@ -10785,7 +10768,7 @@ function get-hvpodfederation {
first element from global:DefaultHVServers would be considered in-place of hvServer first element from global:DefaultHVServers would be considered in-place of hvServer
.EXAMPLE .EXAMPLE
get-hvpodfederation Get-HVPodFederation
Returns information about a Horizon View Pod Federation Returns information about a Horizon View Pod Federation
.NOTES .NOTES
@@ -10801,7 +10784,7 @@ function get-hvpodfederation {
[CmdletBinding( [CmdletBinding(
SupportsShouldProcess = $false, SupportsShouldProcess = $false,
ConfirmImpact = 'High' ConfirmImpact = 'None'
)] )]
param( param(
@@ -11053,7 +11036,7 @@ function set-hvpodfederation {
$podservicehelper=$podservice.read($services) $podservicehelper=$podservice.read($services)
$podservicehelper.getDatahelper().setdisplayname($name) $podservicehelper.getDatahelper().setdisplayname($name)
$podservice.update($services, $podservicehelper) $podservice.update($services, $podservicehelper)
get-hvpodfederation Get-HVPodFederation
[System.gc]::collect() [System.gc]::collect()
} }
@@ -11480,7 +11463,6 @@ function New-HVHomeSite {
} }
process { process {
$confirmFlag = Get-HVConfirmFlag -keys $PsBoundParameters.Keys
$groupinfo = Get-UserInfo -UserName $Group $groupinfo = Get-UserInfo -UserName $Group
$UserOrGroupName = $groupinfo.Name $UserOrGroupName = $groupinfo.Name
$Domain = $groupinfo.Domain $Domain = $groupinfo.Domain