Skip to content

Instantly share code, notes, and snippets.

View alex4rks's full-sized avatar
:octocat:

alex4rks

:octocat:
  • Saint-Petersburg, Russia
View GitHub Profile
function Get-UsernameSID($AccountName) {
$NTUserObject = New-Object System.Security.Principal.NTAccount($AccountName)
$NTUserSID = $NTUserObject.Translate([System.Security.Principal.SecurityIdentifier])
return $NTUserSID.Value
}
@alex4rks
alex4rks / Reload-VideoContoller.ps1
Last active March 20, 2021 13:03
useful for gpu-passthru vms
#https://stackoverflow.com/a/47262639
$devices = Get-PnpDevice| where {$_.class -eq "Display" -and $_.FriendlyName -notmatch "^.*Microsoft.*|^.*Basic.*|^.*Vmware.*"}
foreach ($dev in $devices) {
$dev | Disable-PnpDevice -Confirm:$false
$dev | Enable-PnpDevice -Confirm:$false
}
# http://www.outsidethebox.ms/19318/
# This is preferred way to disable prefetch in Windows 10. Disabling SysMain service is not recommended:
# https://docs.microsoft.com/en-us/windows-server/security/windows-services/security-guidelines-for-disabling-system-services-in-windows-server#superfetch
# 3 - enables prefetching for Windows and API,
# 2 - enables only for API,
# 0 - disables completely.
reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" /v "EnablePrefetcher" /t REG_DWORD /d "0" /f
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability –Online
Get-Disk | Where partitionstyle -eq 'raw' |
Initialize-Disk -PartitionStyle gpt -PassThru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem NTFS -NewFileSystemLabel "Data" -Confirm:$false
$Secure = Read-Host -AsSecureString
# input password: **********
$hash = ConvertFrom-SecureString -SecureString $Secure
# get hash
$password = ConvertTo-SecureString -String $hash
# use hashed password in cmdlets
New-LocalUser -User $user -password $password -PasswordNeverExpires:$true -AccountNeverExpires:$true
###
### decrypt password
:: Set High performance power scheme
powercfg /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
:: Adjust graphics driver delay time (useful for old gpus, e.g. nvidia gtx 660)
reg add "HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers" /v "TdrDdiDelay" /t REG_DWORD /d "20" /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers" /v "TdrDelay" /t REG_DWORD /d "20" /f
reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "DisableTaskOffload" /t REG_DWORD /d "1" /f
netsh advfirewall firewall add rule name="Program Blocked with Batchfile" dir=out program="C:\Program Files\Program\Program.exe" action=block
@alex4rks
alex4rks / add_socket_assignment.bat
Last active March 20, 2021 13:11
add end user ability to create sockets in python as non-admin user
:: add end user ability to create sockets as non-admin user
:: netsh http add urlacl url=http://+:6000/ user="NT AUTHORITY\Authenticated Users" listen=yes
netsh http add urlacl url=http://+:6000/ user="NT AUTHORITY\Прошедшие проверку" listen=yes