diff --git a/API/Zabbix-api.psm1 b/API/Zabbix-api.psm1
new file mode 100644
index 0000000..a8485f2
--- /dev/null
+++ b/API/Zabbix-api.psm1
@@ -0,0 +1,628 @@
+<#
+ .Synopsis
+ Open a session to the zabbix server
+
+ .Description
+ Open a session to the zabbix server
+
+ .Parameter PSCredential
+ Credential to connect to zabbix server
+
+ .Parameter IPAdress
+ Accept IP adress and domain name
+
+ .Parameter UseSSL
+ Switch to use https, leave empty to use http
+
+ .Example
+ Connect-Zabbix -User admin -Password zabbix -IPAdress 10.0.0.1
+ Connect to Zabbix server by IP adresse
+
+ .Example
+ Connect-Zabbix -User admin -Password zabbix -IPAdress zabbix.domain.lan -UseSSL
+ Connect to Zabbix server by domain name with SSL
+#>
+Function Connect-Zabbix {
+ Param (
+ [Parameter(Mandatory=$True)]
+ [PSCredential]$PSCredential
+ ,
+ [Parameter(Mandatory=$True)]
+ [string]$IPAdress
+ ,
+ [Switch]$UseSSL
+ )
+ $Body = @{
+ jsonrpc = "2.0"
+ method = "user.login"
+ params = @{
+ user = $PSCredential.UserName
+ password = $PSCredential.GetNetworkCredential().Password
+ }
+ id = 1
+ auth = $null
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+
+ Switch ($UseSSL.IsPresent) {
+ $False {$Protocol = "http"}
+ $True {$Protocol = "https"}
+ }
+ $URL = $Protocol+"://$IPAdress/zabbix"
+ $Res = Invoke-RestMethod ("$URL/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Connection successful
+ $Global:ZabbixSession = $Res | Select-Object jsonrpc,@{Name="Session";Expression={$_.Result}},id,@{Name="URL";Expression={$URL}}
+ Write-Host ("Successfuly connected to " + $URL)
+ }
+ else {
+ #Connection error
+ $Res.error
+ }
+}
+
+<#
+ .Synopsis
+ Get all host monitored from zabbix server
+
+ .Description
+ Get all host monitored from zabbix server
+
+ .Parameter HostName
+ To filter by name of the host
+
+ .Parameter HostID
+ To filter by id of the host
+
+ .Example
+ # Get all hosts managed by zabbix server
+ Get-ZabbixHost
+
+ .Example
+ # Get info about Server1 host
+ Get-ZabbixHost -HostName Server1
+
+ .Example
+ # Get info about 10123 ID
+ Get-ZabbixHost -HostID 10123
+#>
+Function Get-ZabbixHost {
+ Param (
+ $HostName
+ ,
+ $HostID
+ )
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "host.get"
+ params = @{
+ output = "extend"
+ selectGroups = @(
+ "groupid",
+ "name"
+ )
+ selectParentTemplates = @(
+ "templateid",
+ "name"
+ )
+ filter = @{
+ host = $HostName
+ }
+ hostids = $HostID
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+<#
+ .Synopsis
+ Get all templates from zabbix server
+
+ .Description
+ Get all templates from zabbix server
+
+ .Parameter TemplateName
+ To filter by name of the template
+
+ .Parameter TemplateID
+ To filter by id of the template
+
+ .Example
+ # Get all templates from zabbix server
+ $Session | Get-ZabbixTemplate
+
+ .Example
+ # Get info about Template1
+ Get-ZabbixTemplate -TemplateName Template1
+
+ .Example
+ # Get info about 10001 ID
+ Get-ZabbixTemplate -TemplateID 10001
+#>
+Function Get-ZabbixTemplate {
+ Param (
+ $TemplateName
+ ,
+ $TemplateID
+ )
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "template.get"
+ params = @{
+ output = "extend"
+ selectHosts = "extend"
+ filter = @{
+ host = $TemplateName
+ }
+ templateids = $TemplateID
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result | Select-Object Name,TemplateID,@{Name="HostsMembers";Expression={$_.hosts.hostid}}
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+<#
+ .Synopsis
+ Get all groups from zabbix server
+
+ .Description
+ Get all groups from zabbix server
+
+ .Parameter GroupName
+ To filter by name of the group
+
+ .Parameter GroupID
+ To filter by id of the group
+
+ .Example
+ # Get all groups from zabbix server
+ $Session | Get-ZabbixGroup
+
+ .Example
+ # Get info about Group1
+ Get-ZabbixGroup -GroupName Group1
+
+ .Example
+ # Get info about 10001 ID
+ Get-ZabbixGroup -GroupID 10001
+#>
+Function Get-ZabbixGroup {
+ Param (
+ $GroupName
+ ,
+ $GroupID
+ )
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "hostgroup.get"
+ params = @{
+ output = "extend"
+ selectHosts = @(
+ "hostid",
+ "host"
+ )
+ filter = @{
+ name = $GroupName
+ }
+ groupids = $GroupID
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+<#
+ .Synopsis
+ Create new host to monitor from zabbix server
+
+ .Description
+ Create new host to monitor from zabbix server
+
+ .Parameter HostName
+ HostName of the host as it will display on zabbix
+
+ .Parameter IP
+ IP adress to supervise the host
+
+ .Parameter DNSName
+ Domain name to supervise the host
+
+ .Parameter Port
+ Port to supervise the host
+
+ .Parameter GroupID
+ ID of the group where add the host
+
+ .Parameter TemplateID
+ ID of the template where add the host
+
+ .Parameter MonitorByDNSName
+ If used, domain name of the host will used to contact it
+
+ .Example
+ # Get all groups from zabbix server
+ New-ZabbixHost -HostName Host1 -IP 10.0.0.1 -GroupID 8 -TemplateID 10001
+#>
+Function New-ZabbixHost {
+ Param (
+ [Parameter(Mandatory=$True)]
+ [string]$HostName
+ ,
+ [string]$InterfaceType = 1
+ ,
+ [string]$InterfaceMain = 1
+ ,
+ [string]$IP
+ ,
+ [string]$DNSName
+ ,
+ [string]$Port = 10050
+ ,
+ [Parameter(Mandatory=$True)]
+ [string]$GroupID
+ ,
+ $TemplateID
+ ,
+ [Switch]$MonitorByDNSName
+ )
+
+ Switch ($MonitorByDNSName.IsPresent) {
+ $False {$ByDNSName = 1} # = ByIP
+ $True {$ByDNSName = 0} # = ByDomainName
+ }
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "host.create"
+ params = @{
+ host = $HostName
+ interfaces = @(
+ @{
+ type = $InterfaceType
+ main = $InterfaceMain
+ useip = $ByDNSName
+ ip = $IP
+ dns = $DNSName
+ port = $Port
+ }
+ )
+ groups = @(
+ @{
+ groupid = $GroupID
+ }
+ )
+ templates = @(
+ @{
+ templateid = $TemplateID
+ }
+ )
+ }
+ auth = $ZabbixSession.Session
+ id = $ZabbixSession.id
+ }
+
+ $BodyJSON = ConvertTo-Json $Body -Depth 3
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result | Select-Object @{Name="hostids";Expression={$_.hostids[0]}}
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+<#
+ .Synopsis
+ Get all zabbix proxy
+
+ .Description
+ Get all zabbix proxy
+
+ .Parameter HostName
+ To filter by name of the proxy
+
+ .Parameter ProxyId
+ To filter by id of the proxy
+
+ .Parameter WithHosts
+ Switch to show hosts supervised by the proxy
+
+ .Example
+ # Get all hosts managed by zabbix server
+ Get-ZabbixProxy
+
+ .Example
+ # Get info about Server1 host
+ Get-ZabbixProxy -HostName ZabbixProxy1
+#>
+Function Get-ZabbixProxy {
+ Param (
+ $HostName
+ ,
+ $ProxyId
+ ,
+ [Switch]$WithHosts
+ )
+
+ Switch ($WithHosts.IsPresent) {
+ $False {$SelectHosts = $null} # = Without hosts
+ $True {$SelectHosts = "extend"} # = With hosts
+ }
+
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "proxy.get"
+ params = @{
+ output = "extend"
+ selectInterface = "extend"
+ proxyids = $ProxyId
+ filter = @{
+ host = $HostName
+ }
+ selectHosts = $SelectHosts
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+<#
+ .Synopsis
+ Update the Zabbix proxy of a host
+
+ .Description
+ Update the Zabbix proxy of a host
+
+ .Parameter HostID
+ ID of the host you want to update
+
+ .Parameter ProxyId
+ ID of the Zabbix proxy which will supervise the host
+
+ .Example
+ The host with the ID 10266 will be supervised by Zabbix Server himself
+ Set-ZabbixHostProxy -HostID 10266 -ProxyId 0
+
+ .Example
+ The host with the ID 10266 will be supervised by the Zabbix proxy with the ID 10267
+ Set-ZabbixHostProxy -HostID 10266 -ProxyId 10267
+#>
+Function Set-ZabbixHostProxy {
+ Param (
+ [Parameter(Mandatory=$True)]
+ [int]$HostID
+ ,
+ [Parameter(Mandatory=$True)]
+ [int]$ProxyId
+ )
+
+ if ($HostID -eq 0) {
+ Write-Error "Please enter a Host ID"
+ break
+ }
+
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "host.update"
+ params = @{
+ hostid = $HostID
+ proxy_hostid = $ProxyId
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+Function Get-ZabbixItem {
+ Param (
+ [int]$HostID
+ ,
+ [int]$ItemID
+ ,
+ [string]$ItemName
+ ,
+ [Switch]$Debug
+ )
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "item.get"
+ params = @{
+ output = "extend"
+ hostids = $HostID
+ itemids = $ItemID
+ search = @{
+ #name = $ItemName
+ #key_ = "system"
+ }
+ sortfield = "name"
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ Switch ($Debug.IsPresent) {
+ $True {Write-Host $BodyJSON -ForegroundColor Yellow}
+ }
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+ Switch ($Debug.IsPresent) {
+ $True {Write-Host $Res -ForegroundColor Yellow}
+ }
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+Function Get-ZabbixHostInterface {
+ Param (
+ $HostID
+ )
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "hostinterface.get"
+ params = @{
+ output = "extend"
+ hostids = $HostID
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result |
+ Select-Object *,@{Name="type_name";Expression={
+ switch ($_.type) {
+ "1" {"agent"; break}
+ "2" {"snmp"; break}
+ "3" {"ipmi"; break}
+ "4" {"jmx"; break}
+ }
+ }}
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+### Fonction non fonctionnelles ###
+<#
+Function Add-ZabbixHostInterface {
+ Param (
+ [string]$HostID,
+ [ValidateRange(1,4)]
+ [int]$InterfaceType = 1,
+ [ValidateSet("agent","snmp","ipmi","jmx")]
+ [string]$InterfaceTypeName,
+ [string]$IP,
+ [string]$DNSName,
+ [switch]$MonitorByDNSName,
+ [int]$InterfaceMain = 0
+ )
+
+ Switch ($MonitorByDNSName.IsPresent) {
+ $False {$ByDNSName = 1} # = ByIP
+ $True {$ByDNSName = 0} # = ByDomainName
+ }
+
+ Switch ($InterfaceTypeName) {
+ "agent" {$InterfaceType = 1; break}
+ "snmp" {$InterfaceType = 2; break}
+ "ipmi" {$InterfaceType = 3; break}
+ "jmx" {$InterfaceType = 4; break}
+ }
+
+ Switch ($InterfaceType) {
+ "1" {$Port = "10050"; break}
+ "2" {$Port = "161"; break}
+ "3" {$Port = "623"; break}
+ "4" {$Port = "11162"; break}
+ }
+
+ $Body = @{
+ jsonrpc = $ZabbixSession.jsonrpc
+ method = "hostinterface.create"
+ params = @{
+ hostids = $HostID
+ dns = $DNSName
+ ip = $IP
+ main = $InterfaceMain
+ port = $Port
+ type = $InterfaceType
+ useip = $ByDNSName
+ }
+ id = $ZabbixSession.id
+ auth = $ZabbixSession.Session
+ }
+
+ $BodyJSON = ConvertTo-Json $Body
+ Write-Host $BodyJSON
+ $Res = Invoke-RestMethod ($ZabbixSession.URL + "/api_jsonrpc.php") -ContentType "application/json" -Body $BodyJSON -Method Post
+
+ if (($Res | Get-Member | Select-Object -ExpandProperty Name) -contains "result") {
+ #Command successful
+ $Res.result
+ }
+ else {
+ #Command error
+ $Res.error
+ }
+}
+
+Add-ZabbixHostInterface -HostID (Get-ZabbixHost -HostName hv1).hostid -InterfaceTypeName snmp -DNSName hv1-2.maison.lan -MonitorByDNSName -IP 127.0.0.1
+Get-ZabbixHostInterface -HostID (Get-ZabbixHost -HostName hv1).hostid
+#>
\ No newline at end of file
diff --git a/API/Zabbix-api.txt b/API/Zabbix-api.txt
new file mode 100644
index 0000000..1f5f815
--- /dev/null
+++ b/API/Zabbix-api.txt
@@ -0,0 +1,12 @@
+Import-Module .\Zabbix-api.psm1
+
+$Cred = Get-Credential
+Connect-Zabbix -PSCredential $Cred -IPAdress 192.168.1.1
+Connect-Zabbix -PSCredential $Cred -IPAdress zabbix.domain.ru -UseSSL
+
+(Get-Module Zabbix).ExportedCommands
+
+Get-ZabbixHostInterface | ft
+Get-ZabbixHost | ft
+Get-ZabbixGroup | ft
+Get-ZabbixTemplate | ft
\ No newline at end of file
diff --git a/posh.txt b/posh.txt
index bbf5900..c57d396 100644
--- a/posh.txt
+++ b/posh.txt
@@ -13,13 +13,16 @@ PowerShell Commands
- ActiveDirectory
- ServerManager
- PackageManagement
-- SQLite
- PowerCLI
- EMShell
-- VBR
-- REST-API
-- Console-API
-- Convert-Language
+- TrueNAS
+- Veeam
+- REST API
+- IE
+- Console API
+- XML
+- Excel
+- SQLite
- Git
### Help
@@ -35,6 +38,15 @@ $PSVersionTable
# Object
+### History
+Get-History # история команд текущей сессии
+(Get-PSReadLineOption).HistorySavePath # путь к сохраненному файлу с 4096 последних команд (из модуля PSReadLine)
+Get-Content (Get-PSReadlineOption).HistorySavePath | Select-String Get # поиск по содержимому файла (GREP)
+Set-PSReadlineOption -MaximumHistoryCount 10000 # изменить количество сохраняемых команд в файл
+Get-PSReadLineOption | select MaximumHistoryCount
+Set-PSReadlineOption -HistorySaveStyle SaveNothing # отключить ведение журнала
+F2 # переключиться с InlineView на ListView
+
### Array
$srv = @("server-01", "server-02") # создать массив
$srv += @("server-03") # добавить в массив новый элемент
@@ -409,10 +421,19 @@ Get-EventLog -List # отобразить все корневые журналы
Clear-EventLog Application # очистить логи указанного журнала
Get-EventLog -LogName Security -InstanceId 4624 # найти логи по ID в журнале Security
-function Get-Log ($count=30,$hour=-3) { # указать значения параметров по умолчанию
-Get-EventLog -LogName Application -Newest $count | where-Object TimeWritten -ge (Get-Date).AddHours($hour) # отобразить 30 новых событий за последние 3 часа
+function Get-Log {
+Param(
+[Parameter(Mandatory = $true, ValueFromPipeline = $true)][int]$Count,
+$Hour
+)
+if ($Hour -ne $null) {
+Get-EventLog -LogName Application -Newest $Count | ? TimeWritten -ge (Get-Date).AddHours($Hour)
+} else {
+Get-EventLog -LogName Application -Newest $Count
}
-Get-Log 10 -1 # передача параметров функции (если значения идут по порядку, то можно не указывать названия переменных)
+}
+10 | Get-Log
+Get-Log 100 -2
### WinEvent
Get-WinEvent -ListLog * | where logname -match SMB | sort -Descending RecordCount # отобразить все доступные журналы логов
@@ -525,14 +546,20 @@ Get-NetAdapter
Get-NetAdapterAdvancedProperty
Get-NetAdapterStatistics
+### DNSClientServerAddress
+Get-DNSClientServerAddress
+Set-DNSClientServerAddress -InterfaceIndex (Get-NetIPConfiguration).InterfaceIndex -ServerAddresses 8.8.8.8
+
### nslookup
+nslookup ya.ru 8.8.8.8
+nslookup -type=any ya.ru
Resolve-DnsName ya.ru -Type MX # ALL,ANY,A,NS,SRV,CNAME,PTR,TXT(spf)
### route
Get-NetRoute
### netstat
-Get-NetTCPConnection -State Established,Listen | where LocalAddress -match "192.168"
+Get-NetTCPConnection -State Established,Listen | ? LocalAddress -match "192.168"
# WinRM
@@ -1177,31 +1204,6 @@ break # остановить цикл
Get-Job | Receive-Job -Keep # отобразить и не удалять вывод (-Keep)
(Get-Job).Information # отобразить результат всех заданий
-# SQLite
-
-Install-Module -name MySQLite -Repository PSGallery
-$path = "$home\desktop\Get-Service.db"
-Get-Service | select Name,DisplayName,Status | ConvertTo-MySQLiteDB -Path $path -TableName Service -force
-(Get-MySQLiteDB $path).Tables
-New-MySQLiteDB -Path $path # создать базу
-Invoke-MySQLiteQuery -Path $path -Query "SELECT name FROM sqlite_master WHERE type='table';" # список всех таблиц в базе
-Invoke-MySQLiteQuery -Path $path -Query "CREATE TABLE Service (Name TEXT NOT NULL, DisplayName TEXT NOT NULL, Status TEXT NOT NULL);" # создать таблицу
-Invoke-MySQLiteQuery -Path $path -Query "INSERT INTO Service (Name, DisplayName, Status) VALUES ('Test', 'Full-Test', 'Active');" # добавить данные в таблицу
-Invoke-MySQLiteQuery -Path $path -Query "SELECT * FROM Service" # содержимое таблицы
-Invoke-MySQLiteQuery -Path $path -Query "DROP TABLE Service;" # удалить таблицу
-
-$Service = Get-Service | select Name,DisplayName,Status
-foreach ($S in $Service) {
-$1 = $S.Name; $2 = $S.DisplayName; $3 = $S.Status;
-Invoke-MySQLiteQuery -Path $path -Query "INSERT INTO Service (Name, DisplayName, Status) VALUES ('$1', '$2', '$3');"
-}
-
-Install-Module PSSQLite
-$Connection = New-SQLiteConnection -DataSource $path
-$Connection.ChangePassword("password")
-$Connection.Close()
-Invoke-SqliteQuery -Query "SELECT * FROM Service" -DataSource "$path;Password=password"
-
# PowerCLI
Install-Module -Name VMware.PowerCLI # -AllowClobber # установить модуль (PackageProvider: nuget)
@@ -1632,7 +1634,33 @@ cd %PROGRAMFILES%\Microsoft\Exchange Server\V14\Scripts # или v15 для Exch
Get-MailboxDatabaseCopyStatus * | where {$_.ContentIndexState -eq "Failed" -or $_.ContentIndexState -eq "FailedAndSuspended"} # отобразить у какой БД произошел сбой работы (FailedAndSuspended) или индекса (ContentIndexState)
-# VBR
+# TrueNAS
+
+import-Module TrueNas
+(Get-Module TrueNas).ExportedCommands
+Connect-TrueNasServer -Server tnas-01 -SkipCertificateCheck
+Get-TrueNasCertificate # настройки сертификата
+Get-TrueNasSetting # настройки языка, time zone, syslog level и server, https port
+Get-TrueNasUser # список пользователей
+Get-TrueNasSystemVersion # характеристики (Physical Memory, Model, Cores) и Uptime
+Get-TrueNasSystemAlert # snmp для оповещений
+Get-TrueNasSystemNTP # список используемых NTP серверов
+Get-TrueNasDisk # список разделов физического диска
+Get-TrueNasInterface # сетевые интерфейсы
+Get-TrueNasGlobalConfig # сетевые настройки
+Get-TrueNasDnsServer # настроенные DNS-сервера
+Get-TrueNasIscsiTarget # отобразить ID группы инициаторов использующих таргет, используемый portal, authentification и authen-method
+Get-TrueNasIscsiInitiator # отобразить группы инициаторов
+Get-TrueNasIscsiPortal # слушатель (Listen) и порт
+Get-TrueNasIscsiExtent # список ISCSi Target (статус работы, путь)
+Get-TrueNasPool # список pool (Id, Path, Status, Healthy)
+Get-TrueNasVolume -Type FILESYSTEM # список pool файловых систем
+Get-TrueNasVolume -Type VOLUME # список разделов в pool и их размер
+Get-TrueNasService | ft # список служб и их статус
+Start-TrueNasService ssh # запустить службу
+Stop-TrueNasService ssh # остановить службу
+
+# Veeam
Set-ExecutionPolicy AllSigned # or Set-ExecutionPolicy Bypass -Scope Process
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
@@ -1650,7 +1678,7 @@ Get-VBRBackupServerCertificate
Get-VBRRestorePoint
Get-VBRViProxy
-# REST-API
+# REST API
$pars = Invoke-WebRequest -Uri $url
$pars | Get-Member
@@ -1703,7 +1731,27 @@ $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
-# Console-API
+# IE
+
+$ie.document.IHTMLDocument3_getElementsByTagName("input") | select name # получить имена всех Input Box
+$ie.document.IHTMLDocument3_getElementsByTagName("button") | select innerText # получить имена всех Button
+$ie.Document.documentElement.innerHTML # прочитать сырой Web Content ( "$home\desktop\proc-table.html" # вывод в формате List (Format-List) или Table (Format-Table)
-
-Import-Module PSWriteHTML
-(Get-Module PSWriteHTML).ExportedCommands
-Get-Service | Out-GridHtml -FilePath ~\Desktop\Get-Service-Out-GridHtml.html
-
-Import-Module HtmlReport
-$topVM = ps | Sort PrivateMemorySize -Descending | Select -First 10 | %{,@(($_.ProcessName + " " + $_.Id), $_.PrivateMemorySize)}
-$topCPU = ps | Sort CPU -Descending | Select -First 10 | %{,@(($_.ProcessName + " " + $_.Id), $_.CPU)}
-New-Report -Title "Piggy Processes" -Input {
-New-Chart Bar "Top VM Users" -input $topVm
-New-Chart Column "Top CPU Overall" -input $topCPU
-ps | Select ProcessName, Id, CPU, WorkingSet, *MemorySize | New-Table "All Processes"
-} > ~\Desktop\Get-Process-HtmlReport.html
-
-### XML (Extensible Markup Language)
-
-$xml = [xml](Get-Content ~\desktop\home.rdg) # прочитать содержимое xml-файла
+$xml = [xml](Get-Content ~\desktop\home.rdg) # прочитать содержимое XML-файла
$xml = New-Object System.Xml.XmlDocument # создать пустой xml объект
$file = Resolve-Path("~\desktop\home.rdg") # забрать путь к файлу
$xml.load($file) # открыть файл
@@ -1950,7 +1980,7 @@ return
}
}
-### XPath
+### XPath (Query Language for Extensible Markup Language)
$FilterXPath = ''
$RDPAuths = Get-WinEvent -ComputerName $srv -LogName "Microsoft-Windows-TerminalServices-LocalSessionManager/Operational" -FilterXPath $FilterXPath
@@ -2004,6 +2034,22 @@ network:
$Result = ConvertFrom-Yaml $network
$Result.Values.ethernets.ens160.nameservers
+### HTML (HyperText Markup Language)
+Get-Process | select Name, CPU | ConvertTo-HTML -As Table > "$home\desktop\proc-table.html" # вывод в формате List (Format-List) или Table (Format-Table)
+
+Import-Module PSWriteHTML
+(Get-Module PSWriteHTML).ExportedCommands
+Get-Service | Out-GridHtml -FilePath ~\Desktop\Get-Service-Out-GridHtml.html
+
+Import-Module HtmlReport
+$topVM = ps | Sort PrivateMemorySize -Descending | Select -First 10 | %{,@(($_.ProcessName + " " + $_.Id), $_.PrivateMemorySize)}
+$topCPU = ps | Sort CPU -Descending | Select -First 10 | %{,@(($_.ProcessName + " " + $_.Id), $_.CPU)}
+New-Report -Title "Piggy Processes" -Input {
+New-Chart Bar "Top VM Users" -input $topVm
+New-Chart Column "Top CPU Overall" -input $topCPU
+ps | Select ProcessName, Id, CPU, WorkingSet, *MemorySize | New-Table "All Processes"
+} > ~\Desktop\Get-Process-HtmlReport.html
+
### CSV (Comma-Separated Values)
Get-Service | Select Name,DisplayName,Status,StartType | Export-Csv -path "$home\Desktop\Get-Service.csv" -Append -Encoding Default # экспортировать в csv (-Encoding UTF8)
Import-Csv "$home\Desktop\Get-Service.csv" -Delimiter "," # импортировать массив
@@ -2014,7 +2060,7 @@ West,Texas,927,923.71
$null,Tennessee,466,770.67
"@
-### Excel.Application.Creat
+# Excel
$path = "$home\Desktop\Services-to-Excel.xlsx"
$Excel = New-Object -ComObject Excel.Application
@@ -2085,6 +2131,32 @@ $data = ps
$Chart = New-ExcelChartDefinition -XRange CPU -YRange WS -Title "Process" -NoLegend
$data | Export-Excel .\ps.xlsx -AutoNameRange -ExcelChartDefinition $Chart -Show
+# SQLite
+
+Install-Module MySQLite -Repository PSGallery
+$path = "$home\desktop\Get-Service.db"
+Get-Service | select Name,DisplayName,Status | ConvertTo-MySQLiteDB -Path $path -TableName Service -force
+(Get-MySQLiteDB $path).Tables
+New-MySQLiteDB -Path $path # создать базу
+Invoke-MySQLiteQuery -Path $path -Query "SELECT name FROM sqlite_master WHERE type='table';" # список всех таблиц в базе
+Invoke-MySQLiteQuery -Path $path -Query "CREATE TABLE Service (Name TEXT NOT NULL, DisplayName TEXT NOT NULL, Status TEXT NOT NULL);" # создать таблицу
+Invoke-MySQLiteQuery -Path $path -Query "INSERT INTO Service (Name, DisplayName, Status) VALUES ('Test', 'Full-Test', 'Active');" # добавить данные в таблицу
+Invoke-MySQLiteQuery -Path $path -Query "SELECT * FROM Service" # содержимое таблицы
+Invoke-MySQLiteQuery -Path $path -Query "DROP TABLE Service;" # удалить таблицу
+
+$Service = Get-Service | select Name,DisplayName,Status
+foreach ($S in $Service) {
+$1 = $S.Name; $2 = $S.DisplayName; $3 = $S.Status;
+Invoke-MySQLiteQuery -Path $path -Query "INSERT INTO Service (Name, DisplayName, Status) VALUES ('$1', '$2', '$3');"
+}
+
+### Creat password database
+
+$Connection = New-SQLiteConnection -DataSource $path
+$Connection.ChangePassword("password")
+$Connection.Close()
+Invoke-SqliteQuery -Query "SELECT * FROM Service" -DataSource "$path;Password=password"
+
# Git
git --version