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
set a=%1%
echo %a:~7,-1%
pause
вот тут уже видно, что в a всё вырезано, можно запускать вместо echoInvoke-Command -ScriptBlock { cmd /c "chcp 65001 && ipconfig /all" } -ComputerName ...
$no_remove = 'dir1', 'dir2', 'dir3'
$path = 'c:\temp'
Get-ChildItem $path | Where-Object { $_.Name -notin $no_remove } | Remove-Item -Force -Recurse -WhatIf
$_.Name -notin $no_remove -and 'Directory' -in $_.Attributes
-WhatIf
убрать $Computername = 'xxx'
Get-CimInstance Win32_Group -filter "LocalAccount='True' and SID='S-1-5-32-555'" -ComputerName $Computername |
Select-Object PSComputername,Name,@{Name="Members";Expression={
(Get-CimAssociatedInstance -InputObject $_ -ResultClassName Win32_UserAccount).Name
}}
$Computername = 'xxx'
Get-WMIObject Win32_Group -filter "LocalAccount='True'and SID='S-1-5-32-555'" -ComputerName $Computername|
Select-Object PSComputername,Name,@{Name="Members";Expression={
$_.GetRelated("Win32_UserAccount").Name
}}
function Get-LocalGroupMember {
param(
[Parameter(ValueFromPipeline=$false, Position=0)]
[string[]]$GroupName = 'Administrators',
[Parameter(ValueFromPipeline=$true)]
[string[]]$ComputerName = '.'
)
PROCESS {
foreach ($computer in $ComputerName) {
foreach ($group in $GroupName) {
$grp = [ADSI]"WinNT://$computer/$group,group"
Write-Verbose ('Group: ' + $grp.Path) # test for existance
$members = @($grp.psbase.Invoke("Members"))
if ($members) {
$members | Foreach-Object {
$name = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
$class = $_.GetType().InvokeMember("Class", 'GetProperty', $null, $_, $null)
$parent = $_.GetType().InvokeMember("Parent", 'GetProperty', $null, $_, $null) -replace 'WinNT://' -replace '.*/'
'' | Select-Object @{n='Class';e={$class}},@{n='Domain';e={$parent}},@{n='Name';e={$name}}
}
}
}
}
}
}
Get-LocalGroupMember -ComputerName MySuperServer -GroupName 'Пользователи удаленного рабочего стола', 'Remote Desktop Users'
robocopy \\%computername%\c$\logs \\server\logs\%computername%\logs /e
$computers =get-content 'c:\computers.txt'
foreach ($computername in $computers) {
robocopy "\\$computername\c`$\logs" "\\server\logs\$computername\logs" /e
}
for /f %%a in (c:\computers.txt) do robocopy \\%%a\c`$\logs \\server\logs\%%a\logs /e
@echo off
set idx=1
set subfolder=1
for %%f in (*. mp4) do (
call :inc "%%f"
)
goto :EOF
:inc
echo %1 - %idx% - %subfolder%
set /a "idx+=1"
if .%idx% == .11 (
set /a "subfolder+=1"
set idx=1
)
# PSv7 $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -AsByteStream), 'InsertLineBreaks')
# PSv5.1 $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -Encoding Byte), 'InsertLineBreaks')
$Cert = @"
MIILYgIBAzCCCx4GCSqGSIb3DQEH
.....
.....
.....
1y1lZqkQICB9A=
"@
#LocalMachine
$location = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser
#ls Cert:\CurrentUser\
#ls Cert:\LocalMachine\
$storeName = 'TrustedPublisher'
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new($storeName, $location)
$store.Open('ReadWrite')
[byte[]]$content = [Convert]::FromBase64String($cert)
$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($content)
$store.Add($certificate)
$store.Close()
@echo off
@powershell.exe -ExecutionPolicy Bypass -Command "$fn = \"%~f0\"; $_=((Get-Content $fn) -join \"`n\");iex $_.Substring($_.IndexOf(\"goto :\"+\"EOF\")+9)"
@goto :EOF
Start-Process microsoft-edge:https://yoomoney.ru/moneylandia/lootboxes
Start-Sleep 5
Get-Process -Name "*msedge*" | Stop-Process
echo "$fn completed!"
pause