Skip to content

Instantly share code, notes, and snippets.

View asvignesh's full-sized avatar

Vignesh A Sathiyanantham asvignesh

View GitHub Profile
@asvignesh
asvignesh / SamplePsModule.cs
Created August 27, 2015 14:27
PowerShell Module
using System;
using System.Management.Automation;
namespace SamplePsModule
{
[Cmdlet(VerbsCommon.Get, "Vignesh")]
public class SampleGet : Cmdlet //Must inherit Cmdlet
{
//Parameters
[Parameter(Mandatory = true)]
@asvignesh
asvignesh / ContainsTest.java
Last active August 29, 2015 14:21
Java List Contains for Custom Object Type
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by Vignesh on 26-05-2015.
*/
public class ContainsTest {
public static void main(String[] args) {
@asvignesh
asvignesh / PortOpenTest.Java
Last active August 29, 2015 14:22
How to check whether the particular port is in use
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
/**
* Created by Vignesh on 26-05-2015.
*/
public class PortOpenTest {
@asvignesh
asvignesh / ExpandDatastore.java
Created August 8, 2015 17:15
Expand the VMFS Datastore to its maximum size
import com.asvignesh.common.MyException;
import com.vmware.vim25.DatastoreHostMount;
import com.vmware.vim25.HostScsiDisk;
import com.vmware.vim25.VmfsDatastoreExpandSpec;
import com.vmware.vim25.VmfsDatastoreOption;
import com.vmware.vim25.mo.*;
import java.rmi.RemoteException;
/**
@asvignesh
asvignesh / MySql-Backup-Postscript.sh
Created November 28, 2017 06:48
Pre and Post script for MySQL server consistent* backup
#!/bin/bash
mysql -u <user> -p<Password> -e 'unlock tables;'
if [ $? -gt 0 ]; then
echo "Failed running mysql unfreeze"
exit 1
else
echo "success"
exit 0
@asvignesh
asvignesh / PaginationParams.java
Created April 10, 2018 15:04
PaginationParams.java
package viewmodel;
import play.mvc.QueryStringBindable;
import java.util.Map;
import java.util.Optional;
public class PaginationParams implements QueryStringBindable<PaginationParams> {
private int page;
private int offset;
@asvignesh
asvignesh / VirtualMachineCreationTime
Created May 10, 2018 17:52
Get vSphere Virtual Machine creation time
public Timestamp getCreatedDate() throws RemoteException {
final EventFilterSpec eventFilterSpec = new EventFilterSpec();
eventFilterSpec.setEventTypeId(new String[]{"VmCreatedEvent", "VmBeingDeployedEvent", "VmRegisteredEvent", "VmClonedEvent"});
EventFilterSpecByEntity entity = new EventFilterSpecByEntity();
entity.setEntity(virtualMachine.getMOR());
EventFilterSpecRecursionOption recOption = EventFilterSpecRecursionOption.self;
entity.setRecursion(recOption);
eventFilterSpec.setEntity(entity);
@asvignesh
asvignesh / VM Creation Time PowerCli
Created May 10, 2018 17:58
VM Creation Time from vSphere Power CLI
$vmProp = ""|Select VMname,CreatedTime
if ($CollectedEvent=$vm|Get-VMEvents -types 'VmBeingDeployedEvent','VmRegisteredEvent','VmClonedEvent','VmBeingCreatedEvent' -ErrorAction SilentlyContinue)
{
if($CollectedEvent.gettype().isArray){$CollectedEvent=$CollectedEvent|?{$_ -is [vmware.vim.VmRegisteredEvent]}}
$CollectedEventType=$CollectedEvent.gettype().name
$CollectedEventCreationDate=$CollectedEvent.CreatedTime
$vmProp.VMname=$CollectedEvent.vm.Name
$vmProp.CreatedTime=$CollectedEventCreationDate
}
@asvignesh
asvignesh / sql_create.ps1
Created April 11, 2019 19:47
Create / Restore Database from Adventure work backup file
import-module sqlps
$total =2
$volume1 = "E:"
$volume2 = "F:"
$backupLocation = "C:\Users\asvignesh\Downloads\AdventureWorks2016.bak"
$database_prefix = "vignesh-testing"
foreach($count in 1..$total)
{
@asvignesh
asvignesh / deleteshadows.ps1
Created April 19, 2019 14:14
Run Remote powershell and delete shadows on all machines
$nodes = @("nim-win1-4.asvigneshad.local","nim-win2-5.asvigneshad.local","nim-win3-3.asvigneshad.local","nim-win4-1.asvigneshad.local","nim-win5-5.asvigneshad.local")
$username = "asvigneshad\administrator"
$password = "Password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
For ($i=0; $i -lt $nodes.Length; $i++) {
$sess = New-PSSession -Credential $cred -ComputerName $nodes[$i]
Enter-PSSession $sess
$script = "./tmp.dsh"