Skip to content

Instantly share code, notes, and snippets.

View asvignesh's full-sized avatar

Vignesh A Sathiyanantham asvignesh

View GitHub Profile
@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 / deployvm.sh
Created January 2, 2019 17:23
Deploy multiple virtual machines from template using powercli
# Specify vCenter Server, vCenter Server username and vCenter Server user password
$vCenter="lab.asvignesh.in"
$vCenterUser="administrator@vsphere.local"
$vCenterPassword="secretPassword"
#
# Specify number of VMs
$vm_count = "100"
#
# Specify the template
$tempate = "W2k12"
@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"
@asvignesh
asvignesh / disableuac.ps1
Created April 20, 2019 10:00
Disable UAC on Windows using powershell
$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
Set-Itemproperty -path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\policies\system' -Name 'EnableLUA' -value 0
@asvignesh
asvignesh / BackupAllDatabases.ps1
Created May 2, 2019 07:44
Powershell script to backup all database
param(
$serverName,
$backupDirectory
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null
@asvignesh
asvignesh / BackupAllDatabases.ps1
Created May 2, 2019 07:44
Powershell script to backup all database
param(
$serverName,
$backupDirectory
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null
@asvignesh
asvignesh / BackupAllDatabases.ps1
Created May 2, 2019 07:44
Powershell script to backup all database
param(
$serverName,
$backupDirectory
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null
@asvignesh
asvignesh / BackupAllDatabases.ps1
Last active May 2, 2019 07:44
Powershell script to backup all database, to run .\BackupAllDatabases.ps1 -serverName NW\CLUST -backupDirectory c:\backupdir
param(
$serverName,
$backupDirectory
)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null