Translate

Slanje poruka sa PowerShell-om

Evo jedna skripta koja sluzi za slanje poruka racunarima u mrezi. Potrebno je samo ukucati naziv racunara i poruku, uz male izmene kao sto je dodatna skripta koja skenira domen i pravi txt fajl sa spiskom svih racunara i umesto textbox staviti dropdown meni koji cita taj txt fajl onda moze da bude jos laksi za upotrebu.

Dodatak koji se stavlja na pocetku da bi pokrenuo skriptu i namestio txt fajl
PS> c:\PSskripte\spisak.ps1 > c:\PSskripte\spisak.txt

izgleda ovako:



#################################################################################

#####Send message!!!!

#####Porukar
$sender = [Environment]::UserName

$Form = New-Object System.Windows.Forms.Form
$Form.width = 300
$Form.height = 180
$Form.Text = "PowerShell Messanger"
$Form.backcolor = "#5D8AA8"
$Form.maximumsize = New-Object System.Drawing.Size(300, 180)
$Form.startposition = "centerscreen"
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$Form.Close()}})

######Label
$label1 = New-Object System.Windows.Forms.Label
$label1.Location = New-Object System.Drawing.Size(10,10)
$Label1.Size = New-Object System.Drawing.Size(280,20)
$Label1.Text = "Computer Name"
$Form.Controls.Add($label1)

$label2 = New-Object System.Windows.Forms.Label
$label2.Location = New-Object System.Drawing.Size(10,60)
$Label2.Size = New-Object System.Drawing.Size(280,20)
$Label2.Text = "Message"
$Form.Controls.Add($label2)

######ComputerName  
$Racunar = new-object System.Windows.Forms.TextBox
$Racunar.Location = new-object System.Drawing.Size(10,30)
$Racunar.Size = new-object System.Drawing.Size(270,20)
$Form.Controls.Add($Racunar)

######Poruka
$poruka = new-object System.Windows.Forms.TextBox
$poruka.Location = new-object System.Drawing.Size(10,80)
$poruka.Size = new-object System.Drawing.Size(270,20)
$Form.Controls.Add($poruka)


######Slanje poruke
$Slanje = new-object System.Windows.Forms.Button
$Slanje.Location = new-object System.Drawing.Size(10,110)
$Slanje.Size = new-object System.Drawing.Size(70,20)
$Slanje.Text = "Send"
$Slanje.FlatAppearance.MouseOverBackColor = [System.Drawing.Color]::FromArgb(255, 255, 192);
$Slanje.ImageAlign = [System.Drawing.ContentAlignment]::MiddleLeft;
$Slanje.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$Slanje.Add_Click({Slanjeporuke})
$Form.Controls.Add($Slanje)

function slanjeporuke {
$tekst = $poruka.text
Invoke-WmiMethod -Path Win32_Process -Name Create -ArgumentList "msg * $tekst . From $sender" -ComputerName $racunar.text

}

$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()

#################################################################################

Нема коментара:

Постави коментар