Generated by All in One SEO v5.0.0.1, this is an llms.txt file, used by LLMs to index the site. # knuckleheadTech Tech for knuckleheads ## Sitemaps - [XML Sitemap](https://knuckleheadtech.com/sitemap.xml): Contains all public & indexable URLs for this website. ## Posts - [pwsh..WMI](https://knuckleheadtech.com/2024/05/16/pwsh-wmi/) - Namespaces Listing all Namespaces # create a new queue $namespaces = [System.Collections.Queue]::new() # add an initial namespace to the queue # any namespace in the queue will later be processed $namespaces.Enqueue('root') # process all elements on the queue until all are taken While ($namespaces.Count -gt 0 -and ($current = $namespaces.Dequeue())) { # find child namespaces - [pwsh..Set-ADUser](https://knuckleheadtech.com/2024/05/16/pwsh-set-aduser/) - Modify PwdLastSet for testing $ID= "CN=testaccount,OU=Datacenter,DC=coolDomain,DC=COM" Set-ADUser -Identity "$ID" -Replace @{pwdlastset="0"} Set-ADUser -Identity "$ID" -Replace @{pwdlastset="-1"} get-aduser $ID -property passwordlastset, passwordneverexpires Update ExtensionAttribute 14 and Description $services = Get-Content -Path "D:\psExports\LISTS\service_accounts.txt" Foreach ($s in $services) { Set-AdUser $s -Clear "Description" Set-AdUser $s -Add @{Description = "Owner - Bob Snobb"} Set-AdUser $s -Clear "ExtensionAttribute14" Set-AdUser $s - [pwsh..SearchBase OU](https://knuckleheadtech.com/2024/05/16/pwsh-searchbase-ou/) - To see all admin accounts in the admin's OUs $OUs = "OU=AdministratorAccounts,OU=Datacenter,DC=coolDomain,DC=COM", "OU = Admin.Accounts,OU=Azure_Admin_Center,DC=coolDomain,DC=COM" $OUs | foreach { Get-ADUser -Filter * -SearchBase $_ -Properties LastLogonDate,passwordlastset} | Select samaccountname,enabled,LastLogonDate,passwordlastset To see all admin accounts in these OUs search for "." and zz*, so the xx.5+5 accounts $OUs= "OU=AdministratorAccounts,OU=Datacenter,DC=coolDomain,DC=COM", "OU=Admin.Accounts,OU=Azure_Admin_Center,DC=coolDomain,DC=COM" $OUs | foreach { Get-ADUser -Filter - [pwsh..Search Applications](https://knuckleheadtech.com/2024/05/16/pwsh-search-applications/) - Use PowerShell to find list of installed software quickly PowerShell: Check installed software list locally 1. Get installed software list with Get-WmiObject In this method, a simple query: Get-WmiObject -Class Win32_Product Filter the data to find specific applications from a single vendor, together with their versions, for example: Get-WmiObject -Class Win32_Product | where vendor -eq - [pwsh..RSAT](https://knuckleheadtech.com/2024/05/16/pwsh-rsat/) - RSAT instructions, including netsh for proxy # To get past internet blocks, in admin cmd: netsh winhttp set proxy 192.168.1.2:3128 # In admin powershell get the path and see if WSUS is in use Get-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU" | select UseWuServer # Set it to 0 to disable WSUS on the client and restart service to - [pwsh..Password Mgmt](https://knuckleheadtech.com/2024/05/16/pwsh-password-mgmt/) - Password Not Expire Searching All get-aduser -filter * -properties Name, PasswordNeverExpires | where {$_.passwordNeverExpires -eq "true" } | Select-Object DistinguishedName,Name,Enabled Only enabled users get-aduser -filter {Enabled -eq "true"} -properties Name, PasswordNeverExpires | where {$_.passwordNeverExpires -eq "true" } | Select-Object Name,samaccountname,DistinguishedName Enable only, plus excluding HealthMailbox because it craps up the results get-aduser -filter {Enabled -eq - [pwsh..OS Counts](https://knuckleheadtech.com/2024/05/16/pwsh-os-counts/) - #basic Get-ADComputer -Filter "name -like '*'" -Properties operatingSystem | group -Property operatingSystem | ` Select Name,Count | Sort Name | ft -AutoSize # Workstations Get-ADComputer -Filter 'operatingsystem -notlike "*server*" -and enabled -eq "true"' -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName,lastLogonDate |` Sort-Object -Property Operatingsystem | ` Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address,lastLogonDate,CanonicalName | ` Export-Csv C:\Scraps\ad_computers\domainX_workstations_03-03-2022.csv -NoTypeInformation #servers Get-ADComputer -Filter 'operatingsystem -like "*server*" - [pwsh..Monitoring Resources](https://knuckleheadtech.com/2024/05/16/pwsh-monitoring-resources/) - Test-Netconnection from a list. $complist = Get-Content "C:\scraps\lists\ff-108.txt" foreach($item in $complist){ $pingtest = Test-Connection -ComputerName $item -Quiet -Count 1 -ErrorAction SilentlyContinue if($pingtest){ Write-Host($item + " is online") } else{ Write-Host($item + " is not reachable") } } From the Registry -- Checking both keys for software $INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, UninstallString $INSTALLED - [pwsh..LAPS admPwd](https://knuckleheadtech.com/2024/05/16/pwsh-laps-admpwd/) - Simple one liner to retrieve LAPS password Replace Export-Csv with OGV or other as needed. Replace $computer with hostname as needed Get-ADComputer $computer -Properties ms-Mcs-AdmPwd | ` Select DNSHostName,Enabled,Name,ms-Mcs-AdmPwd,ObjectGUID | ` Export-Csv .\admPwd.csv -NoTypeInformation -Append -Force Gathering LAPS info in hughman readable remove -filter and add the computerName if running against 1 system $AC = - [pwsh..Hash Filetype Array](https://knuckleheadtech.com/2024/05/16/pwsh-hash-filetype-array/) - $items = Get-ChildItem "C:\temp" foreach($item in $items){ $item.fullname $($item.Extension).Substring(1) #$hash.($($item.Extension).Split(".")[1]) $hash.($($item.Extension).Substring(1)) } $hash = @{ accdb = "Microsoft Access database file"; accde = "Microsoft Access execute-only file"; accdr = "Microsoft Access runtime database"; accdt = "Microsoft Access database template"; avi = "Audio Video Interleave movie or sound file"; bat = "PC batch file"; bin = - [pwsh..GPO Perms](https://knuckleheadtech.com/2024/05/16/pwsh-gpo-general/) - Building a report Don't forget you need the GroupPolicy module installed. That will come from RSAT. set a variable to capture all GPO info $GPOs = Get-GPO -All Use this to get the access rights $ACLs = Get-GPPermission -Guid $GPO.Id -All Script from Easy365Manager - another most excellent site # Set up output file $File - [pwsh..Copy-Item](https://knuckleheadtech.com/2024/05/16/pwsh-copy-item/) - This shows copying from local to a domain sysvol to update the policy store. But really it is just an example of copying local to remote. NOTE: Since this references copying into the domain sysvol you MUST perform this as a domain or enterprise admin. If you can copy to sysvol without those creds you - [pwsh..Az Login](https://knuckleheadtech.com/2024/05/16/pwsh-az-login/) - AzureCLI Endpoints when behind a proxy To Login login to gcch by setting the cloud type first az cloud set --name AzureUSGovernment Then login: az login Welcome to Azure CLI! - always good to see Use az -h to see available commands or go to https://aka.ms/cli. Welcome to the cool new Azure CLI! - Everything - [pwsh..Check .Net Version](https://knuckleheadtech.com/2024/05/16/pwsh-check-net-version/) - Not every post is robust. Some are just bits to not forget that thing. Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | ` Get-ItemProperty -Name version -EA 0 | ` Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version - [pwsh..AD-Groups](https://knuckleheadtech.com/2024/05/16/pwsh-ad-groups/) - Checking AD group for users that are enabled: # enabled $groupname = "FS-Finance" $users = Get-ADGroupMember -Identity $groupname | ` ? {$_.objectclass -eq "user"} foreach ($activeusers in $users) { Get-ADUser -Identity $activeusers | ` ? {$_.enabled -eq $true} | ` select Name, SamAccountName, UserPrincipalName, Enabled } Checking AD group for users that are disabled: # - [pwsh..AD Account Searches](https://knuckleheadtech.com/2024/05/16/pwsh-ad-account-searches/) - Attributes Converting Manager attribute to show the manager's email address. @{Name="ManagerEmail";Expression={(get-aduser -property emailaddress $_.manager).emailaddress}} Contractors & Admins Searching for contractors based on a list of users provided. Filtering on Surname, DisplayName having (Contr) in it, and making sure they are enabled $S = Get-Content -Path D:\psExports\LISTS\contr-sams.txt $S | Foreach { Get-ADUser -Filter {SN -eq $_ - [pwsh..AD Account Disable/Enable/Lock](https://knuckleheadtech.com/2024/05/16/pwsh-ad-account-disable-enable-lock/) - Disable Search for an account with name bobdob found only in a given OU and disable Get-ADUser -Filter 'Name -like "name"' -SearchBase "OU=Finance,OU=UserAccounts,DC=Domain,DC=COM" | Disable-ADAccount Disable, but make sure it's the correct account Get-ADUser $user | Disable-ADAccount # or Disable-Account -Identity userName From a CSV file $users=Import-CSV c:\temp\users.csv ForEach ($user in $users) { Disable-ADAccount - [Linux..command NsLookup](https://knuckleheadtech.com/2024/05/16/linux-command-nslookup/) - basic $ nslookup hostname reverse $ nslookup 192.168.1.2 soa record $ nslookup -type=soa redhat.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: redhat.com origin = a1-68.akam.net mail addr = noc.redhat.com serial = 2023013100 refresh = 300 retry = 180 expire = 604800 minimum = 14400 Authoritative answers can be found from: a1-68.akam.net internet address = 193.108.91.68 a1-68.akam.net - [Linux..command DU](https://knuckleheadtech.com/2024/05/16/linux-command-du/) - Standard human readable du -h Human readable looking for the 5 largest in the current dir sudo du -hs * | sort -rh | head -5 sudo du -a | sort -n -r | head -n 5 ## Pages - [Home](https://knuckleheadtech.com/) - This site is mostly a dump of my random notes over the years. These notes are a collection of a bunch of txt files, CherryTree notebooks, and Obsidian notes. Mostly I just grab a little snippet and move on. Occasionally add a little nugget here and there. Another big use of my notes is to ## Categories - [Linux](https://knuckleheadtech.com/category/linux/) - All things Linux - [linux.commands](https://knuckleheadtech.com/category/linux/linuxcommands/) - Linux commands - [PowerShell](https://knuckleheadtech.com/category/pwsh/) - PowerShell related - [pwsh.AD](https://knuckleheadtech.com/category/pwsh/pwshad/) - All things PowerShell and Active Directory - [pwsh.AppMgmt](https://knuckleheadtech.com/category/pwsh/pwshapps/) - PowerShell to work with applications, app settings, and similar. - [pwsh.Azure](https://knuckleheadtech.com/category/pwsh/pwshazure/) - Well, PowerSell for Azure. - [pwsh.Tasks](https://knuckleheadtech.com/category/pwsh/pwshtasks/) - General PowerShell tasks.