Try
$winRM = Get-Service -Name winrm
If ($winRM.Status -ne "Running") {Start-Service -Name winrm}
Set-ExecutionPolicy Bypass -Force
Enable-PSRemoting -Force
Enable-WSManCredSSP -Role Server -Force | Out-Null
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024
$winRM = Get-Service -Name winrm
If ($winRM.Status -ne "Running") {Start-Service -Name winrm}
Set-ExecutionPolicy Bypass -Force
Enable-PSRemoting -Force
Enable-WSManCredSSP -Role Server -Force | Out-Null
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024