0
votes

I am installing some MSI package in a powershell script like that :

Start-Process "Msi_Path" /qn -Wait

these MSI package are :

SQLSysClrTypes.msi,SharedManagementObjects.msi,PowerShellTools.msi (For SQL Server 2012)

In the same script, after installation, I am trying to import the SqlPs module like that :

Import-Module SqlPs -DisableNameChecking

But I got this error :

The specified module 'SQLPS' was not loaded becuase no valid file was found in any module directory.

When I open a new PowerShell windows and import the module it's works. I tried to start a new PowerShell process in my script like that :

Start-Process 'powershell' 'secondScript.ps1' #with Import-Module SqlPs

But I got the same error.

Did you have any idea or work around ?

Thank you.

1
Have you tried calling Start-Process with -UseNewEnvironment? Module paths are defined in environment variables which are not changed while the process is running. I believe Start-Process uses the parent process's environment by default.Mike Zboray

1 Answers

0
votes

Thank you mike z,

I found an other work around, I'm using the Invoke-Command (http://technet.microsoft.com/en-us/library/hh849719.aspx)

With this way, I can perform all actions in the same PowerShell script.