SqlPS and PowerShell with Import-Module SQLPS different behaviors I'm trying to write an automated installation script in powershell for SQL Server Express 2014. I'm stuck with a stupid issue when trying to enable the TCP protocol in the SQL instance.

What I'm doing is the following:

Import-Module "sqlps" -DisableNamechecking

$smo = 'Microsoft.SqlServer.Management.Smo.'
$wmi = new-object ($smo + 'Wmi.ManagedComputer').

# List the object properties, including the instance names.
$Wmi

# Enable the TCP protocol on the default instance.
$uri = "ManagedComputer[@Name='JOHN-PC']/ ServerInstance[@Name='DEMO']/ServerProtocol[@Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp.IsEnabled = $false
$Tcp.Alter()
$Tcp


The issue I have is when I run the script in a standard powershell (run as administrator) the list of instance of my $wmi object is empty.

If I run the same commands (except the first one to load the module) in SqlPS, it works as expected, with my instances being populated correctly.

Unfortunately, I cannot run the whole script in SqlPs, because the script itself installs SQL Server.
This is how I alter TCP to use a specific port including enabling TCP at the end -- You have $Tcp.IsEnabled = $false is that correct?

[system.reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")|Out-Null
$mc = new-object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer .
$Instance = $mc.ServerInstances[$InstanceName]
#Change TCP Port
$TCP = $Instance.ServerProtocols['Tcp']
$AllIps = $TCP.IPAddresses['IPAll']
$AllIps.IPAddressProperties['TcpDynamicPorts'].Value = ''
$AllIps.IPAddressProperties['TcpPort'].Value = $Port
$TCP.IsEnabled = $true  
$TCP.Alter()


so I would do the following

[system.reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")|Out-Null
$mc = new-object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer .
$Instance = $mc.ServerInstances[$InstanceName]
#Enable TCP
$TCP = $Instance.ServerProtocols['Tcp']
$TCP.IsEnabled = $true  ## or false to disable
$TCP.Alter()