update scripts
This commit is contained in:
parent
566cebdc96
commit
a5a3637b5c
14 changed files with 6289 additions and 5805 deletions
106
posh.txt
106
posh.txt
|
|
@ -21,7 +21,10 @@ PowerShell Commands
|
|||
# DHCP
|
||||
# DFS
|
||||
# Package
|
||||
# PS2EXE
|
||||
# NSSM
|
||||
# Jobs
|
||||
# SMTP
|
||||
# Hyper-V
|
||||
# VMWare/PowerCLI
|
||||
# Exchange/EMShell
|
||||
|
|
@ -83,6 +86,8 @@ Invoke-Expression # iex принимает текст в виде команды
|
|||
$PSVersionTable # версия PowerShell
|
||||
Set-ExecutionPolicy Unrestricted
|
||||
Get-ExecutionPolicy
|
||||
$Metadata = New-Object System.Management.Automation.CommandMetaData (Get-Command Get-Service) # получить информацию о командлете
|
||||
[System.Management.Automation.ProxyCommand]::Create($Metadata) # исходный код функции
|
||||
|
||||
# Object
|
||||
|
||||
|
|
@ -1019,8 +1024,24 @@ Test-Connection -Count 1 $srv1, $srv2 # отправить icmp-пакет дв
|
|||
Test-Connection $srv -ErrorAction SilentlyContinue # не выводить ошибок, если хост не отвечает
|
||||
Test-Connection -Source $srv1 -ComputerName $srv2 # пинг с удаленного компьютера
|
||||
|
||||
$ping = New-Object System.Net.Networkinformation.Ping
|
||||
1..254 | % {$ping.send("192.168.3.$_") | select address, status}
|
||||
function Test-PingNetwork {
|
||||
param (
|
||||
[Parameter(Mandatory,ValueFromPipeline)][string[]]$Network,
|
||||
[ValidateRange(100,10000)][int]$Timeout = 100
|
||||
)
|
||||
$ping = New-Object System.Net.NetworkInformation.Ping
|
||||
$Network = $Network -replace "0$"
|
||||
$net = @()
|
||||
foreach ($r in @(1..254)) {
|
||||
$net += "$network$r"
|
||||
}
|
||||
foreach ($n in $net) {
|
||||
$ping.Send($n, $timeout) | select @{Name="Address"; Expression={$n -replace ".+\."}}, Status
|
||||
}
|
||||
}
|
||||
|
||||
Test-PingNetwork -Network 192.168.3.0
|
||||
Test-PingNetwork -Network 192.168.3.0 -Timeout 1000
|
||||
|
||||
### port
|
||||
tnc $srv -p 5985
|
||||
|
|
@ -1083,6 +1104,7 @@ hostname.exe
|
|||
[System.Net.Dns]::GetHostName()
|
||||
|
||||
### arp
|
||||
ipconfig /all | Select-String "физ" # grep
|
||||
Get-NetNeighbor -AddressFamily IPv4
|
||||
|
||||
function Get-ARP {
|
||||
|
|
@ -1684,7 +1706,8 @@ Get-Command *Veeam*
|
|||
Import-Module -Name VeeamLogParser # загрузить модуль
|
||||
Get-Module VeeamLogParser | select -ExpandProperty ExportedCommands # отобразить список функций
|
||||
|
||||
### PS2EXE
|
||||
# PS2EXE
|
||||
|
||||
Install-Module ps2exe -Repository PSGallery
|
||||
Get-Module -ListAvailable # список всех модулей
|
||||
-noConsole # использовать GUI, без окна консоли powershell
|
||||
|
|
@ -1694,7 +1717,8 @@ Get-Module -ListAvailable # список всех модулей
|
|||
-credentialGUI # вывод диалогового окна для ввода учетных данных
|
||||
Invoke-ps2exe -inputFile "$home\Desktop\WinEvent-Viewer-1.1.ps1" -outputFile "$home\Desktop\WEV-1.1.exe" -iconFile "$home\Desktop\log_48px.ico" -title "WinEvent-Viewer" -noConsole -noOutput -noError
|
||||
|
||||
### NSSM
|
||||
# NSSM
|
||||
|
||||
$powershell_Path = (Get-Command powershell).Source
|
||||
$NSSM_Path = (Get-Command "C:\WinPerf-Agent\NSSM-2.24.exe").Source
|
||||
$Script_Path = "C:\WinPerf-Agent\WinPerf-Agent-1.1.ps1"
|
||||
|
|
@ -1709,6 +1733,7 @@ $Service_Name | Stop-Service # остановить
|
|||
& $NSSM_Path remove $Service_Name # удалить
|
||||
|
||||
# Jobs
|
||||
|
||||
Get-Job # получение списка задач
|
||||
Start-Job # запуск процесса
|
||||
Stop-Job # остановка процесса
|
||||
|
|
@ -1718,7 +1743,7 @@ Wait-Job # ожидание вывода команды
|
|||
Receive-Job # получение результатов выполненного процесса
|
||||
Remove-Job # удалить задачу
|
||||
|
||||
function Start-MTPing ($Network){
|
||||
function Start-PingJob ($Network) {
|
||||
$RNetwork = $Network -replace "\.\d{1,3}$","."
|
||||
foreach ($4 in 1..254) {
|
||||
$ip = $RNetwork+$4
|
||||
|
|
@ -1735,10 +1760,11 @@ break # завершаем цикл
|
|||
}}
|
||||
}
|
||||
|
||||
Start-MTPing -Network 192.168.3.0
|
||||
(Measure-Command {Start-MTPing -Network 192.168.3.0}).TotalSeconds # 60 Seconds
|
||||
Start-PingJob -Network 192.168.3.0
|
||||
(Measure-Command {Start-PingJob -Network 192.168.3.0}).TotalSeconds # 60 Seconds
|
||||
|
||||
### ThreadJob
|
||||
|
||||
Install-Module -Name ThreadJob
|
||||
Get-Module ThreadJob -list
|
||||
Start-ThreadJob {ping ya.ru} | Out-Null # создать фоновую задачу
|
||||
|
|
@ -1746,7 +1772,7 @@ Get-Job | Receive-Job -Keep # отобразить и не удалять выв
|
|||
(Get-Job).HasMoreData # если False, то вывод команы удален
|
||||
(Get-Job)[-1].Output # отобразить вывод последней задачи
|
||||
|
||||
function Start-MTPing ($Network){
|
||||
function Start-PingThread ($Network) {
|
||||
$RNetwork = $Network -replace "\.\d{1,3}$","."
|
||||
foreach ($4 in 1..254) {
|
||||
$ip = $RNetwork+$4
|
||||
|
|
@ -1763,12 +1789,12 @@ break # завершаем цикл
|
|||
}}
|
||||
}
|
||||
|
||||
Start-MTPing -Network 192.168.3.0
|
||||
(Measure-Command {Start-MTPing -Network 192.168.3.0}).TotalSeconds # 24 Seconds
|
||||
Start-PingThread -Network 192.168.3.0
|
||||
(Measure-Command {Start-PingThread -Network 192.168.3.0}).TotalSeconds # 24 Seconds
|
||||
|
||||
### PoshRSJob
|
||||
|
||||
function Start-MTPing ($Network){
|
||||
function Start-PingRSJob ($Network) {
|
||||
$RNetwork = $Network -replace "\.\d{1,3}$","."
|
||||
foreach ($4 in 1..254) {
|
||||
$ip = $RNetwork+$4
|
||||
|
|
@ -1779,8 +1805,35 @@ $ping_out
|
|||
Get-RSJob | Remove-RSJob
|
||||
}
|
||||
|
||||
Start-MTPing -Network 192.168.3.0
|
||||
(Measure-Command {Start-MTPing -Network 192.168.3.0}).TotalSeconds # 10 Seconds
|
||||
Start-PingRSJob -Network 192.168.3.0
|
||||
(Measure-Command {Start-PingRSJob -Network 192.168.3.0}).TotalSeconds # 10 Seconds
|
||||
|
||||
# SMTP
|
||||
|
||||
function Send-SMTP {
|
||||
param (
|
||||
[Parameter(Mandatory = $True)]$mess
|
||||
)
|
||||
$srv_smtp = "smtp.yandex.ru"
|
||||
$port = "587"
|
||||
$from = "login1@yandex.ru"
|
||||
$to = "login2@yandex.ru"
|
||||
$user = "login1"
|
||||
$pass = "password"
|
||||
$subject = "Service status on Host: $hostname"
|
||||
$Message = New-Object System.Net.Mail.MailMessage
|
||||
$Message.From = $from
|
||||
$Message.To.Add($to)
|
||||
$Message.Subject = $subject
|
||||
$Message.IsBodyHTML = $true
|
||||
$Message.Body = "<h1> $mess </h1>"
|
||||
$smtp = New-Object Net.Mail.SmtpClient($srv_smtp, $port)
|
||||
$smtp.EnableSSL = $true
|
||||
$smtp.Credentials = New-Object System.Net.NetworkCredential($user, $pass);
|
||||
$smtp.Send($Message)
|
||||
}
|
||||
|
||||
Send-SMTP $(Get-Service)
|
||||
|
||||
# Hyper-V
|
||||
|
||||
|
|
@ -2358,6 +2411,25 @@ $vjob = $vjob.Content | ConvertFrom-Json
|
|||
$vjob = Invoke-RestMethod "https://veeam-11:9419/api/v1/jobs" -Method GET -Headers $Header -SkipCertificateCheck
|
||||
$vjob.data.virtualMachines.includes.inventoryObject
|
||||
|
||||
### Telegram
|
||||
|
||||
function Send-Telegram {
|
||||
param (
|
||||
[Parameter(Mandatory = $True)]$Text
|
||||
)$token_bot = "5517149522:AAFop4_darMpTT7VgLpY2hjkDkkV1dzmGNM"
|
||||
$id_chat = "-609779646"
|
||||
$payload = @{
|
||||
"chat_id" = $id_chat
|
||||
"text" = $Text
|
||||
"parse_mode" = "html"
|
||||
}
|
||||
Invoke-RestMethod -Uri ("https://api.telegram.org/bot{0}/sendMessage" -f $token_bot) -Method Post -ContentType "application/json;charset=utf-8" -Body (
|
||||
ConvertTo-Json -Compress -InputObject $payload
|
||||
)
|
||||
}
|
||||
|
||||
Send-Telegram -Text Test
|
||||
|
||||
# Selenium
|
||||
|
||||
.\nuget.exe install Selenium.WebDriver
|
||||
|
|
@ -2469,6 +2541,14 @@ $wshell.SendKeys("{F1}")
|
|||
$wshell.SendKeys("{F12}")
|
||||
$wshell.SendKeys("{+}{^}{%}{~}{(}{)}{[}{]}{{}{}}")
|
||||
|
||||
function Get-AltTab {
|
||||
$wshell = New-Object -ComObject wscript.shell
|
||||
$wshell.SendKeys("%{Tab}") # ALT+TAB
|
||||
sleep 120
|
||||
Get-AltTab
|
||||
}
|
||||
Get-AltTab
|
||||
|
||||
### Wscript.Shell.Popup
|
||||
$wshell = New-Object -ComObject Wscript.Shell
|
||||
$output = $wshell.Popup("Выберите действие?",0,"Заголовок",4)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue