diff --git a/Scripts/Get-AltTab.ps1 b/Scripts/Get-AltTab.ps1 index 6a8c602..0e9e139 100644 --- a/Scripts/Get-AltTab.ps1 +++ b/Scripts/Get-AltTab.ps1 @@ -1,7 +1,6 @@ function Get-AltTab { -$wshell = New-Object -ComObject wscript.shell -$wshell.SendKeys("%{Tab}") -sleep 120 +(New-Object -ComObject wscript.shell).SendKeys("%{Tab}") +Start-Sleep $(Get-Random -Minimum 30 -Maximum 180) Get-AltTab } Get-AltTab \ No newline at end of file diff --git a/Scripts/Start-Shutdown.ps1 b/Scripts/Start-Shutdown.ps1 new file mode 100644 index 0000000..da53001 --- /dev/null +++ b/Scripts/Start-Shutdown.ps1 @@ -0,0 +1,36 @@ +function Start-Shutdown { + <# + .SYNOPSIS + Module for shutdown and restart the computer at a specified time + .DESCRIPTION + Example: + # Start-Shutdown -Time "18:00" + # Start-Shutdown -Restart -Time "18:00" + # Start-Shutdown -Cancel + .LINK + https://github.com/Lifailon/PS-Commands + #> + param( + [string]$Time, + [switch]$Restart, + [switch]$Cancel + ) + if ($Time) { + $currentDateTime = Get-Date + $shutdownTime = Get-Date $Time + if ($shutdownTime -lt $currentDateTime) { + $shutdownTime = $shutdownTime.AddDays(1) + } + $timeUntilShutdown = $shutdownTime - $currentDateTime + $secondsUntilShutdown = [math]::Round($timeUntilShutdown.TotalSeconds) + } + if ($Cancel) { + Start-Process -FilePath "shutdown.exe" -ArgumentList "/a" + } elseif ($Restart) { + Write-Host "The computer will restart after $($timeUntilShutdown.Hours) hours and $($timeUntilShutdown.Minutes) minutes." + Start-Process -FilePath "shutdown.exe" -ArgumentList "/r", "/f", "/t", "$secondsUntilShutdown" + } else { + Write-Host "The computer will shutdown after $($timeUntilShutdown.Hours) hours and $($timeUntilShutdown.Minutes) minutes." + Start-Process -FilePath "shutdown.exe" -ArgumentList "/s", "/f", "/t", "$secondsUntilShutdown" + } +} \ No newline at end of file diff --git a/Scripts/Telegraf-Replace-Win-Config.ps1 b/Scripts/Telegraf-Replace-Win-Config.ps1 new file mode 100644 index 0000000..c20584a --- /dev/null +++ b/Scripts/Telegraf-Replace-Win-Config.ps1 @@ -0,0 +1,40 @@ +$local_path = "D:\Telegraf-Replace-Win-Config" +$remote_path = "D:\Telegraf" +$csv = Get-Content "$local_path\win-all-nt.csv" +$conf = Get-Content "$local_path\telegraf.conf" -Raw -Encoding UTF8 +$srv_name_list = ($csv | ConvertFrom-Csv -Delimiter ",").name +foreach ($srv in $srv_name_list) { + #$srv = "tvsds-polit0110.delta.sbrf.ru" + $session = New-PSSession $srv -ErrorAction Ignore + if ($session) { + Invoke-Command -Session $session { + $name = (Get-WmiObject -Class Win32_ComputerSystem).Name+"."+(Get-WmiObject -Class Win32_ComputerSystem).Domain + $local_conf = "$using:remote_path\telegraf.conf" + $remote_conf = $using:conf + if (Test-Path $local_conf) { + Write-Host "Telegraf path to $name - true" -ForegroundColor Green + Get-Service telegraf | Stop-Service + #(Get-Filehash -Algorithm SHA256 $local_conf).Hash + $remote_conf | Out-File $local_conf -Encoding UTF8 + #(Get-Filehash -Algorithm SHA256 $local_conf).Hash + Get-Service telegraf | Start-Service -ErrorAction Ignore + $status = Get-Service telegraf | Select-Object + if ($status.Status -eq "Stopped") { + Get-Service telegraf | Start-Service -ErrorAction Ignore + $status = $(Get-Service telegraf | Select-Object) + } + if ($status.Status -eq "Stopped") { + Write-Host "Telegraf service $($status.Status) to $($using:srv)" -ForegroundColor Red + } else { + Write-Host "Telegraf service $($status.Status) to $($using:srv)" -ForegroundColor Green + } + } else { + Write-Host "Telegraf path to $name - false" -ForegroundColor Red + } + } + Disconnect-PSSession $session > $null + Remove-PSSession $session > $null + } else { + Write-Host "Connect to $srv - false" -ForegroundColor Red + } +} \ No newline at end of file