r/PowerShell • • Dec 01 '25

PowerShell Profile

What cool things have you done with your profile?

10 Upvotes

37 comments sorted by

View all comments

1

u/jsiii2010 Dec 03 '25 edited Dec 03 '25
# add commandline property to get-process output in powershell 5.1
$updateTypeData = @{
    TypeName   = 'System.Diagnostics.Process'
    MemberName = 'CommandLine'
    MemberType = [Management.Automation.PSMemberTypes]::ScriptProperty
    Force      = $true
    Value      = { (Get-CimInstance Win32_Process -Filter "ProcessId = 
                   $($this.Id)").CommandLine }
}
Update-TypeData @updateTypeData

# tab complete property names after "get-aduser -property "
# get-aduser js -property * | gm -membertype property | % name
$aduserProps = -split 'AccountExpirationDate accountExpires
AccountLockoutTime AccountNotDelegated
AllowReversiblePasswordEncryption AuthenticationPolicy
AuthenticationPolicySilo BadLogonCount badPasswordTime badPwdCount
businessCategory c CannotChangePassword CanonicalName Certificates
City CN codePage Company CompoundIdentitySupported Country countryCode
Created createTimeStamp Deleted Department departmentNumber
Description DisplayName Division DoesNotRequirePreAuth
dSCorePropagationData EmailAddress EmployeeID EmployeeNumber
extensionAttribute5 extensionAttribute6 facsimileTelephoneNumber Fax
flags HomeDirectory HomedirRequired HomeDrive HomePage HomePhone
Initials instanceType isDeleted KerberosEncryptionType l
LastBadPasswordAttempt LastKnownParent lastLogon LastLogonDate
lastLogonTimestamp LockedOut lockoutTime logonCount LogonWorkstations
mail Manager MemberOf MNSLogonAccount MobilePhone Modified
modifyTimeStamp mS-DS-ConsistencyGuid
msDS-User-Account-Control-Computed msTSExpireDate msTSLicenseVersion
msTSLicenseVersion2 msTSLicenseVersion3 msTSManagingLS
nTSecurityDescriptor ObjectCategory objectSid Office OfficePhone
Organization OtherName PasswordExpired PasswordLastSet
PasswordNeverExpires PasswordNotRequired POBox PostalCode PrimaryGroup
primaryGroupID PrincipalsAllowedToDelegateToAccount ProfilePath
ProtectedFromAccidentalDeletion proxyAddresses pwdLastSet
sAMAccountType ScriptPath sDRightsEffective ServicePrincipalNames
SIDHistory SmartcardLogonRequired sn st State StreetAddress
telephoneNumber Title TrustedForDelegation TrustedToAuthForDelegation
uid uidNumber UseDESKeyOnly userAccountControl userCertificate
uSNChanged uSNCreated whenChanged whenCreated'

$scriptBlock = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    $aduserProps | ? { $_ -like "$wordToComplete*" } 
}
# had to be "properties" not "property"
Register-ArgumentCompleter -CommandName get-aduser -ParameterName properties -ScriptBlock $scriptBlock