Skip to content

Instantly share code, notes, and snippets.

@manualbashing
manualbashing / freqStunnedVMs.sh
Created June 21, 2018 14:49
Shows which vms on a esxi host got stunned recently and for how long
for log in `esxcli vm process list | \
grep Config | \
awk '{print $3}' | \
sed 's|[^/]*vmx$|vmware.log|g'`
do
printf "\n$log\n"
cat $log | grep Checkpoint_Unstun | sed 's/^/\t/g'
done
@manualbashing
manualbashing / missing_values_count.py
Last active November 6, 2019 12:31
[Missing values statistics for a pandas dataframe] #Pandas
def missing_values_count(df_train):
tbl = []
for col in df_train.columns[df_train.isnull().any()]:
tbl.append([col, df_train[col].isnull().sum()])
return pd.DataFrame(tbl, columns=["column", "missing_values_count"])
@manualbashing
manualbashing / get_vm.ps1
Last active November 6, 2019 12:30
Find vm by ip address in #PowerCLI
get-vm | ? { $_.Guest.IPAddress -contains '172.22.0.25' }
@manualbashing
manualbashing / crlf2lf.ps1
Last active August 27, 2019 14:45
Convert all files in the current folder from CRLF to LF (recursively)
# Explicit version
$files = Get-ChildItem -Recurse -File
foreach ($path in $files.FullName)
{
$crlfContent = Get-Content $path
$lfContent = ($crlfContent -join "`n") + "`n"
Set-Content -Path $path -Value $lfContent -NoNewline
}
# Short version
@manualbashing
manualbashing / vm_off_times.sh
Last active October 2, 2019 11:31
Determine how long a VM is turned off according to last write time to vmware.log
# Find vms,
find /vmfs/volumes/ -iname vmware.log | while read line; do
ls -lach $line | awk '{print "[" $6 " " $7 " " $8 "]" " " $9}' >> /tmp/vm_off_times.log
done
@manualbashing
manualbashing / exactlyOne.ps1
Last active October 9, 2019 13:18
Returns True if InputObject is a single object. False if it is null or a collection.
function ExactlyOne ($InputObject) {
(@($InputObject | Select-Object)).Count -eq 1
}
@manualbashing
manualbashing / Get-NmpDeviceSettings.ps1
Created October 9, 2019 14:16
Returns nmp Device Settings for SC Storage
function Get-NmpDeviceSettings ($VMHost)
{
$VMHost = Get-VMHost $VMHost
foreach ($vmh in $VMHost)
{
$esxcli = $VMHost | Get-EsxCli -V2
$esxcli.storage.nmp.device.list.Invoke() |
Where-Object DeviceDisplayName -like COMPELNT* |
Select-Object Device*,
PathSelectionPolicy,
@manualbashing
manualbashing / Get-vCenterDnsName.ps1
Created October 11, 2019 10:51
Query an esxi host for the dns name of the vcenter server it is managed by.
$vCenterDnsName = $vmHost.ExtensionData.CLient.ServiceUrl -replace 'https?://(.+?)/sdk','$1'
@manualbashing
manualbashing / ISE_Cmdlet_Snippet.ps1
Last active October 15, 2019 14:49
ISE snipped for cmdlet with parameter validation.
<#
.Synopsis
Kurzbeschreibung
.DESCRIPTION
Lange Beschreibung
.EXAMPLE
Beispiel für die Verwendung dieses Cmdlets
.EXAMPLE
Another example of how to use this cmdlet
.INPUTS
@manualbashing
manualbashing / Setup_AzureSQL_for_mRemoteNG.md
Last active October 30, 2019 10:45
Use mRemoteNG with Azure SQL
  • Serverless
  • Connect with MS-SQL Studio
  • Create Tables