Get-Snapshot -VM VM -Name '<snapshot name>'
Friday, January 5, 2018
Power on/off VM via command line.
Power on a VM
To power on a virtual machine from the command line:
- List the inventory ID of the virtual machine with the command:
vim-cmd vmsvc/getallvms |grep <vm name>
Note: The first column of the output shows the vmid.
- Check the power state of the virtual machine with the command:
vim-cmd vmsvc/power.getstate <vmid>
- Power-on the virtual machine with the command:
vim-cmd vmsvc/power.on <vmid>
Get all vm's with connected CD rom drives
This is a powercli command to get all the vm's with connected cdrom drive.
get-cluster | where {$_.Name -eq "SFColo Test & Dev"} | get-vm | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" } } | select Name
Get VMX and VMWare tools version and export to CSV
To get the VMware tools versions and export it to a csv called vmtools.csv
get-vm | where {$_.powerstate -ne "PoweredOff" } | where {$_.Guest.ToolsVersionStatus -ne "guestToolsCurrent"} | % { get-view $_.id } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}}, @{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}} | Export-Csv -NoTypeInformation -UseCulture -Path d:\vmtools.csv
Check if a user is in an AD group.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Security.Principal;
namespace test_adgroup
{
class Program
{
static void Main(string[] args)
{
string username = "cykill";
//string username = WindowsIdentity.GetCurrent().Name;
PrincipalContext pc = new PrincipalContext(ContextType.Domain,"mydomainname");
UserPrincipal up = UserPrincipal.FindByIdentity(pc, username);
if(up.IsMemberOf(pc,IdentityType.SamAccountName,"mygroup"))
{
Console.WriteLine("In Group");
}
else
{
Console.WriteLine("Not In Group");
}
}
}
}
Caveat: This does not work for the "Domain Users" group. It always return false. I don't know why.
Update: Seems it doesn't work for large AD groups.
Disable IPv6 via commands in Windows
get-netadapterbinding
set-NetAdapterBinding -Name “Network Adapter Name” –ComponentID ms_tcpip6 –Enabled $False
new-itemproperty -Path HKLM:\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters -Name DisabledComponents -PropertyType DWord -Value ffffffff
Reset a slot in Cisco UCS.
- Reset a slot (equivalent to remove power from the blade and reapplying):
#reset slot x/y (where x = chassis and y = blade or server #)
Tarball an entire Linux system
#!/bin/bash
#Version: 1.0
#Description: Checks for a destination mount directory. Mounts it if it does not exist, the backs up the server to the mount directory.
mountdir="<mount directory>"
servername="<servername>"
exclusions="--exclude=/mnt --exclude=/proc --exclude=/lost+found --exclude=/tmp --exclude=/media --exclude=/sys --exclude=/dev --exclude=/run --exclude=/var/cache"
if [ -d $mountdir ]; then
cd $mountdir
tar -zcpf $servername-full-backup-`date '+%d-%B-%Y'`.tar.gz / $exclusions
else
sudo mount -t cifs -o username=moatisuser,password=moatisuser,rw \\\\fw24\\ata_1 /mnt/fw24
cd $mountdir
tar -zcpf $servername-full-backup-`date '+%d-%B-%Y'`.tar.gz / $exclusions
fi
Setup iptables in Linux
Ubuntu does come with iptables preset like in Fedora. Here's the base set up for iptables.
Add iptable rules.
Block Null Packets
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
Reject Syn-Flood Attack
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
Reject XMAS/recon packets
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
Allow custom ports
<here>
Accept Established Connections
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -j REJECT iptables -A FORWARD -j REJECT
iptables -A FORWARD -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -j REJECT
iptables -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
Use iptables-save to save it to a file.
iptables-save > /etc/iptables.rules
Edit rc.local to import iptables rules during boot up.
iptables-restore < /etc/iptables.rules
Write to a file in CSharp
Quick and dirty way to write to a file in C#.
StreamWriter log = new StreamWriter(@c:\log.txt);
log.WriteLine(ErrorMessage);
log.WriteLine();
log.Close();
test test
Subscribe to:
Posts (Atom)