Q:

Set SQL Server 'Maximum server memory in (MB)' using Powershell

I'm currently automating a VM and using a Powershell script to install SQL Server 2017.
I need to be able to script the Maximum server memory as well. Is this possible through the current configuration settings or will I need to create a custom script? If a custom script is required what would I need to do.

A:

You could use SQL (run from Powershell):
sp_configure 'show advanced options', 1;  
RECONFIGURE;  
sp_configure 'max server memory', 4096;  
RECONFIGURE;  

or use PowerShell cmdlet from dbatools.io:

Set-DbaMaxMemory
explicitly set the max memory to 2048 MB on just one server, “sqlserver1”
Set-DbaMaxMemory -SqlServer sqlserver1 -MaxMb 2048 

