Search code examples
powershellpowershell-3.0sqlps

PowerShell Installing additional tools and use cmdlets installed


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.


Solution

  • 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.