Showing posts with label sysadmin. Show all posts
Showing posts with label sysadmin. Show all posts

Thursday, November 9, 2017

Replace "space" with"underscore" in folder name - recursively

I have multiple folders with space in the folder name, and need to replace the space with underscore.
Found a simple batch file to do that

From this:


To this:


Script:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /D %%d IN (*) DO (
   SET "NAME=%%d"
   SET "NEWNAME=!NAME: =_!"
   IF NOT "!NAME!"=="!NEWNAME!" rename "!NAME!" "!NEWNAME!"
)
pause
exit


Tuesday, November 26, 2013

Determining which user removed or deleted a virtual machine

quite a common question for vm sysadmin, may i know who deleted the vm?

answer in the link.

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2005478


To determine which user removed or deleted a virtual machine, check the vCenter Server Events tab for the host or cluster on which the virtual machine resided. 
 
If the Events tab does not provide a record far back enough, you can export user events.
 
To export user events:
  1. With the vSphere client connected to the vCenter Server, click File > Export > Export Events.
  2. Ensure the type User is selected.
  3. Choose a time range using the From and To dropdowns.
  4. Click OK.
  5. Open the text file that is created, navigate to the end of the file, and search backward for the name of the virtual machine. The username of the user that removed or deleted the virtual machine displays.

Tuesday, August 13, 2013

Keeping VMTools ALWAYS up to date

Dear sysadmins out there, how do you guys keep the VMtools and virtual hardware up to date, all the time? Less than 20 VM would still be manageable, but hundreds of them, with some are in live production environment is not an easy task.

The task should be split into two parts:
1) Get all the VMtools up to date
2) Upgrade virtual hardware

This would require at least 2 downtimes. First downtime is a reboot once VMtools installed. 2nd downtime is to power off the VM and do the virtual hardware upgrade. Note that virtual hardware should only be upgraded once the VMtools is updated or you might lose the network setting on that VM.

There is an option to keep the VMtools checked during each power cycle. Found a link to get that massed using powerCLI (http://damiankarlson.com/2011/01/23/managing-vmware-tools-advanced-options-powercli/) but for the first round it could be the manual option. 

1st update:
One liner to get the VMtool and virtual hardware version status:
Get-VM | select Name,Version,@{N="Tools Status";E={$_.Guest.Extensiondata.ToolsVersionStatus}}

2nd Update:
One liner is not good enough, my plan is to align the VMtool upgrade during patching windows (subject to approval)

first, script to get the details.

Function Get-myPatchingReport {
#sample get-vm | % { Get-myPatchingReport $_ } | ft -a
param ($VM)
$report = @()
$row = "" | select Name, OS, Version, ToolStatus
$v = get-vm $VM | get-view
$get = get-vm $VM
$row.Name = $VM
$row.OS = $v.Guest.GuestFullName
$row.Version = $get.Version
$row.ToolStatus = $get.Guest.Extensiondata.ToolsVersionStatus
$report += $row
$report
}
export the report to csv/xls and compare to the patching master list for the exact window. Since some VMs are still running Win2k3, they will not be in patching list. Thus, the Guest OS that is captured from the script.

Going to update this (again) later after I got some live data.
*edit: script was badly coded it will create large temp files and took very long time to complete if you have large environment. will work for about 20-30 vm. else just export the list from vcenter.

Wednesday, July 3, 2013

How to remove ESXi from domain (AD)

This is how to leave a domain for ESX server (for whatever reason you have).


1) Put the ESX in maintenance mode
2) Go to Configuration > Authentication Services
3) click on Properties
4) On the Domain Settings, click button Leave Domain
5) Exit maintenance mode

on the error event "Leave Windows Domain: The operation is not allow in the current state", try to reboot the ESX and repeat the steps. In my case, it helps.


PowerCLI command to see which ESX is still authenticated to AD:-

Get-VMHost | sort | Get-VMHostAuthentication | select vmhost,domain,DomainMembershipStatus,TrustedDomains | ft -a

Wednesday, June 5, 2013

powershell script to get number of CPU and Memory

takes input list of servers from C:\servers.txt and output the result to C:\ram-cpu.csv

make sure your powershell/powerCLI has admin rights


get-wmiobject Win32_ComputerSystem -computer (gc C:\servers.txt) | select Name,@{name="TotalPhysicalMemory(MB)";expression={($_.TotalPhysicalMemory/1mb).tostring("N0")}},NumberOfProcessors | export-csv C:\ram-cpu.csv

Get logical disk layout from OS level (windows)

run this in powerCLI / powershell. make sure you have admin rights (elevated for the powerCLI/powershell)

it takes list of servers from c:\servers.txt and output the result to c:\Disk-GB.csv

gwmi -query "SELECT SystemName,Caption,VolumeName,Size,Freespace FROM win32_logicaldisk WHERE DriveType=3" -computer (gc c:\servers.txt) | Select-Object SystemName,Caption,VolumeName,@{Name="Size(GB)"; Expression={"{0:N2}" -f ($_.Size/1GB)}},@{Name="Freespace(GB)"; Expression={"{0:N2}" -f ($_.Freespace/1GB)}}, @{n="% Free";e={"{0:P2}" -f ([long]$_.FreeSpace/[long]$_.Size)}} | sort "Systemname","caption" | export-csv c:\Disk-GB.csv

Wednesday, September 5, 2012

Windows Slowdown, Investigated and Identified

reblogging from http://randomascii.wordpress.com/2012/09/04/windows-slowdown-investigated-and-identified/

all credits goes to original author, I'm merely archiving it for my personal future reference.
in short, if your free memory is high, and cached is low, there's a culprit in there.