PowerShell - script para Cambiar red publica a privada desde powershell

 
Vista:
Imágen de perfil de A.H.H.

script para Cambiar red publica a privada desde powershell

Publicado por A.H.H. (1 intervención) el 26/05/2019 00:52:25
APORTE:

Hola el siguiene script copiado y pegado en un bloc de notas de windows guardandolo con extension .ps1 y ejecutandolo desde powershell, lo que hace es elevarse como administrador y abrir una ventana en la que puedes elegir cambiar la red del tipo public a private o viceversa...hay veces que después de actualizarse windows se queda la red en publica y estando en una casa es mejor que la red este en privada o private.....


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<# This form was created using POSHGUI.com  a free online gui designer for PowerShell
.NAME
    CHANGE INTERNET NETWORK ::  PRIVATE-PUBLIC ::  PUBLIC-PRIVATE
#>
 
#elevated powershell administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe " -NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
 
#MINIMIZED ALLCONSOLE POWERSHELL
powershell -command  { $x = New-Object -ComObject Shell.Application; $x.MinimizeAll()}
 
#get network ¿public or private?$tipodered=public or private.....
Get-NetConnectionProfile | foreach-object{ if ($_.NetworkCategory -eq "Private") {$tipodered = $_.NetworkCategory}` else{ $tipodered = $_.NetworkCategory}}
 
 
 
#funcion balloon
 
function ShowBalloonTip {
 
  [CmdletBinding(SupportsShouldProcess = $true)]
  param
  (
    [Parameter(Mandatory=$true)]
    $Text,
 
    [Parameter(Mandatory=$true)]
    $Title,
 
    [ValidateSet('None', 'Info', 'Warning', 'Error')]
    $Icon = 'Info',
    $Timeout = 10000
  )
 
  Add-Type -AssemblyName System.Windows.Forms
 
  if ($script:balloon -eq $null)
  {
    $script:balloon = New-Object System.Windows.Forms.NotifyIcon
  }
 
  $path                    = Get-Process -id $pid | Select-Object -ExpandProperty Path
  $balloon.Icon            = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
  $balloon.BalloonTipIcon  = $Icon
  $balloon.BalloonTipText  = $Text
  $balloon.BalloonTipTitle = $Title
  $balloon.Visible         = $true
 
  $balloon.ShowBalloonTip($Timeout)
Start-Sleep 5
$script:balloon.Dispose()
$Form.Close()
}
 
#end funcion balloon
 
#building the form
 
Add-Type -AssemblyName System.Windows.Forms
 
[System.Windows.Forms.Application]::EnableVisualStyles()
 
$Form = New-Object system.Windows.Forms.Form
$formicono = Get-Process -id $pid | Select-Object -ExpandProperty Path
$Form.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($formicono)
 
$Form.ClientSize = '400,302'
 
$Form.text = "Cambio Tipo Red
"
$Form.TopMost = $false
 
$Form.StartPosition = "CenterScreen"
 
$Form.FormBorderStyle = "Fixed3D"
 
$Form.WindowState = "Normal"
 
$Form.MaximizeBox = $false
 
$Label1 = New-Object system.Windows.Forms.Label
 
$Label1.text = "En estos momentos la red esta configurada en:"
 
$Label1.AutoSize = $true
 
$Label1.width = 25
 
$Label1.height = 10
 
$Label1.location = New-Object System.Drawing.Point(63,25)
 
$Label1.Font = 'Microsoft Sans Serif,10'
 
 
$Label2 = New-Object system.Windows.Forms.Label
 
$Label2.text = $tipodered
 
$Label2.AutoSize = $true
 
$Label2.width = 25
 
$Label2.height = 10
 
$Label2.location = New-Object System.Drawing.Point(155,43)
 
$Label2.Font = 'Microsoft Sans Serif,20'
 
$Label2.ForeColor = "Green"
 
 
 
 
$Groupbox1                       = New-Object system.Windows.Forms.Groupbox
$Groupbox1.height                = 121
$Groupbox1.width                 = 338
$Groupbox1.text                  = "Puedes cambiar el tipo de red con los botones..."
$Groupbox1.location              = New-Object System.Drawing.Point(30,140)
$Groupbox1.Font                  = 'Microsoft Sans Serif,10'
 
$Button1 = New-Object system.Windows.Forms.Button
 
$Button1.text = "Privada"
 
$Button1.width = 60
 
$Button1.height = 30
 
$Button1.location = New-Object System.Drawing.Point(60,53)
 
$Button1.Font = 'Microsoft Sans Serif,10'
 
 
$Button2 = New-Object system.Windows.Forms.Button
 
$Button2.text = "Publica"
 
$Button2.width = 60
 
$Button2.height = 30
 
$Button2.location = New-Object System.Drawing.Point(190,53)
 
$Button2.Font = 'Microsoft Sans Serif,10'
 
 
$Form.controls.AddRange(@($Groupbox1,$Label1,$Label2))
$Groupbox1.controls.AddRange(@($Button1,$Button2))
 
 
#end building the form
 
 
 
#region boton privada
 
$Button1.add_click({
$num = Get-NetConnectionProfile
$numero = $num.InterfaceIndex
Set-NetConnectionProfile -InterfaceIndex $numero -NetworkCategory Private
Get-NetConnectionProfile | foreach-object{ if ($_.NetworkCategory -eq "Private") {$tipodered = $_.NetworkCategory}` else{ $tipodered = $_.NetworkCategory}}
$label2.Text = $tipodered
ShowBalloonTip –Text "Has cambiado el tipo de Red a:`n $tipodered" –Title "ATENCION  $Env:USERNAME" –Icon Info –Timeout 5000
})
 
#end region boton privada
 
#region boton public
 
$Button2.add_click({
$num=Get-NetConnectionProfile
$numero=$num.InterfaceIndex
Set-NetConnectionProfile -InterfaceIndex $numero -NetworkCategory Public
Get-NetConnectionProfile | foreach-object{ if ($_.NetworkCategory -eq "Private") {$tipodered = $_.NetworkCategory}` else{ $tipodered = $_.NetworkCategory}}
$label2.Text = $tipodered
ShowBalloonTip –Text "Has cambiado el tipo de Red a:`n $tipodered" –Title "ATENCION  $Env:USERNAME" –Icon Info –Timeout 5000
})
 
#end region boton public
 
 
 
 
 
#RUN FORM
[void]$Form.ShowDialog()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Cesar Jesus
Val: 2
Ha mantenido su posición en PowerShell (en relación al último mes)
Gráfica de PowerShell

script para Cambiar red publica a privada desde powershell

Publicado por Cesar Jesus (1 intervención) el 30/09/2019 06:19:40
buen trabajo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar