function Show-SrvFolderList($kat_addr) { # Получаем на вход уже готовый путь к серверу
Get-Children -Path $kat_addr | Format-Table Name
}
function Show-FolderAccess($inp_res) { # увидеть список групп, с исключениями
$lol2 = Get-Acl $inp_res
$lol2 = $lol2.Access | Where-Object {
$_.IdentityReference -notlike "*blabla1*" -and
$_.IdentityReference -notlike "*blabla2*" -and
$_.IdentityReference -notlike "*blabla3*" -and
$_.IdentityReference -notlike "*blabla4*" -and
$_.IdentityReference -notlike "*blabla5*"
}
$lol2 | Format-Table
}
$srv_name = Read-Host "Введите сервер"
$kat_addr = '\\' + $srv_name + '\Folder' # На каждом сервере есть определенная папка \Folder, которая подставляется в Get-Children.
do {
Show-SrvFolderList
# После того, как увидели все каталоги, можем выбрать один из них
$inp_res = Read-Host "Введите ресурс или 1"
if ($inp_res -eq '1') { break }
Show-FolderAccess ($kat_addr + '\' + $inp_res)
} while ($true)
IF $(psvr) <= 2
вам вообще недоступна, в принципе :)powershell -nologo -noprofile "exit $psversiontable.psversion.major"
@powershell -nologo -noprofile "exit $psversiontable.psversion.major"
@echo %ERRORLEVEL%
$argument1 = '-noprofile -command "Start-Process powershell.exe -Verb RunAs -ArgumentList ''-noprofile -file C:\run.ps1''"'
Start-Process -FilePath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Credential $credential -ArgumentList $argument1
Get-WinEvent -LogName Application -MaxEvents 10 | Select-Object -ExpandProperty Message
Get-WinEvent -LogName Application -MaxEvents 10 | Select-Object Machinename, TimeCreated, Message | Export-csv -Path d:\111.csv
и смотреть уже его$e = Get-WinEvent -LogName Application -MaxEvents 10
$e[0].Message
- name: Install Zabbix-release CentOS 7
yum:
name: https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/z...
# --тут тоже нужен when
- name: install zabbix-agent
yum: name=zabbix-agent state=latest
when: ansible_os_family == "RedHat"
Get-ADGroup -Filter '*' | Where-Object { $_.ObjectGUID -in 'xxx', 'yyy', 'zzz' }
$Filter = "ObjectGUID -eq '" + ('xxx', 'yyy', 'zzz' -join "' -or ObjectGUID -eq '") + "'"
userPrincipalName = samAccountName + '@' + $DomainName
$DomainName
при этом может быть как $env:USERDNSDOMAIN
, так и, например, (Get-ADDomain).DNSRoot
$domain = Get-ADDDomain
$DomainName = $domain.Name + $domain.ParentDomain
смотря от кого получаешь данные...Invoke-WebRequest
и подаёте результат на вход Select-String
set a=%1%
echo %a:~7,-1%
pause
вот тут уже видно, что в a всё вырезано, можно запускать вместо echo##########
# Input: file name
:local fn $1
#:local fn "text.txt"
:local content [/file get $fn contents]
:local datalen [:len $content]
:local fi 0
:local idx 0
:local res [:toarray ""]
#:put $datalen
do {
:local cr [:find $content "\n" $fi]
if ([:typeof $cr] = "nil") do={
:set cr $datalen
}
# :put "fi: $fi, cr: $cr, idx: $idx"
:local line [:pick $content $fi $cr]
# :put $line
:set ($res->$idx) $line
:set fi ($cr + 1)
:set idx ($idx + 1)
} while ($fi <= $datalen)
:return $res
:local file2array [:parse [/system script get func_file2array source]]; local lines [$file2array text.txt]; :foreach i in=$lines do={ :put $i }
[DateTime]$StartDate = '2023-05-11'
[DateTime]$EndDate = '2023-05-12'
$ComputerName= 'targetcomputer'
$params = @{
ComputerName=$ComputerName
FilterXml = '<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4647 or EventID=4648) and
TimeCreated[@SystemTime>='''+
$StartDate.ToUniversalTime().ToString('u').Replace(' ','T') + ''' and
@SystemTime<'''+
$EndDate.ToUniversalTime().ToString('u').Replace(' ','T')+ ''']]]
</Select>
</Query>
</QueryList>'
}
$e = Get-WinEvent @params
# Ну и тут потом анализировать $e
########## func_date2days - count days from base to given date.
# Input: two dates like "jan/1/2017"
########## uncomment for testing
:local date $1
#:local date "sep/13/2017"
#:put $date
# Base MUST BE lower of any given date. Mikrotik counts from jan/01/1970.
#correct only for years>1918
:local base 1970
########################################
:local mdays {31;28;31;30;31;30;31;31;30;31;30;31}
:local months {"jan"=1;"feb"=2;"mar"=3;"apr"=4;"may"=5;"jun"=6;"jul"=7;"aug"=8;"sep"=9;"oct"=10;"nov"=11;"dec"=12}
#date
:local dd [:tonum [:pick $date 4 6]]
:local yy [:tonum [:pick $date 7 11]]
:local mm [:pick $date 0 3]
:set mm ($months->$mm)
#0. We have dd/mm/yy
:local res 0
#1. Move to 01/mm/yy
:set res ($res+$dd-1)
#2. Move to 01/01/yy
:while ($mm>1) do={
:set mm ($mm-1)
:local dm [:pick $mdays ($mm-1)]
:if ($mm=2 && (($yy&3=0 && $yy/100*100 != $yy) || $yy/400*400=$yy) ) do={ :set dm 29 }
:set res ($res+$dm)
}
#3. Move to 01/01/1900
:while ($yy>$base) do={
:set yy ($yy-1)
:set res ($res+365)
:if ( ( ($yy&3=0) && ($yy/100*100 != $yy)) || $yy/400*400=$yy ) do={
:set res ($res+1)
}
}
:return $res
########## func_days2date - convert days from base to date string
# Input: days like 18762 (may/15/2021)
########## uncomment for testing
:local days $1
#:local days 789
#:put $days
#days starts from 1
:set days ($days + 1)
# Base MUST BE lower of any given date. Mikrotik counts from jan/01/1970.
#correct only for years>1918
:local base 1970
########################################
:local mdays {31;28;31;30;31;30;31;31;30;31;30;31}
:local months {1="jan";2="feb";3="mar";4="apr";5="may";6="jun";7="jul";8="aug";9="sep";10="oct";11="nov";12="dec"}
#date
:local yy $base
:local mm 0
# base year is not leap
:local daydiff 365
:local isleap false
#1. Move to 01/01/yy
:while ($days > $daydiff) do={
:set days ($days - $daydiff)
:set yy ($yy + 1)
:if ( ( ($yy & 3 = 0) && ($yy/100*100 != $yy)) || $yy/400*400=$yy ) do={
:set daydiff 366
:set isleap true
# :put "adjust: $yy, days: $days"
} else={
:set daydiff 365
:set isleap false
}
# :put "yy: $yy, days: $days"
}
#2. Adjust feb 29 if leap year
#:put "mmm: $mm, days: $days, isleap: $isleap"
:if ($isleap) do={
# :put "adjust month days"
:set ($mdays->1) 29
}
#3. Move to 01/mm/yy
:while ($days > $mdays->$mm) do={
# :put ($mdays->$mm)
:set days ($days-($mdays->$mm))
:set mm ($mm + 1)
# :put "mm: $mm, days: $days"
}
:local month [:tostr ($mm + 1)]
:set month ($months->$month)
:if ($days < 10) do={ :set days ("0".(:tostr $days)) } else={ :set days (:tostr $days) }
:local res "$month/$days/$yy"
#:put $res
:return $res
:local date2days [:parse [/system script get func_date2days source]]; :local today "may/12/2023"; :local days [$date2days $today]; :put $days;
:local days2date [:parse [/system script get func_days2date source]]; :put [$days2date ($days-1)]
$border = 40
$prev_temp = Get-Temperature
do {
$cur_temp = Get-Temperature
if (
($cur_temp -lt $border -and $prev_temp -gt $border) -or
($cur_temp -gt $border -and $prev_temp -lt $border)
)
{
Send-Notification $prev_temp $cur_temp
}
$prev_temp = $cur_temp
Start-Sleep -Seconds 60
} while ($true)