Monday, March 5, 2018

Operations management suite workspaces for Azure gov do not show up in SCOM

The default workspaces that you can connect to in SCOM are tied to Azure commercial.





After logging to the Azure account you will not see the workspaces you have created in the Azure government cloud. 

If you want to connect to an Azure Gov workspace download the respective mp's.
 


These are sealed management packs so you will have to delete the existing  ones before importing these.

 
Once done though,you shall see the dropdown for Azure Gov. After which you can login and the workspaces should show up.


Thursday, December 14, 2017

Executing powershell scripts in C#

To execute powershell scritps in C#

https://www.codeproject.com/articles/18229/how-to-run-powershell-scripts-from-c


And this one just for fun.


Wednesday, November 29, 2017

Community Vmware management pack for vmware sphere 6.0

Mitch Luedy has created a very good management pack for monitoring VMware. He also was gracious enough to make it available to everyone for free.

Link to his github repository of the entire solution is here.

https://github.com/Mitch-Luedy/Community.VMware

This management pack uses PsSnapins in the powershell scripts. And vmware has ceased the use of snapins from 6.0.

 I have modified the scripts to use modules and this management pack will work on vsphere 6.0 now.

Link to that repository is here.

https://github.com/paragwaghmare/Community-Vmware

 


Friday, November 17, 2017

Orchestrator fails to import 64 bit powershell modules. Cmdlets do not work.

  1. Orchestrator spawns processed in 32bit powershell. So if you use any activity that uses 64bit powershell modules. Those modules fail to load.
To overcome this encapsulate your script in the following lines.

C:\Windows\Sysnative\WindowsPowershell\v1.0\Powershell.exe -NonInteractive -Command {
###Enter your script here###

}
 
   2. You can also use the script from the following link. This will need windows remote management to be enabled.And the account being used to be added to Remote Management Users Group.
 
https://social.technet.microsoft.com/wiki/contents/articles/30721.powershell-system-center-orchestrator-best-practice-template.aspx 
 
# Set script parameters from runbook data bus and Orchestrator global variables
# Define any inputs here and then add to the $argsArray and script block parameters below 

$DataBusInput1 = "{Parameter 1 from Initialize Data}"
$DataBusInput2 = "{Global Variable 1}"


#-----------------------------------------------------------------------

## Initialize result and trace variables
# $ResultStatus provides basic success/failed indicator
# $ErrorMessage captures any error text generated by script
# $Trace is used to record a running log of actions
$ResultStatus = ""
$ErrorMessage = ""
$Trace = (Get-Date).ToString() + "`t" + "Runbook activity script started" + " `r`n"
       
# Create argument array for passing data bus inputs to the external script session
$argsArray = @()
$argsArray += $DataBusInput1
$argsArray += $DataBusInput2

# Establish an external session (to localhost) to ensure 64bit PowerShell runtime using the latest version of PowerShell installed on the runbook server
# Use this session to perform all work to ensure latest PowerShell features and behavior available
$Session = New-PSSession -ComputerName localhost

# Invoke-Command used to start the script in the external session. Variables returned by script are then stored in the $ReturnArray variable
$ReturnArray = Invoke-Command -Session $Session -Argumentlist $argsArray -ScriptBlock {
    # Define a parameter to accept each data bus input value. Recommend matching names of parameters and data bus input variables above
    Param(
        [ValidateNotNullOrEmpty()]
        [string]$DataBusInput1,

        [ValidateNotNullOrEmpty()]
        [string]$DataBusInput2
    )

    # Define function to add entry to trace log variable
    function AppendLog ([string]$Message)
    {
        $script:CurrentAction = $Message
        $script:TraceLog += ((Get-Date).ToString() + "`t" + $Message + " `r`n")
    }

    # Set external session trace and status variables to defaults
    $ResultStatus = ""
    $ErrorMessage = ""
    $script:CurrentAction = ""
    $script:TraceLog = ""

    try 
    {
        # Add startup details to trace log
        AppendLog "Script now executing in external PowerShell version [$($PSVersionTable.PSVersion.ToString())] session in a [$([IntPtr]::Size * 8)] bit process"
        AppendLog "Running as user [$([Environment]::UserDomainName)\$([Environment]::UserName)] on host [$($env:COMPUTERNAME)]"
        AppendLog "Parameter values received: DataBusInput1=[$DataBusInput1]; DataBusInput2=[$DataBusInput2]"

        # The actual work the script does goes here
        AppendLog "Doing first action"
        # Do-Stuff -Value $DataBusInput1

        AppendLog "Doing second action"
        # Do-MoreStuff -Value $DataBusInput2

        # Simulate a possible error
        if($DataBusInput1 -ilike "*bad stuff*")
        {
            throw "ERROR: Encountered bad stuff in the parameter input"
        }

        # Example of custom result value
        $myCustomVariable = "Something I want to publish back to the runbook data bus"

        # Validate results and set return status
        AppendLog "Finished work, determining result"
        $EverythingWorked = $true
        if($EverythingWorked -eq $true)
        {
           $ResultStatus = "Success"
        }
        else
        {
            $ResultStatus = "Failed"
        }
    }
    catch
    {
        # Catch any errors thrown above here, setting the result status and recording the error message to return to the activity for data bus publishing
        $ResultStatus = "Failed"
        $ErrorMessage = $error[0].Exception.Message
        AppendLog "Exception caught during action [$script:CurrentAction]: $ErrorMessage"
    }
    finally
    {
        # Always do whatever is in the finally block. In this case, adding some additional detail about the outcome to the trace log for return
        if($ErrorMessage.Length -gt 0)
        {
            AppendLog "Exiting external session with result [$ResultStatus] and error message [$ErrorMessage]"
        }
        else
        {
            AppendLog "Exiting external session with result [$ResultStatus]"
        }
        
    }

    # Return an array of the results. Additional variables like "myCustomVariable" can be returned by adding them onto the array
    $resultArray = @()
    $resultArray += $ResultStatus
    $resultArray += $ErrorMessage
    $resultArray += $script:TraceLog
    $resultArray += $myCustomVariable
    return  $resultArray  
     
}#End Invoke-Command

# Get the values returned from script session for publishing to data bus
$ResultStatus = $ReturnArray[0]
$ErrorMessage = $ReturnArray[1]
$Trace += $ReturnArray[2]
$MyCustomVariable = $ReturnArray[3]

# Record end of activity script process
$Trace += (Get-Date).ToString() + "`t" + "Script finished" + " `r`n"

# Close the external session
Remove-PSSession $Session





Thursday, November 9, 2017

Installing scom webconsole on stand alone server

To install scom web console on a stand alone server.  Follow this link

https://technet.microsoft.com/en-us/library/hh298606(v=sc.12).aspx

Then there are some minor configurations to be done.

1. Change the binding of your default website in iis manager. Enter the hostname for your web server there.

2.   Check if the spn for momsdksvc is registered to the account the sdk service is running on
setspn -L msomsdksvc/managementservernamewithfqdn domain\sdkaccount

msomsdksvc/managementservername domain\sdkaccount

If this is not present add the spn using

setspn -A msomsdksvc/managementservernamewithfqdn domain\sdkaccount
setspn -A msomsdksvc/managementservername domain\sdkaccount

3. The allow delegation in Active directory for the account the sdk service is running on the management server the webconsole will connect.

Open Active directory and select the computer which has the web console installed.
  • Click delegation tab.
  • Check radio button for Trust this computer for delegation to specified services only
  • Check radio button for Use Kerberos only.
  • Click add and search users or Computers for the sdk service account
  • Select your management server spn. Which will be of the form (msomsdksvc/servername) 
  • Click ok and close the box
  4. Restart iis on the web server using
      iisreset /restart
 







Friday, October 27, 2017

Powershell script to ping multiple servers at the same time.

Powershell script to ping multiple servers at the same time.
Warning: This script is resource intensive as it starts a powershell instance for each of the jobs. If you have multiple servers then it will take all up all the memory until it finishes all the jobs.

$scriptDir = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$serverlist = GC "$scriptdir\list.txt"
$outputpath =  "$scriptdir\pingcheck.txt"



foreach($server in $serverlist)
{

  Start-job    -scriptblock {
                                                                         param([string]$computer,$outputpath)
                                                                         $out = Test-NetConnection -ComputerName $computer
                                                                         if($out.pingsucceeded -eq "True")
                                                                         {
                                                                         $output = "$computer" + "`t" + $out.remoteaddress + "`t" + " is pinging"
                                                                       
                                                                         }
                                                                         Else
                                                                         {
                                                                         $output = "$computer" + "`t" + $out.remoteaddress + "`t" + " is not pinging"
                                                                         Out-File -InputObject $output -FilePath $outputpath -Append
                                                                         }
                                                                         Sleep -Seconds 10
 return $output

                                                                   } -ArgumentList @($server,$outputpath)

 }

$A = Get-Job | Wait-Job | Receive-Job
Write-host "Writing A" -ForegroundColor Yellow
$A
Out-File -InputObject $A -FilePath $outputpath -Append 
Get-job | Remove-Job