systemcentercommunity
Your community resource for Microsoft's System Center family of products

Powershell question, Set-Location cannot find provider

Latest post 10-14-2008 2:51 AM by Silverfoxs. 0 replies.
  • 10-14-2008 2:51 AM

    Powershell question, Set-Location cannot find provider

    hi, Guys:

    I am trying to use a schedule maintenance script in powershell.

    If the script run in powershell of SCOM, that's fine.

    But once I use command of windows to run

    powershell c:\mps\putmaint2.ps1 "server1" 2

    I got following error:

    Set-Location : Cannot find a provider with name 'OperationsManagerMonitoring'.
    At C:\mps\putmaint2.ps1:10 char:13
    + Set-Location  <<<< "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
    The term 'Get-Agent' is not recognized as a cmdlet, function, operable program,
     or script file. Verify the term and try again.
    At C:\mps\putmaint2.ps1:17 char:23
    + $computer  = Get-Agent  <<<< | Where-object {$_.PrincipalName -eq $computerPr
    incipalName}
    The term 'get-monitoringclass' is not recognized as a cmdlet, function, operabl
    e program, or script file. Verify the term and try again.
    At C:\mps\putmaint2.ps1:19 char:49
    + $healthServiceWatcherClass = get-monitoringclass  <<<< -name:Microsoft.System
    Center.HealthServiceWatcher
    The term 'get-monitoringobject' is not recognized as a cmdlet, function, operab
    le program, or script file. Verify the term and try again.
    At C:\mps\putmaint2.ps1:21 char:45
    + $healthServiceWatcher = get-monitoringobject  <<<< -monitoringclass:$healthSe
    rviceWatcherClass -criteria:$healthServiceCriteria

     

     

    It seems to me I need to preset Powershell environment. But Set-Location command can't find provider. Any idea?

    I checked the powershell shortcut and find following :

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Console.psc1 -NoExit .\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1

    That's how scom setup it's own environment. But I can't do this since I plan to use Task Schedule to run the script.

    Please help. Thanks

     

    Part of script is following...

    -------------------------------------------------------------------------------------------

    param($computerName,$numberOfHoursInMaintenanceMode,$comment)
    $computerPrincipalName = $computerName + ".agriprod.ridley.com.au"
    $comment = "Maintenanced by IS Team"

    #You only need to do this next line once if you haven’t done so already and this is meant to add the Snapin for SCOM to your regular PowerShell console#Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;

    $rootMS = "scom"
    Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;

    #Set-Location "Monitoring:\doncamgt04.agriprod.ridley.com.au" -ErrorVariable errSnapin;
    #new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;

    #set-location $rootMS -ErrorVariable errSnapin;

    $computer  = Get-Agent | Where-object {$_.PrincipalName –eq $computerPrincipalName}

     

    Filed under:
Page 1 of 1 (1 items) | RSS
Copyright @ 2008 Silect Software Inc.
Powered by Community Server (Commercial Edition), by Telligent Systems