PowerShell Stuff

To find all PS Commands in your computer

Get-Command

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

Change UPN of a user in O365

Store your O365 credentials in a variable

$msolcred = get-credential

Connect to O365

connect-msolservice -credential $msolcred

Change User Principal Name

Set-MsolUserPrincipalName -UserPrincipalName current@domain.onmicrosoft.com -NewUserPrincipalName newusername@domain.com

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