My Blog List

Tuesday, July 26, 2022

Exchange

 



#List DL details  

Get-DistributionGroupMember -Identity BA-EV_Journaling@testdomain.com | Select DisplayName, samAccountname, RecipientTypeDetails | Export-Csv -Path C:\Temp\BA-EV_journal.csv


#Add multiple users to exchange DL using .csv(name = email)

Import-CSV FileName.csv | ForEach {Add-DistributionGroupMember -Identity "GROUP-NAME" -Member $_.Name}


#View the move history for a mailbox using Get-MailboxStatistics and the -IncludeMoveHistory switch

(Get-MailboxStatistics alan.reid -IncludeMoveHistory).MoveHistory | select CompletionTimestamp,SourceDatabase,TargetDatabase | ft -auto


#Find ExchangeDB of a mailbox

Get-Mailbox -Identity MelbourneLending | select name, database


get-mailbox -ResultSize unlimited | where {$_.emailaddresses -like "*testdomain.com"} | Select name, primarysmtpaddress, Emailaddresses | Export-Csv C:\Temp\emailaliases.csv


#Get mailbox details from email address

Import-CSV C:\sj\emails.csv | foreach {Get-Mailbox -Identity $_.Email} | Select Name, RecipientTypeDetails,enabled | Export-Csv -Path C:\Temp\Emails.csv -NTI


Get-ThrottlingPolicy -Identity ATFSPolicy | fl


#Use powershell on the on-premise Exchange:

Remove-remotemailbox –identity testdelt@domain.com


#create new shared mailbox

New-RemoteMailbox -Shared -Name "BA SQL Prod Alerts" -Firstname "BA SQL" -LastName "Prod Alerts" -UserPrincipalName "BASql.ProdAlerts@testdomain.com" -OnPremisesOrganizationalUnit "OU=Shared,OU=Resources,OU=Production,DC=members,DC=com"


#create new mailbox

New-RemoteMailbox -Name "IT SDPDEV" -Firstname "IT" -LastName "SDPDEV" -UserPrincipalName "IT.SDPDEV@testdomain.com" -OnPremisesOrganizationalUnit "OU=Fullmbx,OU=Resources,OU=Production,DC=members,DC=com"


#get recently created mailboxes

Get-Mailbox | Where-Object {$_.WhenCreated –ge ((Get-Date).Adddays(-14))}


#book a meeting room for an invite that has been sent to me

Get-Mailbox "ourroom" | Get-CalendarProcessing |select ProcessExternalMeetingMessages

ProcessExternalMeetingMessages

------------------------------

False

PS> Get-Mailbox "ourroom" | Set-CalendarProcessing -ProcessExternalMeetingMessages $True

PS> Get-Mailbox "ourroom" | Get-CalendarProcessing |select ProcessExternalMeetingMessages

ProcessExternalMeetingMessages

------------------------------

True

#How to Add Remote IP Addresses to Existing Receive Connector

To add a single IP address to an existing Receive Connector:

[PS] C:\>$RecvConn = Get-ReceiveConnector "Relay Connector"
[PS] C:\>$RecvConn.RemoteIPRanges += "10.0.0.99"
[PS] C:\>Set-ReceiveConnector "Relay Connector" -RemoteIPRanges $RecvConn.RemoteIPRanges

Now we can see that 10.0.0.99 has been added to the Receive Connector.

[PS] C:\>Get-ReceiveConnector "Relay Connector" | fl remoteipranges

RemoteIPRanges : {10.0.0.99, 10.0.0.23, 10.0.0.22, 10.0.0.21, 10.0.0.1, 10.0.0.2, 10.0.0.3, 10.0.0.11, 10.0.0.12, 10.0.
                 0.13, 10.0.0.4, 10.0.0.5, 10.0.0.6, 10.0.0.7, 10.0.0.8, 10.0.0.9, 10.0.0.10, 10.0.0.15, 10.0.0.16, 10.
                 0.0.17, 10.0.0.18, 10.0.0.19, 10.0.0.20, 10.0.0.14}

To add multiple IP addresses at once use this command sequence:

[PS] C:\>$RecvConn = Get-ReceiveConnector "Relay Connector"
[PS] C:\>$RecvConn.RemoteIPRanges += "10.0.0.99", "10.0.0.100", "10.0.0.101"
[PS] C:\>Set-ReceiveConnector "Relay Connector" -RemoteIPRanges $RecvConn.RemoteIPRanges

Sometimes the list of IPs being added is too long to type out. To add multiple IP addresses from a text file called newips.txt use this command sequence instead:

[PS] C:\>$RecvConn = Get-ReceiveConnector "Relay Connector"
[PS] C:\>Get-Content .\newips.txt | foreach {$RecvConn.RemoteIPRanges += "$_"}
[PS] C:\>Set-ReceiveConnector "Relay Connector" -RemoteIPRanges $RecvConn.RemoteIPRanges

Wednesday, July 20, 2022

MsolService commands

 #Connect to MsolService

Connect-MsolService

Get-MsolUser -UserPrincipalName affinity_dev@bankaust.com.au  | fl

Get-MsolUser -All | Where {$_.BlockCredential -eq $True} | Select DisplayName,UserPrincipalName,BlockCredential,IsLicensed | Export-Csv C:\temp\Blocked_0365.csv

Get-MsolUser -UserPrincipalName sahan.Jayarathna@bankaust.com.au | fl

Get License details of Azure AD User

Get-MsolUser -UserPrincipalName Alyssa.Roylance@bankaust.com.au | Select UserPrincipalName, Licenses

#get licnese based on user

Get-MsolUser -UserPrincipalName Aman.Nisar@bankaust.com.au | fl

#get all licenses in tenancy 

Get-MsolAccountSku


#get users with a license type

Get-MsolUser -All| Where-Object {($_.licenses).AccountSkuId -match "DYN365_ENTERPRISE_SALES"} | Select UserPrincipalName,DisplayName,BlockCredential | Export-Csv C:\Work\Projects\d365es.csv


#DYN365_ENTERPRISE_CUSTOMER_SERVICE - Dynamics 365 Customer Service Enterprise

#D365_CUSTOMER_SERVICE_ENT_ATTACH - Dynamics 365 Customer Service Enterprise Attach to Qualifying Dynamics 365 Base Offer

#DYN365_TEAM_MEMBERS  - Dynamics 365 Team Members

#DYN365_ENTERPRISE_SALES  - Dynamics 365 Sales Enterprise Edition

O365 Commands

 Install-Module MSOnline

Install-Module ExchangeOnlineManagement


#Connect to MS Online

Connect-MsolService

Get-MsolUser -UserPrincipalName affinity_dev@bankaust.com.au  | fl

Get-MsolUser -All | Where {$_.BlockCredential -eq $True} | Select DisplayName,UserPrincipalName,BlockCredential,IsLicensed | Export-Csv C:\temp\Blocked_0365.csv

Get-MsolUser -UserPrincipalName sahan.Jayarathna@bankaust.com.au | fl

Get License details of Azure AD User

Get-MsolUser -UserPrincipalName Alyssa.Roylance@bankaust.com.au | Select UserPrincipalName, Licenses

#get licnese based on user

Get-MsolUser -UserPrincipalName Aman.Nisar@bankaust.com.au | fl

#get all licenses in tenancy 

Get-MsolAccountSku


#get users with a license type

Get-MsolUser -All| Where-Object {($_.licenses).AccountSkuId -match "DYN365_ENTERPRISE_SALES"} | Select UserPrincipalName,DisplayName,BlockCredential | Export-Csv C:\Work\Projects\d365es.csv


#DYN365_ENTERPRISE_CUSTOMER_SERVICE - Dynamics 365 Customer Service Enterprise

#D365_CUSTOMER_SERVICE_ENT_ATTACH - Dynamics 365 Customer Service Enterprise Attach to Qualifying Dynamics 365 Base Offer

#DYN365_TEAM_MEMBERS  - Dynamics 365 Team Members

#DYN365_ENTERPRISE_SALES  - Dynamics 365 Sales Enterprise Edition

1. Connect to exchnage online

Import-Module ExchangeOnlineManagement

Connect-ExchangeOnline


2. Turn litigation hold on indefinitly

Set-Mailbox Sian.Sewell@bankaust.com.au -LitigationHoldEnabled $true


3. Get-MailboxFolderPermission -Identity WestEndStaff.AnnualLeave@bankaust.com.au:\calendar


4. Add-MailboxFolderPermission -Identity WestEndStaff.AnnualLeave@bankaust.com.au:\calendar -User Lisa.Heard@bankaust.com.au -AccessRights Editor


5. Convert mailboxes in .csv to shared mailboxes

Import-Csv C:\PS\O365\License2132022.csv |  foreach {Get-Mailbox -Identity $_.Email | Where-Object {$_.RecipientTypeDetails -eq "UserMailbox"} | Set-Mailbox -Type Shared}


6. Verify that all the user mailbox is converted to type shared mailbox.

Import-Csv C:\PS\O365\License2132022.csv | foreach {Get-Mailbox -Identity $_.Email} | ft Name, RecipientTypeDetails

7. Check Dmarc config 

Get-DkimSigningConfig -Identity bankaust.com.au | Format-List

8. Test-ApplicationAccessPolicy -Identity svc_veeam@bankaust.onmicrosoft.com -AppId d1c08c34-bc6c-4f1d-b809-0b8c11868824


Daily commands

 

1. #Check installed windows updates:  

wmic qfe

2. PS H:\> Get-FileHash C:\Excel\NSClient.msi -Algorithm MD5          


3. #get installed software on a machine(cmd)

Wmic product get name, version, vendor

4. # remote connect to a PC via Powershell 

Enter-PSSession -ComputerName BA-L156YBD

5. #remote cmd

psexec \\RemoteComputer cmd.exe

6. #uninstall GPL Ghost script

"%ProgramFiles%\gs\gs9.27\uninstgs.exe" /S

7. #install CW over cmd remote

msiexec.exe /i "c:\intel\Agent_Install.MSI" ALLUSERS=1 /qn /norestart /log output.log

8. #get running services

Net start

9. #Enable Remote Desktop connections

Set-ItemProperty ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\‘ -Name “fDenyTSConnections” -Value 0

10. #Enable Network Level Authentication

Set-ItemProperty ‘HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\‘ -Name “UserAuthentication” -Value 1

11. #Enable Windows firewall rules to allow incoming RDP

Enable-NetFirewallRule -DisplayGroup “Remote Desktop”

12. #enable Win10 firewall for RDP remotely

psexec.exe \\<computer name> netsh firewall set service RemoteDesktop enable

13. #Find active sessions citrix

query user

Logoff ID

14. #check windows update cmd

wuauclt.exe /updatenow

15. #get last login date 

Get-ADComputer -Identity BA-CAN-TELLER02 -Properties LastLogonDate  


Get-ADComputer -filter {operatingsystem -like "Windows 10*"  } -Properties OperatingSystemVersion, lastlogondate|select name,OperatingSystemVersion,LastLogonDate

16. #Registry Lookup

Some swear by looking things up in the registry. Not my recommended approach - I like going through proper APIs (or in other words: OS function calls). There are always weird exceptions accounted for only by the internals of the API-implementation:

• HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

• HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

• HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall


17. #NS uninstall

c:\Intel>msiexec /x "NSClient v83.0.0.538.msi" /quiet /norestart


18. #NS Uninstall String

MsiExec.exe /I{FA933B0A-816B-4001-915F-8F2625B8E1A8}


19. #create firewall rule to enable default sql services

New-NetFirewallRule -DisplayName "SQLServer default instance" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow

New-NetFirewallRule -DisplayName "SQLServer Browser service" -Direction Inbound -LocalPort 1434 -Protocol UDP -Action Allow


20. #install .msp file 

msiexec /p C:\Windows\LTSvc\packages\lync2016-kb4475545x86\lync-x-none.msp REINSTALL=ALL REINSTALLMODE=omus /qn


https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec


21. #messageLabs

top left > Address Registration > choose domain bankaust.com.au > add New Address


22. #Change UPN

Set-ADUser -UserPrincipalName test01@test.local -Identity it.servicedeskdev

23. #uninstall Silverlight 

wmic product where caption='Microsoft Silverlight' call uninstall


24. #Robocopy 

Robocopy "\\ba-pqhyp01\d$\Shared" "C:\Hype" /copyall /s /zb /tee 


25. #Get AD users filtered by name

get-aduser -Filter 'Name -like "*sql*"' | select name, samaccountname


26. #Get AD permissions on an OU

(Get-ACL "AD:$((Get-ADOrganizationalUnit -Identity 'OU=HR,DC=SHELLPRO,DC=LOCAL').distinguishedname)").access | Select IdentityReference,AccessControlType

#array

$array = Import-Csv -Path C:\AH\AD\Empty_pass_usernames.csv

foreach($name in $array){

  Get-ADUser -Identity $name.username -Properties useraccountcontrol | Select Samaccountname, useraccountcontrol, Enabled } 

27. #change useraccountcontrol value to 512

$array = Import-Csv -Path C:\AH\AD\Empty-pass-turn512.csv

foreach($name in $array){

  Set-ADUser -Identity $name.username -Replace @{useraccountcontrol=512}

}







Steps to extract ntfs share details from file server shares

As part of a file server consolidation effort, I was tasked to come up with a method to move multiple shares on multiple shares to a WSFC. I...