Skip to content

Instantly share code, notes, and snippets.

View vMarkusK's full-sized avatar

Markus Kraus vMarkusK

View GitHub Profile
@vMarkusK
vMarkusK / EsxiHostHardening.ps1
Created January 15, 2019 13:39
VMware ESXi Host Base Hardening
foreach ($VMhost in (Get-VMHost))
{
#Stop SSH Service
$ServiceList = Get-VMHostService -VMhost $VMhost
$SSHservice = $ServiceList | Where-Object {$_.Key -eq "TSM-SSH"}
If ($SSHservice.Running -eq $true) {Stop-VMHostService -HostService $SSHService -Confirm:$false}
else {Write-Output "SSH Server on host $VMhost is Stopped"}
$Shellservice = $ServiceList | Where-Object {$_.Key -eq "TSM"}
If ($Shellservice.Running -eq $true) {Stop-VMHostService -HostService $Shellservice -Confirm:$false}
else {Write-Output "Shell Server on host $VMhost is Stopped"}
@vMarkusK
vMarkusK / PowerShell Password Complexity Requirements.ps1
Created January 15, 2019 13:20
PowerShell Password complexity requirements
$Credential = Get-Credential
$Password = $Credential.GetNetworkCredential().Password
if(($Password -cmatch '[a-z]') -and ($Password -cmatch '[A-Z]') -and ($Password -match '\d') -and ($Password.length -ge 12) -and $Password -match '!|@|#|%|^|&|$|_') {
Remove-Variable Password
Write-Output "Password is valid"
}
else {
Remove-Variable Password
$Valid = $false
Throw "Invalid Password!
@vMarkusK
vMarkusK / Backup-VCSAToFile.ps1
Created November 5, 2018 15:55
Create a VCSA Backup via BackupAPI. Used as a Veeam Pre or Post Script
Start-Transcript -Path "C:\Scripts\Logs\Backup-$((Get-Date).ToString('yyyy-MM-dd-hh-mm')).log"
#region: Log Rotate
$LogPath = "C:\Scripts\Logs\*"
$LogFiles = "*.log"
[int] $LogRetention = "-14" # in Days
Get-ChildItem $LogPath -Include $LogFiles -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays($LogRetention)} | Remove-Item
#endregion
#region: Import Module
@vMarkusK
vMarkusK / Find Duplicate VM IPs.ps1
Created October 24, 2018 08:07
Find Duplicate VM IPs
Function GetArrayDupes {
param($array)
$hash = @{}
$array | %{ $hash[$_] = $hash[$_] + 1 }
$result = $hash.GetEnumerator() | ?{$_.value -gt 1} | %{$_.key}
Return $result
}
$VMs = Get-VM
$IPs = $VMs.Guest.IPAddress
@vMarkusK
vMarkusK / Update Get-CIDatastore Threshold.ps1
Created October 24, 2018 07:56
Update Get-CIDatastore Threshold
$CiDs = Get-CIDatastore | where {$_.Name -like "LOCAL-*"} | Get-CIView
foreach ($object in $CiDs ){
$Cap = $object.TotalCapacityGb
$red = [math]::round($object.TotalCapacityGb/85, 0)
$yellow = [math]::round($object.TotalCapacityGb/75, 0)
Write-Host "Total Cap: '$cap GB'"
Write-Host "New ThresholdRedGb: '$red GB'"
Write-Host "New ThresholdYellowGb: '$yellow GB'"
$object.ThresholdRedGb = $red
@vMarkusK
vMarkusK / ESXi-NetApp-Config.ps1
Created February 22, 2018 09:34
This Script Configures ESXi DNS, NTP, SSH, PowerProfile and NetApp Advanced Options
function Set-MyESXiOption {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=0)]
[String] $Name,
[Parameter(Mandatory=$False, ValueFromPipeline=$False, Position=1)]
[String] $Value
)
process {
$myESXiOption = Get-AdvancedSetting -Entity $VMhost -Name $Name
@vMarkusK
vMarkusK / ESXi-Depot-Install-ESXCLI.ps1
Created February 22, 2018 08:55
This PowerCLI Script Uploads and Installs a ESXi Depot Package via ESXCLI -v2
[String]$ClusterName = "Compute01"
[String]$LocalPath = "D:\Image\HPE-20180220.zip"
[String]$DepotName = "HPE-20180220.zip"
[String]$TempDatastoreName = "LOCAL*"
$VMhosts = Get-Cluster -Name $ClusterName | Get-VMHost | Where-Object {$_.ConnectionState -eq "Maintenance"}
foreach ($VMhost in $VMhosts) {
#region: Upload Patch
$Datastore = $VMhost | Get-Datastore -Name $TempDatastoreName
@vMarkusK
vMarkusK / vRops-Veeam.ps1
Last active February 16, 2018 08:37
Push Custom Properties about Veeam Protection into VMware vRealize Operations Manager
#Credits: http://vman.ch/vrops-suite-api-properties-import/
#region: SSL Config for SelfSigned Cert and force TLS 1.2
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
@vMarkusK
vMarkusK / removeDuplicatesFromArray.js
Created September 21, 2017 10:19
vRealize Orchestrator - remove Duplicates From Array
// VMware vRealize Orchestrator action sample
//
// Removes duplicates from an array, with the option to also sort the array
//
// For vRO 6.0+
//
// Action Inputs:
// a - Array/Any - Array with potential duplicates
// doSort - boolean - Sort the array also? Potentially better performance than unsorted algorithm
//
@vMarkusK
vMarkusK / VeeamBR95-Silent.ps1
Created August 2, 2017 10:32
Veeam Availability Suite Unattended Install with PowerShell
# Requires PowerShell 5.1
# Requires .Net 4.5.2 and Reboot
#region: Variables
$source = "X:"
$licensefile = "C:\_install\veeam.lic"
$username = "svc_veeam"
$fulluser = $env:COMPUTERNAME+ "\" + $username
$password = "Password!"
$CatalogPath = "D:\VbrCatalog"