daknetworks.com

You are here: Blog Powershell Useful Commands

Powershell Useful Commands

Powershell Useful Commands

This is my Powershell Useful Commands. They are commands that I want to use but can't remember their silly non-sensical syntax. I'll update it as I see fit. This is for me. If you can use it, great.

LOOK AT USER ACCOUNT EVERYTHING:
1.Get-Mailbox USERACCOUNT | Select *
LOOK AT USER ACCOUNT SELECTED PROPERTIES:
1.Get-Mailbox USERACCOUNT | Select prop1, prop2, etc
GET USER FORWARD EMAIL ACCOUNT
1.Get-Mailbox USERACCOUNT | FL *forward*
2.Get-Mailbox USERACCOUNT | Select Name, PrimarySMTPAddress, ForwardingAddress, ForwardingSMTPAddress, DeliverToMailboxAndForward

NOTE: There are two properties that are very similar ForwardingAddress & ForwardingSMTPAddress.

Here is the difference:
ForwardingAddress: This is to forward to another account within the same domain.
ForwardingSMTPAddress: This is to forward to an external account.

SET FORWARDING TO EXTERNAL EMAIL ADDRESS
1.Set-Mailbox USERNAME -DeliverToMailboxAndForward $true -ForwardingSMTPAddress forwarding-email-address.tld
DELETE FORWARDING TO EXTERNAL EMAIL ADDRESS
1.Set-Mailbox USERNAME -DeliverToMailboxAndForward $false -ForwardingSMTPAddress $Null
SET USER PSEUDONYM
1.Set-Mailbox USERACCOUNT -EmailAddresses foouser1-AT-domain.tld, foouser2-AT-domain.tld
2.<h5>FIND ALL USERS WITH FORWARDING ADDRESS IS SET TO EXTERNAL EMAIL ADDRESS</h5>
3.<h5>{code}Get-Mailbox | Where {$_.ForwardingsmtpAddress -ne $null} | Select Name, ForwardingAddress,ForwardingsmtpAddress, DeliverToMailboxAndForward
FIND ALL USERS IN A GROUP
1.Get-DistributionGroupMember GROUP-NAME-at-DOMAIN.TLD
FIND ALL INFO ABOUT A GROUP
1.Get-DistributionGroup GROUP-NAME-at-DOMAIN.TLD|FL
ADD USER TO A GROUP
1.Add-DistributionGroupMember -Identity GROUP-NAME-at-DOMAIN.TLD -Member USERNAME -BypassSecurityGroupManagerCheck"
REMOVE USER FROM A GROUP
1.Remove-DistributionGroupMember -Identity GROUP-NAME-at-DOMAIN.TLD -Member USERNAME -BypassSecurityGroupManagerCheck

By default only internal-accounts can email groups. To set a group to accept Senders outside of organization:

SET A GROUP TO ACCEPT SENDERS OUTSIDE OF THE ORGANIZATION
1.Set-DistributionGroup -Identity GROUP-NAME-at-DOMAIN.TLD -RequireSenderAuthenticationEnabled $False

WINDOWS AZURE AD MODULE

I don't know how to explain this. But here it goes... The following are commands that affect the USERACCOUNT at a root level. Because of this, REGULAR POWERSHELL (and all it's dependencies) can't run the commands. You have to get a SUPER POWERSHELL.

They call it the WINDOWS AZURE AD MODULE. It will only run on WINDOWS-7 & WINDOWS-8 and it requires something called ONLINE SERVICES SIGN IN ASSISTANT. Even though it is called a MODULE which maybe should just upgrade your current POWERSHELL, the truth is that it's another POWERSHELL (Trust me, nothing in Microsoft world makes sense).

DOWNLOAD WINDOWS AZURE AD MODULE

So, AS ADMINISTRATOR, you have to use this AD MODULE rather than POWERSHELL to make changes.

CONNECT WINDOWS AZURE AD MODULE TO OFFICE365
1.right-click WINDOWS AZURE AD MODULE click RUN AS ADMINISTRATOR type: $msolcred = get-credential type: connect-msolservice -credential $msolcred
SET USERNAME TO NOT REQUIRE STRONG PASSWORD
1.Set-MsolUser -UserPrincipalName jsmith-at-company.com -StrongPasswordRequired $false
HARD SET THE USERNAME PASSWORD AND DON'T REQUIRE A CHANGE
1.Set-MsolUserPassword -UserPrincipalName jsmith-at-company.com -NewPassword new-password-here -ForceChangePassword $false
DELETE USERNAME
1.Remove-MsolUser –UserPrincipalName USERNAME-at-DOMAIN.TLD
ADD USERNAME
1.New-MsolUser -DisplayName "testuser" –UserPrincipalName testuser-AT-yourdomain.com –UsageLocation "US" | Set-MsolUserLicense -AddLicenses "tenantname:ENTERPRISEPACK"

OTHER COMMON COMMANDS

ls: lists contents of directory.

cat: read contents of text file.

Select-String: the MS version of grep.

Contact Dak Networks

We are not taking on new clients at this time.