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.

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###

}


Reference:
http://www.purgar.net/using-exchange-2010-cmdlets-in-system-center-orchestrator/



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

Register powershell snapin manually

I wanted to use the VMWare.vimautomation.core psssnapin in my scom discovery script.
But the snapin would not show up.
Earlier i had installed Powercli 6.0 and it does not have this snapin
So i uninstalled it and installed Powercli 5.5. But when the vcenter powershell was started it still showed 6.0 and the snapins would not show up.


 








 These are the steps I followed to manually register the snapin

As an example I will use the VMWare.VimAutomation.Core powershell snapin for .net 2.0.
Add the following registry key to your server.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\VMware.VimAutomation.Core]
"PowerShellVersion"="2.0"
"Vendor"="VMware Inc."
"Description"="This Windows PowerShell snap-in contains Windows PowerShell cmdlets for managing vSphere."
"Version"="5.5.0.0"
"ApplicationBase"="C:\\Program Files (x86)\\VMware\\Infrastructure\\vSphere PowerCLI"
"AssemblyName"="VMware.VimAutomation.ViCore.Cmdlets, Version=5.5.0.0, Culture=neutral, PublicKeyToken=null"
"ModuleName"="C:\\Program Files (x86)\\VMware\\Infrastructure\\vSphere PowerCLI\\VMware.VimAutomation.ViCore.Cmdlets.dll"
"CustomPSSnapInType"="VMware.VimAutomation.ViCore.Cmdlets.Vim4PSSnapIn"

Copy the assembly files in modulename for powercli 5.0 to location

C:\\Program Files (x86)\\VMware\\Infrastructure\\vSphere PowerCLI

Open powershell and run command Add-PSSnapin Vmware.vimautomation.Core