Code Snippets Exchange Microsoft PowerShell

Hide Office 365 Groups from the GAL

Schools may require that newly created classes are hidden from the Global Address List (GAL) in Exchange Online. Classes may be hidden through PowerShell. Use the instructions below to hide Classes created with SDS from the GAL.

Classes are represented in Office 365 as Office 365 Groups. In Exchange Online, where the GAL is built, they are called Unified Groups. Use the Get/Set-UnifiedGroup cmdlet to manage these groups through PowerShell.

 

Hide a single class

Launch PowerShell as an Administrator and connect to Exchange Onlineas shown below.

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

Once connected, run the command below against the Group you want to hide.

Set-UnifiedGroup -Identity <UnifiedGroupIdParameter> -HiddenFromAddressListsEnabled $true 

 

Hide all classes created by SDS

Launch PowerShell as an Administrator and connect to Exchange Online as shown below.

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

Once connected, run the command below against all SDS-created groups.

 $Groups = Get-UnifiedGroup -ResultSize Unlimited | ? {$_.PrimarySmtpAddress -like "Section_*"}
Foreach ($Group in $Groups) {Set-UnifiedGroup -Identity $Group.Name -HiddenFromAddressListsEnabled $true}
}

 

 

https://docs.microsoft.com/en-us/schooldatasync/hide-office-365-groups-from-the-gal

Code Snippets SQL Server

Query to list number of records in each table in a database


SELECT SCHEMA_NAME(schema_id) AS [SchemaName],
[Tables].name AS [TableName],
SUM([Partitions].[rows]) AS [TotalRowCount]
FROM sys.tables AS [Tables]
JOIN sys.partitions AS [Partitions]
ON [Tables].[object_id] = [Partitions].[object_id]
AND [Partitions].index_id IN ( 0, 1 )
-- WHERE [Tables].name = N'name of the table'
GROUP BY SCHEMA_NAME(schema_id), [Tables].name;

Exchange Microsoft SSL

Problems with mail flow after changing email certificate

Problems sending email from onpremises to Office 365 accounts in hybrid environment.

 

When configuring a hybrid deployment, you must use and configure certificates that you have purchased from a trusted third-party CA.

 To check if the issue is related to the certificate part, please manually remove the previously created hybrid connectors both in the on-premises Exchange server and Office 365, re-run the HCW (Hybrid Configuration Wizard) to re-create these connectors using the new certificate, then check if the messages can be delivered.

Microsoft Remote Desktop Services RemoteApp Tips & tricks Windows server

Remote App error

Error message:”The computer can’t verify the identity of the RD Gateway. It’s not safe to connect to servers that can’t be identified.”

Are you getting the error code: “The computer computer can’t verify the identity of the RD Gateway. It’s not safe to connect to servers that can’t be identified”? You most likely setup Remote Desktop Web Access (RDweb) with a self signed certificated.

The reason why you are getting this error is your machine doesn’t trust and can’t verify the identity of the RD Gateway.

To allow your machine to trust the RD Gateway and get RD Web Access working you will need to import the Cert from the website and put it into the “Trusted Root Certification Authorities” store

read more »

Code Snippets .NET IIS Microsoft

Register asp.net in IIS 10

run as admin

 
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>dism /online /enable-feature /featurename:IIS-ASPNET45

might need to enable this extensions:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ApplicationDevelopment
C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ISAPIFilter
C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ISAPIExtensions
C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-NetFxExtensibility45

C:\Windows\Microsoft.NET\Framework64\v4.0.30319/dism /online /enable-feature /featurename:IIS-ASPNET45
Code Snippets Active Directory

Using PowerShell To List All Users Password Expiration Date

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

export to csv

 

 get-aduser -filter * -Properties passwordlastset, passwordneverexpires, displayName,Enabled,givenName,sn,distinguishedname,mail,mailnickname,mobile,telephoneNumber,facsimileTelephoneNumber,title | select displayName,passwordlastset, Passwordneverexpires, Enabled,givenName,sn,distinguishedname,mail,mailnickname,mobile,telephoneNumber,facsimileTelephoneNumber,title | export-csv "c:\20190904_ADUsers4.csv" -NoTypeInformation
 

How to Get AD Users Password Expiration Date

Code Snippets Networking

Enable/disable firewall from command line

psexec \\pcname netssh firewall set opmode disable

Get PsTools:
https://docs.microsoft.com/en-us/sysinternals/downloads/pstools

more info:

Enable/disable firewall from command line

Code Snippets .NET ASP.Net

Tamanho máximo de upload asp.net

we.config

<configuration>
  ...
  <system.web>
    ...
    <httpRuntime maxRequestLength="1048576"/>
    ...
  </system.web>
  ...
  </system.webServer>
    ...
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>
    ...
  </system.webServer>
  ...
</configuration>

set to 1 gigabyte

maxAllowedContentLength -> bytes;
maxRequestLength -> kilobytes.

Exchange Microsoft PowerShell

Use the Exchange Management Shell to set up mail forwarding

This example delivers email to the mailbox of Douglas Kohn and, at the same time, forwards all mail sent to Douglas Kohn to douglaskohn.parents@fineartschool.net.

Set-Mailbox -Identity "Douglas Kohn" -DeliverToMailboxAndForward $true -ForwardingSMTPAddress "douglaskohn.parents@fineartschool.net"

This example forwards all email sent to the mailbox of Ken Sanchez, an employee of Contoso Suites, to one of his coworkers, pilarp@contoso.com.

Set-Mailbox -Identity "Ken Sanchez" -ForwardingSMTPAddress "pilarp@contoso.com"
 

For detailed syntax and parameter information, see Set-Mailbox.

Note:
-ForwardingsmtpAddress to multiple addresses Shell script

The parameter “ForwardingSmtpAddress” only allow to setup one SMTP address.
To work around this issue, you can setup the mailbox forwarding to a distribution group, you need to add the users you want to forward message to this distribution group.

link:
https://docs.microsoft.com/en-us/exchange/recipients/user-mailboxes/email-forwarding?view=exchserver-2019

on office365 account, go to portal.office.com > outlook > definitions

 

 

 

REMOVE

Set-Mailbox "email xpto" -ForwardingAddress $NULL -ForwardingSmtpAddress $NULL
Databases SQL Server Tips & tricks Transact-SQL

How to get different SQL Server date formats

Below is a list of formats and an example of the output.  The date used for all of these examples is “2006-12-30 00:38:54.840”.

DATE ONLY FORMATS
Format # Query Sample
1 select convert(varchar, getdate(), 1) 12/30/06
2 select convert(varchar, getdate(), 2) 06.12.30
3 select convert(varchar, getdate(), 3) 30/12/06
4 select convert(varchar, getdate(), 4) 30.12.06
5 select convert(varchar, getdate(), 5) 30-12-06
6 select convert(varchar, getdate(), 6) 30 Dec 06
7 select convert(varchar, getdate(), 7) Dec 30, 06
10 select convert(varchar, getdate(), 10) 12-30-06
11 select convert(varchar, getdate(), 11) 06/12/30
12 select convert(varchar, getdate(), 12) 061230
23 select convert(varchar, getdate(), 23) 2006-12-30
101 select convert(varchar, getdate(), 101) 12/30/2006
102 select convert(varchar, getdate(), 102) 2006.12.30
103 select convert(varchar, getdate(), 103) 30/12/2006
104 select convert(varchar, getdate(), 104) 30.12.2006
105 select convert(varchar, getdate(), 105) 30-12-2006
106 select convert(varchar, getdate(), 106) 30 Dec 2006
107 select convert(varchar, getdate(), 107) Dec 30, 2006
110 select convert(varchar, getdate(), 110) 12-30-2006
111 select convert(varchar, getdate(), 111) 2006/12/30
112 select convert(varchar, getdate(), 112) 20061230
TIME ONLY FORMATS
8 select convert(varchar, getdate(), 8) 00:38:54
14 select convert(varchar, getdate(), 14) 00:38:54:840
24 select convert(varchar, getdate(), 24) 00:38:54
108 select convert(varchar, getdate(), 108) 00:38:54
114 select convert(varchar, getdate(), 114) 00:38:54:840
DATE & TIME FORMATS
0 select convert(varchar, getdate(), 0) Dec 12 2006 12:38AM
9 select convert(varchar, getdate(), 9) Dec 30 2006 12:38:54:840AM
13 select convert(varchar, getdate(), 13) 30 Dec 2006 00:38:54:840AM
20 select convert(varchar, getdate(), 20) 2006-12-30 00:38:54
21 select convert(varchar, getdate(), 21) 2006-12-30 00:38:54.840
22 select convert(varchar, getdate(), 22) 12/30/06 12:38:54 AM
25 select convert(varchar, getdate(), 25) 2006-12-30 00:38:54.840
100 select convert(varchar, getdate(), 100) Dec 30 2006 12:38AM
109 select convert(varchar, getdate(), 109) Dec 30 2006 12:38:54:840AM
113 select convert(varchar, getdate(), 113) 30 Dec 2006 00:38:54:840
120 select convert(varchar, getdate(), 120) 2006-12-30 00:38:54
121 select convert(varchar, getdate(), 121) 2006-12-30 00:38:54.840
126 select convert(varchar, getdate(), 126) 2006-12-30T00:38:54.840
127 select convert(varchar, getdate(), 127) 2006-12-30T00:38:54.840
FORMATS WITH ISSUES
130 select convert(varchar, getdate(), 130) 10 ?? ????? 1427 12:38:54:840A
131 select convert(varchar, getdate(), 131) 10/12/1427 12:38:54:840AM

You can also format the date or time without dividing characters, as well as concatenate the date and time string:

Sample statement Output
select replace(convert(varchar, getdate(),101),’/’,”) 12302006
select replace(convert(varchar, getdate(),101),’/’,”) + replace(convert(varchar, getdate(),108),’:’,”) 12302006004426

read more »