Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Description
- <#
- ########################################################################
- Lab 20
- Scenario:
- User01 is experiencing slow behavior when connected to a desktop in the
- PCoIPDTP desktop pool.
- ########################################################################
- #>
- #endregion
- #region requires
- #requires -Version 4.0
- #requires -Modules mod_requirements, mod_common, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.0.0.0"}
- #endregion
- #region variables
- $vCenter = $ClassXml.Class.Infrastructure.vCenter
- $victimVM = $ClassXml.Class.Modules.Module6.b61.VM
- $csRes = $ClassXml.Class.Modules.Module6.b61.CsRes
- $adm = $ClassXml.Class.Modules.Module6.b61.AdmFile
- $pol = $ClassXml.Class.Modules.Module6.b61.PolFile
- $defPol = $ClassXml.Class.Modules.Module6.b61.DefPol
- $polPath = $ClassXml.Class.Modules.Module6.b61.RegPath
- $polKey = $ClassXml.Class.Modules.Module6.b61.RegKey
- $polVal = $ClassXml.Class.Modules.Module6.b61.RegVal
- $gpoPath = $ClassXml.Class.Modules.Module6.b61.GpoRoot
- #endregion
- Write-Host -NoNewLine $INFO_CONNECT_TARGET
- $ret = Connect-VISystem -VIHost $vCenter.Name -Username $vCenter.Username -Password $vCenter.Password
- if ($ret) {
- Add-StatusCode $STATUS_OK
- } else {
- Add-StatusCode $STATUS_FAIL
- Write-Host -ForegroundColor Yellow $WARN_SEEK_ASSISTANCE
- Write-Host
- throw $ERROR_CONNECT_TARGET
- }
- Write-Host -NoNewline $INFO_DISCOVER_ENV
- try {
- $targetVM = Get-VM -Name $victimVM.Name
- if ($targetVM.PowerState -ne "PoweredOn") { throw $ERROR_VM_NOT_RUNNING }
- $viewVM = Get-VirtualServerFromLdap -DisplayName $victimVM.Name
- if ($viewVM.'pae-VmState' -ne "READY") { throw $ERROR_VIEW_VM_NOT_READY }
- $credential = New-Object System.Management.Automation.PSCredential($victimVM.Username,(ConvertTo-SecureString -String $victimVM.Password -AsPlainText -Force))
- Add-StatusCode $STATUS_OK
- } catch {
- Add-StatusCode $STATUS_FAIL
- Write-Host
- Write-Host -ForegroundColor Yellow $WARN_NOT_YET_READY
- Write-Host
- Write-Host -ForegroundColor Red $ERROR_DISCOVER_DMG_COMPONENTS
- Write-Host
- Write-Host -ForegroundColor Red $ERROR_INTERCEPT_MSG $_
- Disconnect-VIServer -Confirm:$false
- if ($ShowDetailedError) { throw $_ } else { exit }
- }
- Write-Host -NoNewline $INFO_APPLYING_DMG_LONG
- try {
- try
- {
- Connect-viServer 172.20.10.94 -User administrator@vsphere.local -Password VMware1!
- Copy-VMGuestFile -GuestToLocal -source "C:\Windows\System32\GroupPolicy\Machine\Registry.pol" -Destination "C:\Scripts\Mod6" -VM PCoIPDT-1
- $desteny = [System.IO.Path]::GetTempPath()
- write-host $desteny
- Move-Item "C:\Scripts\Mod6\Registry.pol" -Destination $desteny -Force
- }
- catch
- {
- Write-Host "Copy failed, using local"
- Copy-Item -Path (Join-Path -Path $DamageScriptRootPath -ChildPath $defPol) -Destination ([System.IO.Path]::GetTempPath())
- }
- $targetFile = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetFileName($pol))
- try
- {
- if (-not ("TJX.PolFileEditor.PolFile" -as [type]))
- {
- $cs = Join-Path $DamageScriptRootPath -ChildPath $csRes
- Add-Type -Path $cs
- }
- $polFile = New-Object TJX.PolFileEditor.PolFile
- $polFile.LoadFile($targetFile)
- $polFile.SetDWORDValue($polPath,$polKey,$polVal)
- $polFile.SaveFile()
- $admSrc = Join-Path -Path $DamagescriptRootPath -ChildPath $adm
- $admPath = Join-Path -Path $gpoPath -ChildPath "Adm"
- write-host $admSrc $admPath
- Copy-VMGuestFile -LocalToGuest -Source "C:\Scripts\Dependencies\resources\pcoip.adm" -Destination "C:\Windows\System32\GroupPolicy\Adm\" -VM $targetVM -Force
- $machinePath = Join-Path -Path $gpopath -ChildPath "Machine"
- write-host "test23"
- Copy-VMGuestFile -LocalToGuest -Source "C:\Users\administrator.VCLASS\AppData\Local\Temp\Registry.pol" -Destination "C:\Windows\System32\GroupPolicy\Machine\" -VM "PCoIPDT-1" -Force
- write-host "dfsdgjnskg"
- $dmg = @()
- $dmg += '$gptContents = Get-Content $env:systemroot\system32\GroupPolicy\gpt.ini'
- $dmg += '$gptContents | %{ [regex]::Replace($_, "(?<=Version\s*=\s*)\d+", { [int]$args[0].Value + 1 }) } | Set-Content $env:systemroot\system32\GroupPolicy\gpt.ini -Force'
- $dmg += 'Invoke-Command {gpupdate /force}'
- Invoke-VMScript -VM $targetVM -ScriptText ($dmg -join "`n") -ScriptType Powershell -GuestCredential $credential | Out-Null
- Add-StatusCode $STATUS_OK
- }a
- catch
- {
- throw $_
- }
- }
- catch
- {
- Add-StatusCode $STATUS_FAIL
- Write-Host
- Write-Host -ForegroundColor Yellow $WARN_NOT_YET_READY
- Write-Host
- Write-Host -ForegroundColor Red $ERROR_APPLY_DAMAGE_FAILED
- Write-Host
- Write-Host -ForegroundColor Red $ERROR_INTERCEPT_MSG $_
- Disconnect-VIServer -Confirm:$false
- if ($ShowDetailedError) { throw $_ } else { exit }
- }
- Write-Host
- Write-Host
- Write-Host -ForegroundColor Green $INFO_READY_TO_START_LAB
- Write-Host
- Disconnect-VIServer -Confirm:$false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement