Skip to content

Instantly share code, notes, and snippets.

@mcxiaoke
Last active December 15, 2022 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcxiaoke/588c2313c81cfaf87209c6ebbff546aa to your computer and use it in GitHub Desktop.
Save mcxiaoke/588c2313c81cfaf87209c6ebbff546aa to your computer and use it in GitHub Desktop.
Windows 10 Tips

嵌套虚拟化在虚拟机中运行 Hyper-V

Set-VMProcessor -VMName -ExposeVirtualizationExtensions $true

Hyper-V 虚拟机连接外网方案

使用内部交换机,假设IP为 192.168.137.x
添加NAT,然后重启虚拟机
https://www.vembu.com/blog/hyper-v-virtual-switch-using-nat-setup/
https://charbelnemnom.com/how-to-configure-hyper-v-virtual-switch-that-supports-nat-network-with-powershell-hyperv-powershell/

New-NetNat -Name HyperVNat -InternalIPInterfaceAddressPrefix 192.168.137.0/24

批处理文件获取目录文件等

set filepath="C:\some path\having spaces.txt"
for /F "delims=" %%i in (%filepath%) do set dirname="%%~dpi"
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"

ffmpeg按最大边长保持长宽比缩放

ffmpeg -vf 'scale=if(gte(iw,ih),min(1280,iw),-2):if(lt(iw,ih),min(1280,ih),-2)'

dotnet application slim and single file

dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true /p:IncludeNativeLibrariesForSelfExtract=true

Windows CMD batch file get date time

https://stackoverflow.com/questions/7727114/batch-command-date-and-time-in-file-name

for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I

SSH Copy ID

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh {IP-ADDRESS-OR-FQDN} "cat >> .ssh/authorized_keys"

Set System Proxy using PowerShell

https://www.scriptinglibrary.com/languages/powershell/how-to-modify-your-proxy-settings-with-powershell/

$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $regKey -name ProxyServer -Value "$($server):$($port)"
Set-ItemProperty -Path $regKey -name ProxyEnable -Value 1

Git pull all using PowerShell

param()
function Get-AllRepos ()
{
    Get-ChildItem -Recurse -Depth 2 -Force |
        Where-Object { $_.Mode -match "h" -and $_.FullName -like "*\.git" } |
        ForEach-Object {
            $dir = Get-Item (Join-Path $_.FullName "../")
            pushd $dir
            "Fetching $($dir.Name)"
            git pull
            popd
        }
 }
Get-AllRepos

change wallpaper background using PowerShell script

do not use $RegKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP"

use User32.dll function instead, is working

Install HEVC Video Extension

open ms-windows-store://pdp/?ProductId=9n4wgh0z6vhq in browser

Startup Folder

Windows 11/10 startup folder location
To open the Windows 11/10 Startup folder:
Open the WinX Menu
Select Run to open the Run box
Type shell:startup and hit Enter to open the Current Users Startup folder
Type shell:common startup and hit Enter to open the All Users Startup folder

DSIM Usage

; get wim info
C:\Windows\System32 > Dism.exe /get-wiminfo /wimfile:”C:\install.wim”
; mount wim
C:\Windows\System32>Dism /mount-wim /wimfile:”C:\install.wim” /index:3 /MountDir:D:\1
; unmount wim
C:\Windows\System32 > Dism /unmount-wim /MountDir:d:\1 /discard

Windows Tips

; PowerShell set http_proxy/https_proxy 
; Using context parameters to add a proxy configuration in your PowerShell script 
; https://docs.vmware.com/en/VMware-Cloud-Assembly/services/Using-and-Managing/GUID-58652BA4-2254-4B3B-85A9-6662CB01D1F4.html 
$proxyString = "http://" + $context.proxy.host + ":" + $context.proxy.port
$Env:HTTP_PROXY = $proxyString
$Env:HTTPS_PROXY = $proxyString

windows powershell alias set

Set-Alias -Name list -Value Get-ChildItem
#windows powershell equal of which
Get-Command ipconfig
Get-Command -CommandType Application

Repair System Errors

DISM.exe /Online /Cleanup-image /Restorehealth
sfc /scannow

VIMRC not working

Instead of using the user vimrc file: $HOME_vimrc and user gvimrc file: $HOME_gvimrc I used 2nd user vimrc file: $HOME\vimfiles\vimrc and 2nd user gvimrc file: $HOME\vimfiles\gvimrc

  • working: $HOME\vimfiles\vimrc
  • not working: $HOME/_vimrc
   system vimrc file: "$VIM\vimrc"
     user vimrc file: "$HOME\_vimrc"
 2nd user vimrc file: "$HOME\vimfiles\vimrc"
 3rd user vimrc file: "$VIM\_vimrc"
      user exrc file: "$HOME\_exrc"
  2nd user exrc file: "$VIM\_exrc"
       defaults file: "$VIMRUNTIME\defaults.vim"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment