Posts tagged ‘Powershell’

Start Azure Automation runbook from powershell

With the new Azure Automation cmdlets I wrote about in the previous post we are now able to start runbooks from outside of Azure.
Here is an example how to start a runbook and also get the output from the runbook:

$AzureAccount = "Name of Azure Automation Account"
$RBname = "Name of runbook to start"
$Params = @{"Param1" = "Value1";"Param2" = "Value2"}

$RBjob = Start-AzureAutomationRunbook -AutomationAccountName $AzureAccount -name $RBname -Parameters $Params

DO {
    $RBjobId = Get-AzureAutomationJob -AutomationAccountName $AzureAccount -id $RBjob.Id
    $RBjobstatus = $RBjobId.Status
    } Until ($RBjobstatus -eq "Completed")

Get-AzureAutomationJobOutput -AutomationAccountName $AzureAccount -Id $RBjob.Id -stream Any

Azure Automation Powershell cmdlets

With the Azure Tool kit being updated last week we got a couple of cmdlets for Azure Automation, so now we are able to start, stop get jobs and so on from our runbooks in Azure Automation from on-premises.

Here are the new cmdlets:

To download the updated powershell module go here: http://azure.microsoft.com/en-us/downloads/

For reference on the new cmdlets, go here: http://msdn.microsoft.com/en-us/library/dn690262.aspx

Using Powershell in Orchestrator

Create subscribers from .CSV

Here is a small powershell script for creating multiple subscribers from a CSV-file.

Your file should look like this:

"Name","Email","SMS","IM"
"Marsellus Wallace","marsellus.wallace@opsmode.com","12345678","marsellusw"

And the code looks like this:

$NotificationSubscribers = Import-Csv "D:\temp\SCOMNotificationSubscribers.csv"

foreach($NotificationSubscriber in $NotificationSubscribers)
{
$Name = $NotificationSubscriber.Name
$eMail = $NotificationSubscriber.Email
$SMS = $NotificationSubscriber.SMS
$IM = $NotificationSubscriber.IM

Add-SCOMNotificationSubscriber -Name $Name -DeviceList $eMail,"sms:$SMS","sip:$IM"
}

Web Console prerequisites, OpsMgr 2012

When installing the Web Console there is a couple of components that is required, the Operations Manager 2012 Supported Configuration (http://technet.microsoft.com/en-us/library/hh205990.aspx) list these:

  • Recommended processor speed: 2.8 GHz or faster.
  • Minimum memory: not less than 2 GB.
  • Operating System: Windows Server 2008 R2
  • Processor Architecture: must be AMD64
  • Internet Information Services (IIS) v7.5 or later, with the IIS Management Console and the following role services installed:
    • Static Content
    • Default Document
    • Directory Browsing
    • HTTP Errors
    • HTTP Logging
    • Request Monitor
    • Request Filtering
    • Static Content Compression
    • Web Server (IIS) Support
    • IIS 6 Metabase Compatibility
    • ASP.NET
    • Windows Authentication
  • Default website: must have an http or https binding configured
  • Both .NET Framework 3.5 SP1 and .NET Framework 4 is required for setup to run. For more information, see the following.

 

The role services is easily installed with powershell, which makes it a little quicker then using Server Manager GUI:

Import-Module ServerManager
Add-WindowsFeature NET-Framework-Core,Web-WebServer,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-Asp-Net,Web-Http-Logging,Web-Request-Monitor,Web-Windows-Auth,Web-Filtering,Web-Stat-Compression,Web-Mgmt-Console,Web-Metabase

As you might see I’ve also added NET-Framework-Core  (.NET Framework 3.5.1) there as well.

When the IIS install is ready you should install .NET Framework 4. (http://www.microsoft.com/download/en/details.aspx?id=17851)

If you installed .NET Framework 4 before installing the IIS you’ll get an error:

The ASP.NET 4.0 handler is not registered with IIS.
The ASP.NET 4.0 handler is not registered with IIS 

To fix this, the Operations Manager 2012 Deployment document states that you should run:

%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -r

I suggest that that you add the -enable option (%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -enable -r), that enables the ASP.NET ISAPI extension. And gets rid of this prerequisites error:

Web Console cannot operate properly because the ISAPI and CGI Restrictions in Internet Information Services (IIS) are disabled or missing for ASP.NET 4.0.
Web Console cannot operate properly because the ISAPI and CGI Restrictions in Internet Information Services (IIS) are disabled or missing for ASP.NET 4.0.

Lastly do a restart of the server before running the setup again.

Scheduling OpsMgr PowerShell scripts

When scheduling an Operations Manager PowerShell script you have to load the powershell snapins.

Insert this in the beginning of your script

$ServerName = “hostname”
add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;
set-location “OperationsManagerMonitoring::”;
new-managementGroupConnection -ConnectionString:$ServerName;
set-location $ServerName;

PowerShell: List agent based on setting

Based on the data you get from the cmdlet get-agent you can list all agents with a specific setting.

This line for example, will list all agents with the Agent Proxy setting enabled:
get-agent | where {$_.ProxyingEnabled -like $true}

Change $_.ProxyingEnabled to $_.ManuallyInstalled and you’ll get a list with all manually installed agents.

In OM2007 SP1 there is a bug on updating the ManuallyInstalled property, so that wont work. This is corrected in R2.
If you dont have to use powershell there is a workaround in this thread.

 
Your options are:
PrimaryManagementServerName
Id
LastModified
Name
DisplayName
HostComputer
HostedHealthService
HealthState
PrincipalName
NetworkName
ComputerName
Domain
IPAddress
Version
RequestCompression
CommunicationPort
MaximumSizeOfAllTransferredFilesBytes
MaximumQueueSizeBytes
ManuallyInstalled
InstallTime
InstalledBy
CreateListener
AuthenticationName
ActionAccountIdentity
HeartbeatInterval
ProxyingEnabled
ManagementGroup
ManagementGroupId