• Home
  • About
    • Building XP photo

      Building XP

      Let's be honest: I have no idea what this is all about. So why not have fun while learning things?

    • Learn More
    • Email
    • Twitter
    • LinkedIn
    • Github
    • Keybase
  • Posts
    • All Posts
    • All Tags
  • Log
    • All Posts

01 Feb. 2019

01 Feb 2019

Reading time ~1 minute

2019-02-01

  • Powershell.org forums doesn’t help me more than Reddit.
  • Several ways of distinguishing Desktops and Laptops:
    • Win32_SystemEnclosure.ChassisTypes
    • Win32_SystemComputer.PCSystemType
    • Win32_Battery
  • PKGDat/PKGX files
  • System.Security.Principal.WindowsIdentity
    • ::GetCurrent() : info about current user
    • ::New($username) : info about another user
  • Win32_UserAccount reads every user in the domain: awfully slow
    • You can Trick the machine with New-CIMInstance -Clientonly -Key
  • Win32_SystemUsers (still slow)
  • No CIM cmdlet equivalent of Get-WMIObject (shame) -There are WMI classes that cannot be enumerated: Win32_SID
  • SID/Username translation:
    • $NTA =New-Object Security.Principal.NTAccount -ArgumentList 'DOMAIN\User'
    • $NTA.Translate([Security.Principal.SecurityIdentifier])
    • $SecID = New-Object Security.Principal.SecurityIdentifier -Arg ‘'
    • $SecID.Translate([Security.Principal.NTAccount])
  • Win32_UserProfile : profiles saved locally, with SID
  • [DirectoryServices.AccountManagement.Principal]::FindByIdentity()

There are several types in AccountManagement (user, computer, group, etc.), but Principal has a FindByIdentity that works for everything. It even works for local accounts, without having to switch from Domain to Machine context.

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$context = [DirectoryServices.AccountManagement.PrincipalContext]::new('Domain')
ciminstance Win32_UserProfile | % {
    [DirectoryServices.AccountManagement.Principal]::FindByIdentity($context,$_.SID)
}

Dug through Chocolatey doc and code to find how to install to non-default paths: choco install ruby --params "/InstallDir:c:\stuff\ruby"

Installed Ruby, discovered Gem, thanks to searching how to create a github.io page with Jekyll. Got me a blank page at first, that’s what you get for trying to use a Gem not on github, apparently. Found my way through Jekyll thanks to the beautiful Moon theme, by Taylan Tatlı



PowerShellWMIdotnet Share Tweet +1