Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. Function CheckComputer {
  2. $global:CompExists = $null
  3.  
  4. #CHANGED
  5. $Connectivity = $(try {Test-Connection -ComputerName $CNText.Text -Count 1 -Quiet} catch {$null})
  6. #$Connectivity
  7. if ($Connectivity -eq $true)
  8. {
  9. $Details.SelectionColor = 'Green'
  10. $global:CompExists = $true
  11.  
  12. # CHANGED
  13. return 'Online'
  14.  
  15. } else {
  16. $Details.SelectionColor = 'Red'
  17. $global:CompExists = $false
  18. # CHANGED
  19. return 'Offline'
  20. }
  21. }
  22.  
  23. Function CheckUser{
  24. Import-Module ActiveDirectory
  25. $global:UserExists = $null
  26. $User = $(try { Get-ADUser $SNText.Text -Properties *} catch {$null})
  27. $CheckUser = $User
  28. If ($CheckUser -ne $null)
  29. {
  30. $Details.SelectionColor = 'Green'
  31. $global:UserExists = $true
  32.  
  33. # CHANGED
  34. return $User.DisplayName
  35. #$Details.Text = $UserExists
  36. }
  37. Else
  38. {
  39. $global:UserExists = $false
  40.  
  41. # CHANGED
  42. $Details.SelectionColor = 'Red'
  43. $global:UserExists = $true
  44. return 'User Not Found'
  45. }
  46. }
  47.  
  48. Function EnableRemoteDesktop
  49. {
  50. $Details.Refresh()
  51. $Details.Text = "Please Wait..."
  52. if ($CompExists -and $UserExists -eq $true)
  53. {
  54. $( try {Invoke-Command -Computername $CNText.Text -ScriptBlock {Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" –Value 0; Enable-NetFirewallRule -DisplayGroup "Remote Desktop";Add-LocalGroupMember -Group "Remote Desktop Users" -Member $Using:SNText.Text -ErrorAction SilentlyContinue;}}catch {$null})
  55. $Output = $( try {Invoke-Command -Computername $CNText.Text -ScriptBlock {Get-LocalGroupMember -Group "Remote Desktop Users"}}catch {$null})
  56. $Details.Text = $Output, "Added Successfully"
  57. }
  58. Else { $Details.Text = "Somethings not right"
  59. }
  60. }
  61. Add-Type -AssemblyName System.Windows.Forms
  62. [System.Windows.Forms.Application]::EnableVisualStyles()
  63.  
  64. $Form = New-Object system.Windows.Forms.Form
  65. $Form.ClientSize = '626,230'
  66. $Form.text = "Form"
  67. $Form.TopMost = $false
  68.  
  69. $SN = New-Object system.Windows.Forms.Label
  70. $SN.text = "Student/Staff Number"
  71. $SN.AutoSize = $true
  72. $SN.width = 25
  73. $SN.height = 10
  74. $SN.location = New-Object System.Drawing.Point(29,90)
  75. $SN.Font = 'Microsoft Sans Serif,10'
  76.  
  77. $CN = New-Object system.Windows.Forms.Label
  78. $CN.text = "Computer Name"
  79. $CN.AutoSize = $true
  80. $CN.width = 25
  81. $CN.height = 10
  82. $CN.location = New-Object System.Drawing.Point(28,49)
  83. $CN.Font = 'Microsoft Sans Serif,10'
  84.  
  85. $LG = New-Object system.Windows.Forms.Label
  86. $LG.text = "Local Group"
  87. $LG.AutoSize = $true
  88. $LG.width = 25
  89. $LG.height = 10
  90. $LG.location = New-Object System.Drawing.Point(30,135)
  91. $LG.Font = 'Microsoft Sans Serif,10'
  92.  
  93. $CNText = New-Object system.Windows.Forms.TextBox
  94. $CNText.multiline = $false
  95. $CNText.width = 100
  96. $CNText.height = 20
  97. $CNText.location = New-Object System.Drawing.Point(237,45)
  98. $CNText.Font = 'Microsoft Sans Serif,10'
  99.  
  100. $SNText = New-Object system.Windows.Forms.TextBox
  101. $SNText.multiline = $false
  102. $SNText.width = 100
  103. $SNText.height = 20
  104. $SNText.location = New-Object System.Drawing.Point(237,84)
  105. $SNText.Font = 'Microsoft Sans Serif,10'
  106.  
  107. $LGName = New-Object system.Windows.Forms.ListBox
  108. $LGName.text = "listBox"
  109. $LGName.width = 102
  110. $LGName.height = 30
  111. $LGName.location = New-Object System.Drawing.Point(237,122)
  112.  
  113. $Details = New-Object System.Windows.Forms.RichTextBox
  114. $Details.height = 100
  115. $Details.width = 200
  116. $Details.BackColor = "#ffffff"
  117. $Details.text = "Details"
  118. $Details.location = New-Object System.Drawing.Point(379,48)
  119.  
  120. $Close = New-Object system.Windows.Forms.Button
  121. $Close.BackColor = "#ffffff"
  122. $Close.text = "Close"
  123. $Close.width = 71
  124. $Close.height = 30
  125. $Close.location = New-Object System.Drawing.Point(492,171)
  126. $Close.Font = 'Microsoft Sans Serif,10'
  127. $Form.controls.Add($Close)
  128. $Close.Add_Click({ $Form.Tag = $null; $Form.Close() })
  129.  
  130. $Help = New-Object system.Windows.Forms.Button
  131. $Help.BackColor = "#ffffff"
  132. $Help.text = "Help"
  133. $Help.width = 60
  134. $Help.height = 30
  135. $Help.location = New-Object System.Drawing.Point(408,170)
  136. $Help.Font = 'Microsoft Sans Serif,10'
  137. $Form.controls.Add($Help)
  138.  
  139. $TestConnection = New-Object system.Windows.Forms.Button
  140. $TestConnection.BackColor = "#ffffff"
  141. $TestConnection.text = "Checks"
  142. $TestConnection.width = 167
  143. $TestConnection.height = 30
  144. $TestConnection.location = New-Object System.Drawing.Point(28,171)
  145. $TestConnection.Font = 'Microsoft Sans Serif,10'
  146.  
  147. # CHANGED
  148. $TestConnection.Add_Click({$Details.text = (CheckUser)+"`n"+(CheckComputer)})
  149.  
  150. $Addtogroup = New-Object system.Windows.Forms.Button
  151. $Addtogroup.BackColor = "#ffffff"
  152. $Addtogroup.text = "Enable Remote Desktop"
  153. $Addtogroup.width = 153
  154. $Addtogroup.height = 30
  155. $Addtogroup.location = New-Object System.Drawing.Point(223,170)
  156. $Addtogroup.Font = 'Microsoft Sans Serif,10'
  157. $Addtogroup.Add_Click({EnableRemoteDesktop})
  158.  
  159. $Form.controls.AddRange(@($SN,$CN,$LG,$CNText,$SNText,$LGName,$Details,$Close,$Help,$TestConnection,$Addtogroup))
  160.  
  161. $Form.Add_Shown({$Form.Activate()})
  162. [void] $Form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement