Fixing PowerShell profile to work in Nano Server

17 May 2015

The new Windows Server Nano deployment option comes with a new version of PowerShell, PowerShell core. Not all the normal features are implemented.

I make heavy use of profiles, I set up over a hundred functions and aliases to make work on Windows easier for me.

I started tested Nano Server with the Technical Preview 2 released to web in May 2015. I got several errors. Here I describe how to fix them.

Remember that in a remote PowerShell session, no profiles are loaded automatically, one way around is to register a profile:

Register-PSSessionConfiguration -Name WithProfile -StartupScript C:\bin\etc\posh-link.ps1
then use the profile when entering the session:
Enter-PSSession -ComputerName server1 -Credential server1\administrator -ConfigurationName WithProfile

First problem:
Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I replaced
Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2
with:
Get-CimInstance -ClassName Win32_OperatingSystem -Namespace root/cimv2
Next whoami is not available:
whoami : The term 'whoami' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I replaced the call to whoami with some other code.

Next problem

Cannot find an overload for "GetEnvironmentVariable" and the argument count: "2".
At @([Environment]::GetEnvironmentVariable("path", "Machine")  ...
Here I just used $env:Path.

The last one:

Add-Type : The term 'Add-Type' is not recognized as the name of a cmdlet, function, script file, or operable program.
For now I don't use that bit when on a Nano Server, one way to check is:
  if (!(Test-Path "$env:SystemRoot\regedit.exe")) { $OsIsNano = $true }...
regedit.exe does exist in all other Windows versions including server core.

Pages in this section

Categories

ASP.Net | Community | Development | IIS | IT Pro | Security | SQL (Server) | Tools | Web | Work on the road | Windows