$credential = Get-Credential domain\Admin
#Сначала другим пользователем, а потом им же, но с повышенными правами
Start-Process -Credential $credential -FilePath powershell -ArgumentList "Start-Process -Verb runAs -FilePath powershell -ArgumentList 'Get-Service winrm; read-host'"
function ShowMenu([array]$Menu, [int]$Default)
{
$minY = [Console]::CursorTop
$y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0)
do {
[Console]::CursorTop = $minY
[Console]::CursorLeft = 0
$i = 0
foreach ($item in $Menu) {
$colors = @{
BackgroundColor = if ($i -ne $y) { [Console]::BackgroundColor } else { 'Cyan' }
ForegroundColor = if ($i -ne $y) { [Console]::ForegroundColor } else {' Blue' }
}
Write-Host (' {0}. {1} ' -f ($i+1), $item) @colors
$i++
}
$k = [Console]::ReadKey()
switch ($k.Key) {
'UpArrow' { if ($y -gt 0) { $y-- } }
'DownArrow' { if ($y -lt ($menu.Count - 1)) { $y++ } }
'Enter' { return $Menu[$y] }
}
} while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter))
}
$Menu = 'test1','text2','menu3','result4'
ShowMenu $menu 2
Get-ADUser -filter "samAccountName -like '*env'" | Set-ADUser -ScriptPath "somescriptname"
Get-ADGroupMember somegroupname | Set-ADUser -ScriptPath "somescriptname"
$user = [ADSI]"LDAP://$($user_DistinguishedName)"
#read
#$user.psbase.InvokeGet('TerminalServicesInitialProgram')
#write
$user.psbase.InvokeSet('TerminalServicesInitialProgram', 'cmd.exe')
$user.SetInfo()
Get-Process $processname | Foreach-Object { $pslist=@{} } { $pslist[$_.id]=$_.cpu }
Get-Process $processname | Where-Object { ($_.cpu - $pslist[$_.id])/($numcores*$sleepseconds) * 100 -gt 75 }
set_fact:
scriptdirs: {{ dirs. | selectattr(type, 'equalto', 'es_script') | list }}
template:
src: template.j2
dest: " {{ item.path }}"
mode: "{{ item.mode }}"
loop: "{{ scriptdirs }}"
$output = foreach ($item in $items)
{
#...
New-Object -TypeName PSObject -Property @{
#...
}
}
$output | Export-Csv -Encoding utf-8 -Path C:\organization.csv