PowerShell Stuff

To find all PS Commands in your computer


Understanding the Results of the Get-Command Cmdlet

There are four columns in the results of the Get-Command Output

With this information, you can filter the results from Get-Command. Say you want to see PowerShell commands containing the word “EventLog”, running the command below will get the job done:

Get-Command -Name *EventLog

Connect PS to Remote Computer

Enter-PSSession -ComputerName COMPUTER -Credential USER

List All User Password Ages

get-aduser -filter * -properties passwordlastset, passwordneverexpires |ft Name, passwordlastset, Passwordneverexpires

List All User Password Expiration Dates

Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" | Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}

Find All Locked Account

Search-ADAccount -LockedOut

Remove Inactive RDS User Profiles

Take ownership of ‘folder.V2’ path

takeown /r /d Y /f .\folder.V2

Grant open permissions to the folder (for easy deletion)

icacls .\folder.V2 /grant Everyone:F /T

Delete the ‘folder.V2’ path

remove-item -path .\folder.V2 -force -recurse

Migrate DHCP server configuration

Export the existing configuration:

Export-DHCPServer -ComputerName <old server> c:\dhcp.xml -ver -leases

Import to the new server:

Import-DHCPServer -ComputerName <new server> c:\dhcp.xml -backuppath c:\dhcpbackup -leases

Fix Common BPA Scan Results on new Windows Servers

Using command prompt as administrator

Get All AD Users Logon History with their Logged on Computers (with IPs) & OUs