Advertisement
Guest User

dg

a guest
Jun 26th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. #region Description
  2. <#
  3. ########################################################################
  4. Lab 20
  5.  
  6. Scenario:
  7. User01 is experiencing slow behavior when connected to a desktop in the
  8. PCoIPDTP desktop pool.
  9. ########################################################################
  10. #>
  11. #endregion
  12.  
  13. #region requires
  14. #requires -Version 4.0
  15. #requires -Modules mod_requirements, mod_common, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.0.0.0"}
  16. #endregion
  17.  
  18. #region variables
  19. $vCenter = $ClassXml.Class.Infrastructure.vCenter
  20. $victimVM = $ClassXml.Class.Modules.Module6.b61.VM
  21. $csRes = $ClassXml.Class.Modules.Module6.b61.CsRes
  22. $adm = $ClassXml.Class.Modules.Module6.b61.AdmFile
  23. $pol = $ClassXml.Class.Modules.Module6.b61.PolFile
  24. $defPol = $ClassXml.Class.Modules.Module6.b61.DefPol
  25. $polPath = $ClassXml.Class.Modules.Module6.b61.RegPath
  26. $polKey = $ClassXml.Class.Modules.Module6.b61.RegKey
  27. $polVal = $ClassXml.Class.Modules.Module6.b61.RegVal
  28. $gpoPath = $ClassXml.Class.Modules.Module6.b61.GpoRoot
  29. #endregion
  30.  
  31. Write-Host -NoNewLine $INFO_CONNECT_TARGET
  32. $ret = Connect-VISystem -VIHost $vCenter.Name -Username $vCenter.Username -Password $vCenter.Password
  33. if ($ret) {
  34. Add-StatusCode $STATUS_OK
  35. } else {
  36. Add-StatusCode $STATUS_FAIL
  37. Write-Host -ForegroundColor Yellow $WARN_SEEK_ASSISTANCE
  38. Write-Host
  39. throw $ERROR_CONNECT_TARGET
  40. }
  41.  
  42. Write-Host -NoNewline $INFO_DISCOVER_ENV
  43. try {
  44. $targetVM = Get-VM -Name $victimVM.Name
  45.  
  46. if ($targetVM.PowerState -ne "PoweredOn") { throw $ERROR_VM_NOT_RUNNING }
  47.  
  48. $viewVM = Get-VirtualServerFromLdap -DisplayName $victimVM.Name
  49. if ($viewVM.'pae-VmState' -ne "READY") { throw $ERROR_VIEW_VM_NOT_READY }
  50.  
  51. $credential = New-Object System.Management.Automation.PSCredential($victimVM.Username,(ConvertTo-SecureString -String $victimVM.Password -AsPlainText -Force))
  52. Add-StatusCode $STATUS_OK
  53. } catch {
  54. Add-StatusCode $STATUS_FAIL
  55. Write-Host
  56. Write-Host -ForegroundColor Yellow $WARN_NOT_YET_READY
  57. Write-Host
  58. Write-Host -ForegroundColor Red $ERROR_DISCOVER_DMG_COMPONENTS
  59. Write-Host
  60. Write-Host -ForegroundColor Red $ERROR_INTERCEPT_MSG $_
  61. Disconnect-VIServer -Confirm:$false
  62. if ($ShowDetailedError) { throw $_ } else { exit }
  63. }
  64.  
  65. Write-Host -NoNewline $INFO_APPLYING_DMG_LONG
  66. try {
  67. try
  68. {
  69.  
  70. Connect-viServer 172.20.10.94 -User administrator@vsphere.local -Password VMware1!
  71.  
  72. Copy-VMGuestFile -GuestToLocal -source "C:\Windows\System32\GroupPolicy\Machine\Registry.pol" -Destination "C:\Scripts\Mod6" -VM PCoIPDT-1
  73.  
  74. $desteny = [System.IO.Path]::GetTempPath()
  75.  
  76. write-host $desteny
  77.  
  78. Move-Item "C:\Scripts\Mod6\Registry.pol" -Destination $desteny -Force
  79.  
  80.  
  81. }
  82. catch
  83. {
  84. Write-Host "Copy failed, using local"
  85. Copy-Item -Path (Join-Path -Path $DamageScriptRootPath -ChildPath $defPol) -Destination ([System.IO.Path]::GetTempPath())
  86. }
  87. $targetFile = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetFileName($pol))
  88.  
  89. try
  90. {
  91. if (-not ("TJX.PolFileEditor.PolFile" -as [type]))
  92. {
  93. $cs = Join-Path $DamageScriptRootPath -ChildPath $csRes
  94. Add-Type -Path $cs
  95. }
  96.  
  97. $polFile = New-Object TJX.PolFileEditor.PolFile
  98. $polFile.LoadFile($targetFile)
  99.  
  100. $polFile.SetDWORDValue($polPath,$polKey,$polVal)
  101. $polFile.SaveFile()
  102.  
  103.  
  104. $admSrc = Join-Path -Path $DamagescriptRootPath -ChildPath $adm
  105. $admPath = Join-Path -Path $gpoPath -ChildPath "Adm"
  106.  
  107. write-host $admSrc $admPath
  108.  
  109. Copy-VMGuestFile -LocalToGuest -Source "C:\Scripts\Dependencies\resources\pcoip.adm" -Destination "C:\Windows\System32\GroupPolicy\Adm\" -VM $targetVM -Force
  110.  
  111. $machinePath = Join-Path -Path $gpopath -ChildPath "Machine"
  112.  
  113. write-host "test23"
  114.  
  115. Copy-VMGuestFile -LocalToGuest -Source "C:\Users\administrator.VCLASS\AppData\Local\Temp\Registry.pol" -Destination "C:\Windows\System32\GroupPolicy\Machine\" -VM "PCoIPDT-1" -Force
  116.  
  117. write-host "dfsdgjnskg"
  118.  
  119. $dmg = @()
  120. $dmg += '$gptContents = Get-Content $env:systemroot\system32\GroupPolicy\gpt.ini'
  121. $dmg += '$gptContents | %{ [regex]::Replace($_, "(?<=Version\s*=\s*)\d+", { [int]$args[0].Value + 1 }) } | Set-Content $env:systemroot\system32\GroupPolicy\gpt.ini -Force'
  122. $dmg += 'Invoke-Command {gpupdate /force}'
  123.  
  124. Invoke-VMScript -VM $targetVM -ScriptText ($dmg -join "`n") -ScriptType Powershell -GuestCredential $credential | Out-Null
  125. Add-StatusCode $STATUS_OK
  126. }a
  127. catch
  128. {
  129. throw $_
  130. }
  131. }
  132. catch
  133. {
  134. Add-StatusCode $STATUS_FAIL
  135. Write-Host
  136. Write-Host -ForegroundColor Yellow $WARN_NOT_YET_READY
  137. Write-Host
  138. Write-Host -ForegroundColor Red $ERROR_APPLY_DAMAGE_FAILED
  139. Write-Host
  140. Write-Host -ForegroundColor Red $ERROR_INTERCEPT_MSG $_
  141. Disconnect-VIServer -Confirm:$false
  142. if ($ShowDetailedError) { throw $_ } else { exit }
  143. }
  144. Write-Host
  145. Write-Host
  146. Write-Host -ForegroundColor Green $INFO_READY_TO_START_LAB
  147. Write-Host
  148. Disconnect-VIServer -Confirm:$false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement