Answered by:
How to import management pack with powershell

Question
-
I am creating installer for management pack. Last step is importing of MP.
Here is my script:
param ($Filepath) $rootMS="localhost" add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"; set-location "OperationsManagerMonitoring::"; new-managementGroupConnection -ConnectionString:$rootMS; install-managementpack -filepath $filepath
The problem is in script starting.
powershell.exe 'c:\program files\my managementpack\my powershell script.ps1' 'c:\program files\my managementpack\my mp.mp'
does not work
powershell.exe "c:\program files\my managementpack\my powershell script.ps1" "c:\program files\my managementpack\my mp.mp"
does not work too.
What is the correct syntax?Wednesday, August 26, 2009 8:38 AM
Answers
-
Sorry about that
powershell -command "& 'c:\program files\my managementpack\my powershell script.ps1'" 'c:\program files\my managementpack\my mp.mp'- Proposed as answer by S. Halsey Thursday, August 27, 2009 6:05 PM
- Marked as answer by Maxim BugriyMicrosoft employee Friday, August 28, 2009 7:07 AM
- Unmarked as answer by Maxim BugriyMicrosoft employee Tuesday, September 1, 2009 2:27 PM
- Marked as answer by Maxim BugriyMicrosoft employee Tuesday, September 1, 2009 3:32 PM
Thursday, August 27, 2009 5:13 PM
All replies
-
Try
Install-ManagementPack -filepath "$($filepath)"Wednesday, August 26, 2009 3:16 PM -
You mean in script?
And how shoul I execute this script?
this way:
powershell.exe "c:\program files\my managementpack\my powershell script.ps1" "c:\program files\my managementpack\my mp.mp"
or this:
powershell.exe 'c:\program files\my managementpack\my powershell script.ps1' 'c:\program files\my managementpack\my mp.mp'Wednesday, August 26, 2009 3:26 PM -
powershell.exe "c:\program files\my managementpack\my powershell script.ps1" 'c:\program files\my managementpack\my mp.mp'
- Proposed as answer by S. Halsey Wednesday, August 26, 2009 5:32 PM
- Unproposed as answer by Maxim BugriyMicrosoft employee Thursday, August 27, 2009 5:39 AM
Wednesday, August 26, 2009 3:30 PM -
It does not work.
>powershell "c:\program files\my managementpack\my powershell script.ps1" 'c:\program files\my managementpack\my mp.mp'
The term c:\program' 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.
At line:1 char:7
+ c:\program <<<< files\my managementpack\my powershell script.ps1 'c:\program files\my managementpack\my mp.mp' + CategoryInfo : ObjectNotFound: (D:\for:String) [], CommandNotFo
undException
+ FullyQualifiedErrorId : CommandNotFoundExceptionThursday, August 27, 2009 5:39 AM -
Sorry about that
powershell -command "& 'c:\program files\my managementpack\my powershell script.ps1'" 'c:\program files\my managementpack\my mp.mp'- Proposed as answer by S. Halsey Thursday, August 27, 2009 6:05 PM
- Marked as answer by Maxim BugriyMicrosoft employee Friday, August 28, 2009 7:07 AM
- Unmarked as answer by Maxim BugriyMicrosoft employee Tuesday, September 1, 2009 2:27 PM
- Marked as answer by Maxim BugriyMicrosoft employee Tuesday, September 1, 2009 3:32 PM
Thursday, August 27, 2009 5:13 PM -
Thank you, Mike. It works. Can you give me advice, where can I read about such powershell syntax things - -command, &, ", ', etc?Friday, August 28, 2009 7:08 AM
-
I'm afraid I don't have any sources to recommend. It's a lot of web searching for me. :-(
Friday, August 28, 2009 4:54 PM -
It works in windows x86, but it does not work in windows x64. My installer (inno setup) is x86, so when it executes powershell.exe with parameters the problem begins.
Here is a string from installer:
Filename: "powershell.exe"; WorkingDir: "{tmp}"; Parameters: "-command ""& '{tmp}\install-MP.ps1'"" '{tmp}\MyMP.mp'"; StatusMsg: "Importing Management Pack. Please wait, this operation can take up to several minutes."; Flags: waituntilterminated runhidden
Here is an output from powershell:
Add-PSSnapin : No Windows PowerShell Snap-ins are available for version 1.
At C:\Users\SCOM-S~1\AppData\Local\Temp\2\is-R61LK.tmp\install-MP.ps1:3 char:13
+ add-pssnapin <<<< "Microsoft.EnterpriseManagement.OperationsManager.Client";
Set-Location : Cannot find a provider with name 'OperationsManagerMonitoring'.
At C:\Users\SCOM-S~1\AppData\Local\Temp\2\is-R61LK.tmp\install-MP.ps1:4 char:13
+ set-location <<<< "OperationsManagerMonitoring::";
The term 'new-managementGroupConnection' is not recognized as a cmdlet, functio
n, operable program, or script file. Verify the term and try again.
At C:\Users\SCOM-S~1\AppData\Local\Temp\2\is-R61LK.tmp\install-MP.ps1:5 char:30
+ new-managementGroupConnection <<<< -ConnectionString:$rootMS;
The term 'install-managementpack' is not recognized as a cmdlet, function, oper
able program, or script file. Verify the term and try again.
At C:\Users\SCOM-S~1\AppData\Local\Temp\2\is-R61LK.tmp\install-MP.ps1:6 char:23
+ install-managementpack <<<< -filepath "$($filepath)
I tried this, but it did not help:
Filename: "{syswow64}\WindowsPowerShell\v1.0\powershell.exe"; WorkingDir: "{tmp}"; Parameters: "-command ""& '{tmp}\install-MP.ps1'"" '{tmp}\MyMP.mp'"; StatusMsg: "Importing Management Pack. Please wait, this operation can take up to several minutes."; Flags: waituntilterminated
I think I've found a decision. http://blogs.msdn.com/mstehle/archive/2007/01/24/kb-preview-error-no-windows-powershell-snap-ins-when-loading-exchange-powershell-snap-in.aspxTuesday, September 1, 2009 2:27 PM