Wednesday, December 7, 2022

20221207 PowerShell auto update

 PowerShell 7.2 enables a default auto update with Windows Update. 

To disable,

$pwshRegPath = "HKLM:\SOFTWARE\Microsoft\PowerShellCore"
if (!(Test-Path -Path $pwshRegPath)) {
    throw "PowerShell 7 is not installed"
}

Set-ItemProperty -Path $pwshRegPath -Name UseMU -Value 0 -Type DWord

Thursday, November 3, 2022

20221103 Windows Server 2019 Docker Linux container

Reference

https://stackoverflow.com/questions/57317141/linux-docker-ee-containers-on-windows-server-2016/57691939#57691939

https://github.com/docker/labs/issues/490

https://computingforgeeks.com/how-to-run-docker-containers-on-windows-server-2019/


Thursday, May 26, 2022

20220526 git move folders with their history to another repo

Main ref: https://mattsch.com/2015/06/19/move-directory-from-one-repository-to-another-preserving-history/

If there are multiple folders, we need to do thing differently.

  1. Source repo
    1. git remote rm origin
    2. git filter-branch --index-filter 'git rm --cached --ignore-unmatch -rf XXX' --prune-empty -f HEAD
      1. for all other folders or files
      2. for all subtrees, just do a clean up
  2. Dest repo
    1. git remote add <branch> <source repo directory>
    2. git checkout <branch>
    3. git checkout <Dest repo working branch>
    4. git merge develop --allow-unrelated-histories
    5. git push
    6. add back subtree
    7. git push
The assumption is that the directory names in the source repo remain the same in the dest repo.  If different, the commit history needs to change. 
  • Directory name and level manipulation shall be done at the Source repo side.  This shall greatly simplify the merge. 

Thursday, April 28, 2022

20220428 LDAP query

Download and install Remote Server Administration Tools for Windows 10

  • https://www.microsoft.com/en-us/download/details.aspx?id=45520

Open up a Powershell console and use Active Directory cmdlets

  • https://docs.microsoft.com/en-us/powershell/module/activedirectory/?view=windowsserver2022-ps

Examples:

Get-ADUser -Identity "username"

  • get basic user info

Get-ADPrincipalGroupMembership username| select name

  • get all groups that a user belongs to


Get-ADGroup

Get-ADGroupMembers



Wednesday, March 30, 2022

20220330 powershell configure pagefile.sys

 Only for Powershell 5

Get-Volume; $pagefile = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges; $pagefile.AutomaticManagedPagefile = $false; $pagefile.put(); $pagefileset = Get-WmiObject Win32_pagefilesetting; $pagefileset.InitialSize = 1024; $pagefileset.MaximumSize = 8339; $pagefileset.put();Gwmi win32_Pagefilesetting | Select Name, InitialSize, MaximumSize; restart-computer -force