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
[System.BitConverter]::ToSingle(@(0xcd,0xcc,0x4c,0x41),0)
12,8
$usb = Get-ChildItem -path HKLM:\SYSTEM\ControlSet001\Enum\USB\ -Recurse
$usb | Where-Object { $_.GetValue('Address') -eq 4 }
$usb[1].<Ctrl+Space>
Get-Member -InputObject $usb[1]
$x = 'test'
psexec \\server powershell -NoProfile -Сommand "write-host '$X'"
psexec \\server powershell -NoProfile -Command "param(`$a) write-host `$a" $x
New-ItemProperty -LiteralPath HKCR:\Microsoft.PowerShellScript.1\Shell\runas\command -Name '(Default)' -Value 'powershell.exe -NoExit -Command "if((Get-ExecutionPolicy ) -ne ''AllSigned'') { Set-ExecutionPolicy -Scope Process Bypass }; & ''%1''"' -PropertyType String -Force | Out-Null;
#А вообще пароль проще запросить
$cred = get-credential
#и использовать
Import-ExchangeCertificate -FileName "C:\mail\mail.pfx" -Password $cred.Password
Invoke-Command -ComputerName $computer { C:\Temp\Install.exe /S }
$session = New-PSSession -ComputerName $computer
Invoke-Command -Session $session { C:\Temp\Install.exe /S }
Invoke-Command -Session $session { C:\Temp\Install2.exe /S }
$Date = get-date -Format "yyyy-MM-dd"
Get-ChildItem -Path "I:\BACKUP\File_$Date*.bak"
# Если непременно надо подчёркивание, то переменную придётся выделить
# Get-ChildItem -Path "I:\BACKUP\File_$($Date)_*.bak"
$folders = 'E:\BASE\enm*\pm*','F:\DATE\enm*\pm*'
$send_mail = $false
Get-ChildItem -force $folders -ErrorAction SilentlyContinue | Where-Object { $_ -is [io.directoryinfo] } | ForEach-Object {
$len = 0
Get-ChildItem -recurse -force $_.fullname -ErrorAction SilentlyContinue | ForEach-Object { $len += $_.length }
$colors = @{$False='black'; $True='red'}
$_.fullname+' - ', '<font color="{1}">{0:N2} Gb</font>' -f ($len / 1Gb), $colors[$len -ge 3Gb]
if ($len -ge 3Gb) {
$send_mail = $True
}
} | Tee-Object -Variable body
if ($send_mail)
{
Send-MailMessage-From 'test@test.ru' -To 'test@test.ru', -Subject "enm size" -BodyAsHtml ($Body -join "<br>`r`n") –SmtpServer '10.10.10.10'
}
$c = Get-Content d:\your_file.txt
$c | Foreach-Object -Begin { $data = @{} } -Process { $a = $_ -split ':', 2; if ($a.Length -eq 2) { $data[$a[0].Trim()] = $a[1].Trim() } } -End { [PSCustomObject]$data }
$info = $c | ......
[float]($info.Download -replace 'Mbps.*')
PS D:\> $s = '<?xml version="1.0" encoding="utf-8"?>
>> <Data>
>> <Card>
>> <Id>123</Id>
>> <CreateDate>2022-06-20T21:01:32.7727011+05:00</CreateDate>
>> <CardData>
>> <Id>456</Id>
>> <Value>789</Value>
>> <Ord>0</Ord>
>> </CardData>
>> </Card>
>> </Data>'
PS D:\> $xml = [xml]$s
PS D:\> function ConvertFrom-Xml2 {
>> param([parameter(Mandatory, ValueFromPipeline)] [System.Xml.XmlNode] $node)
>> process {
>> if ($node.DocumentElement) { $node = $node.DocumentElement }
>> $oht = [ordered] @{}
>> $name = $node.Name
>> if ($node.FirstChild -is [system.xml.xmltext]) {
>> $oht.$name = $node.FirstChild.InnerText
>> } else {
>> $oht.$name = New-Object System.Collections.ArrayList
>> foreach ($child in $node.ChildNodes) {
>> $null = $oht.$name.Add((ConvertFrom-Xml2 $child))
>> }
>> }
>> $oht
>> }
>> }
PS D:\> $xml | ConvertFrom-Xml2 | ConvertTo-Json -Depth 10
{
"Data": [
{
"Card": [
{
"Id": "123"
},
{
"CreateDate": "2022-06-20T21:01:32.7727011+05:00"
},
{
"CardData": [
{
"Id": "456"
},
{
"Value": "789"
},
{
"Ord": "0"
}
]
}
]
}
]
}