Advertisement
Guest User

Useful Commands

a guest
Aug 3rd, 2020
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.54 KB | None | 0 0
  1. Import AD shell into Exchange shell > Import-Module ActiveDirectory
  2. Add exchange commands to shell > Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
  3.  
  4. CREATE NEW REMOTE MAIL USER
  5. #Creates remote mailbox. Run in Exchange shell
  6. Enable-remotemailbox -identity [email protected] -remoteroutingaddress [email protected]
  7.  
  8. USEFUL EXPORTS FOR REPORTING
  9. #Fastest export for members of an AD group
  10. Get-ADUser -filter {(memberOf -eq "CN=OutlookSignature_CCG_REDACTED,OU=CityREDACTEDUsers,DC=cityREDACTED,DC=local") -AND (enabled -eq $true)} | Select name, givenname, surname, userPrincipalName | Export-Csv \\CC74321\C$\Temp\REDACTED.CSV
  11. #Online powershell, fastest export for DLs
  12. Get-distributiongroupmember "DL Payslip Attachments 1" | Select name, firstname, lastname, primarysmtpaddress | export-csv \\cc74321\c$\temp\DL1.csv
  13. #Accurate export for all active user accounts. Filter by OU (OU=City REDACTED Users,OU=City REDACTED,DC=cityREDACTED,DC=local) if you want only staff.
  14. Get-ADUser -filter {enabled -eq $true} -properties * | select name,emailaddress,description | export-csv \\cc74321\c$\temp\ADUsers.CSV
  15.  
  16. EXPORT A LIST OF USERS IN MORE THAN ONE GROUP
  17. #Specify groups
  18. #$GroupA = "CN=MFA_Office,OU=Azure Groups,OU=City REDACTED Groups,OU=City REDACTED,DC=cityREDACTED,DC=local"
  19. $GroupA = "CN=MFA_Fieldstaff,OU=Azure Groups,OU=City REDACTED Groups,OU=City REDACTED,DC=cityREDACTED,DC=local"
  20. $GroupB = "CN=OutlookSignature_CCG_REDACTED,OU=CityREDACTEDUsers,DC=cityREDACTED,DC=local"
  21. #Export all users that are members of both groups
  22. Get-ADUser -filter {(memberOf -eq $GroupA) -And (memberOf -eq $GroupB)} | Select name, givenname, surname, userPrincipalName | Export-Csv \\CC74321\C$\Temp\REDACTEDFieldStaff.CSV
  23.  
  24. OTHER MISC EXPORTS
  25. get-adgroupmember allccusers | find OU="Pages Road"
  26. Get-ADGroupMember -Identity <groupname> | Get-ADUser -properties * | select name,samaccountname,emailaddress | export-csv \\CC74321\C$\Temp\Group.csv
  27. Get-ADGroupMember "Reportcentralexcelfinance" | select name | export-csv \\CC74321\C$\Temp\Reportexcelfinance.csv
  28. Get-ADUser -filter {enabled -eq $true} | where DistinguishedName -notlike "*field staff*" | export-csv \\cc70080\c$\temp\ADUsers.CSV
  29. Get-ADUser -searchbase "OU=Standard Users,OU=City REDACTED Users,OU=City REDACTED,DC=cityREDACTED,DC=local" -filter 'description -notlike "*"' -properties * | select name,emailaddress,description | export-csv \\cc74321\c$\temp\ADUsers.CSV
  30. Get-ADUser -filter {name -eq "Arne Burgess"} -properties lastlogondate
  31.  
  32. $Date = (Get-Date).AddDays(-90)
  33. Get-ADUser -Filter {PasswordLastSet -LT $Date} -Properties PasswordLastSet -SearchBase "OU=Standard Users,OU=City REDACTED Users,OU=City REDACTED,DC=cityREDACTED,DC=local" | Export-CSV \\CC74321\C$\Temp\PasswordsExpired.CSV
  34.  
  35. Get-Mailbox | fl
  36. Get-Mailbox | ?{$_.ExchangeUserAccountControl -eq 'AccountDisabled'} | Get-MailboxAutoReplyConfiguration | select identity,autoreplystate
  37. #This single-line command will export to CSV a list of any mailboxes where other users have permissions to access them, and will also list what level of access those users have.
  38. Get-Mailbox | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | Select Identity,User,@{Name='Access Rights';Expression={[string]::join(', ', $_.AccessRights)}} | Export-Csv -NoTypeInformation mailboxpermissions.csv
  39. Get-User -RecipientTypeDetails RemoteUserMailbox -ResultSize Unlimited | where {$_.UseraccountControl -notlike "*accountdisabled*"} | Select-Object DisplayName,WindowsEmailAddress | export-csv \\cc70080\c$\temp\allemailaccounts.csv
  40. Set-MailContact "Lemon King" -emailaddresspolicyenabled $false
  41. Set-mailbox -identity [email protected] -type regular
  42.  
  43. Import-CSV \\cc70080\c$\temp\webstandard.csv | ForEach {Add-ADGroupMember -Identity "WebFilter_StandardUsers" -members $_.samAccountname}
  44.  
  45. netstat -na | Find "10.10.253.6"
  46.  
  47. MAILBOX PERMISSION
  48. Connect-EXOPSSession
  49. Add-MailboxPermission -identity [email protected] -user [email protected] -accessrights fullaccess -inheritancetype all
  50. #additional commands
  51. Add-RecipientPermission -Identity [email protected] -Trustee [email protected] -AccessRights SendAs
  52. Remove-MailboxPermission -identity [email protected] -user [email protected]
  53. Get-Mailboxpermission -identity [email protected]
  54. Get-MailboxFolderPermission -identity [email protected]:\calendar
  55. Add-MailboxFolderPermission -identity [email protected]:\Calendar -user "Default" -AccessRights Editor
  56. Set-MailboxFolderPermission -identity [email protected]:\Calendar -user "Lemon King" -AccessRights [AvailabilityOnly,LimitedDetails,Editor]
  57. Set-Mailbox [email protected] -DeliverToMailboxAndForward $true -ForwardingAddress [email protected]
  58.  
  59. CREATE SHARED MAILBOX
  60. Enable-Mailbox -Identity [email protected] -Shared -Database DB01
  61.  
  62. CHANGE MAILBOX TYPE
  63. Set-Mailbox [email protected] -Type [Regular,Room,Shared]
  64.  
  65. UPDATE UPN in MSOL
  66. Connect-MSOLService
  67. Set-MsolUserPrincipalName -UserPrincipalName [email protected] -NewUserPrincipalName [email protected]
  68.  
  69. BULK IMPORT SCRIPT (PAYSLIP)
  70. $Table = Import-Csv C:\Temp\Lemon\PayslipImport.csv
  71. $Table | %{New-MailContact -Name $_.Name -DisplayName $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.First -LastName $_.Last -OrganizationalUnit 'cityREDACTED.local/CityREDACTEDEmployees NON COMPUTER USERS'}
  72. $Table | %{Set-MailContact -Identity $_.Name -hiddenfromaddresslistsenabled $true -emailaddresspolicyenabled $false}
  73.  
  74. BULK IMPORT USERS TO GROUP
  75. $Table = Import-CSV \\CC74321\C$\Temp\GroupUsers.csv
  76. $Table | %{Add-ADGroupMember -Identity GROUP -Members $Table.SAMAccountName}
  77.  
  78. COPY GROUPS FROM ONE USER TO ANOTHER
  79. $templateuser = read-host 'Template user'
  80. $newuser = read-host 'New user'
  81. $CopyFromUser = Get-ADUser $templateuser -prop MemberOf
  82. $CopyToUser = Get-ADUser $newuser -prop MemberOf
  83. $CopyFromUser.MemberOf | Where{$CopyToUser.MemberOf -notcontains $_} | Add-ADGroupMember -Members $CopyToUser
  84.  
  85. MESSAGE TRACE
  86. Exchange online powershell
  87. Get-MessageTrace -SenderAddress "[email protected]" -StartDate 06/13/2019 -EndDate 06/15/2019 | FL > \\cc74321\c$\temp\report.csv
  88. Note: date is american format, MM/dd/YYYY
  89.  
  90. ROBYCOPY FROM BACKUP
  91. subst X: "\\cityREDACTED.local\DivisionDrives\National Maintenance\@GMT-2018.04.30-19.00.09\Underground\Users\"
  92. robocopy X: "\\cityREDACTED.local\DivisionDrives\National Maintenance\Underground\Users\" /E
  93. ONCE DONE
  94. subst X: /D
  95.  
  96. USER EXPIRED.CMD
  97. @Echo off
  98. :START
  99. echo username please:
  100. set /p username=
  101. net user %username% /domain | find "Password"
  102. if (%username%)==(end) goto END
  103. goto START
  104. :END
  105. Pause
  106.  
  107.  
  108. MAK Key activation: slmgr.vbs /ipk <MultipleActivationKey>
  109. Re-check KMS activation: slmgr -rearm
  110.  
  111. RESET LOCAL ACCOUNT PASSWORD (elevated command prompt)
  112. net user administrator password
  113.  
  114. SET OUT OF OFFICE
  115. #Format is mm/dd/yyyy and NZ is +13 hours
  116. Set-MailboxAutoReplyConfiguration -Identity [email protected] -AutoReplyState Enabled -startdate "mm/dd/yyyy 1:00 AM" -enddate "mm/dd/yyyy 5:00 PM"
  117. #HTML Format for message
  118. $reply = "<p>Hello, Thank you for your email.</p><p>I am out of the office today (Friday 06/12/2019), and unable to respond to or action emails. <br /> Should the request be urgent, please call the main line, 0800 000 000.</p><p>Otherwise, I will respond to your email on Monday.</p><p>Many thanks,<br />Username</p>"
  119. Set-MailboxAutoReplyConfiguration -identity [email protected] -InternalMessage $reply -ExternalMessage $reply
  120.  
  121. EMPLOYEE CODE CHECK v1
  122. Import-Module ActiveDirectory
  123. Get-ADUser -searchbase "OU=Standard Users,OU=City REDACTED Users,OU=City REDACTED,DC=cityREDACTED,DC=local" -filter 'description -notlike "*"' -properties * | select name,emailaddress,description | export-csv \\CCMGT05\c$\temp\EmployeeCodeCheck.CSV
  124. #sends email
  125. Send-MailMessage -From [email protected] -To [email protected] -Subject EmployeeCodeCheck -body "This week's Employee Code Check has been exported to \\CCMGT05\C$\Temp" -SmtpServer smtprelay.cityREDACTED.local
  126. #opens the csv in notepad
  127. Invoke-Item C:\Temp\EmployeeCodeCheck.CSV
  128.  
  129. SKYPE HOLIDAY SETS
  130. $a = New-CsRgsHoliday -Name REDACTEDCentralAdminXMas2019 -StartDate "12/20/2019 12:00 PM" -EndDate "01/06/2020 7:30 AM"
  131. New-CsRgsHolidaySet -Parent "ApplicationServer:ccchcsfb01.cityREDACTED.local" -Name "2019 Holidays" -HolidayList ($a)
  132. #note the date format is American (MM/dd/YYYY)
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement