function Get-TextEncoding ($Encoding) {
switch -regex ($Encoding) {
'default' {
[System.Text.Encoding]::Default
}
'utf8' {
[System.Text.Encoding]::UTF8
}
'oem' {
[System.Text.Encoding]::GetEncoding(
(Get-Culture).TextInfo.OEMCodePage
)
}
'ansi' {
[System.Text.Encoding]::GetEncoding(
(Get-Culture).TextInfo.ANSICodePage
)
}
'^\d+$' {
[System.Text.Encoding]::GetEncoding([int]$Encoding)
}
default {
[System.Text.Encoding]::GetEncoding($Encoding)
}
}
}
function Convert-TextEncoding {
param (
[Parameter(ValueFromPipeline=$true,Position=0)]
[String[]]$InputObject,
[Parameter(Mandatory=$true,Position=1)]
[string]$FromEncoding,
[Parameter(Mandatory=$true,Position=2)]
[string]$ToEncoding
)
BEGIN {
try {
$FE = Get-TextEncoding $FromEncoding
$TE = Get-TextEncoding $ToEncoding
}
catch {
throw
}
}
PROCESS{
foreach ($s in $InputObject) {
if ($s) {
$TE.GetString($FE.GetBytes($s))
}
else {
$s
}
}
}
}
Invoke-Command -ComputerName $Computer { net user } |
Convert-TextEncoding -FromEncoding 1251 -ToEncoding 866 Get-ChildItem его можно отсортировать через Sort-Object -Descending -Property LastWriteTimeSelect-Object -Skip 10), поудалять остальные$lol.IdentityReference$myArray$lol.IdentityReference это для Powershell $lol.IdentityReference | Out-Default, потому что далее этот вывод никуда не попадает, ни в переменную, ни в поток'-i', "$($file.BaseName).mp3", '-metadata', "title=`"$title`""& 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 MessageGet-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 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[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