Skip to content

Instantly share code, notes, and snippets.

@skunkie
skunkie / MyPSObject.ps1
Last active November 25, 2019 14:18
PSObject with op_Addition
Class MyPSObject : PSObject {
static [MyPSObject] op_Addition ([MyPSObject] $Object1, [MyPSObject] $Object2) {
<#
$obj1 = [mypsobject] @{a = 1}
$obj2 = [mypsobject] @{b = 2; c = 3}
$obj3 = [mypsobject] @{c = 0; d = 4}
$obj1 + $obj2 + $obj3
a c b d
@skunkie
skunkie / Get-LoggedOnUser.ps1
Last active March 28, 2019 15:16
Get Logged On Users with 'query.exe USER' in PowerShell
function Get-LoggedOnUser {
param(
[string[]] $ComputerName=$env:COMPUTERNAME
)
Begin {
$ErrorActionPreference = 'Stop'
& cmd /c ver | Out-Null
$encoding = [Console]::OutputEncoding
[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding('utf-8')
}
@skunkie
skunkie / Get-FolderPath.ps1
Last active February 11, 2019 07:13
This cmdlet retrieves the path to the folder on a vCenter Server system.
function Get-FolderPath {
<#
.NAME
Get-FolderPath
.SYNOPSIS
This cmdlet retrieves the path to the folder on a vCenter Server system.
.DESCRIPTION
This cmdlet retrieves the path to the folder on a vCenter Server system.
.PARAMETER Folder
a folder on a vCenter Server system
@skunkie
skunkie / Invoke-WmiMethodAsync.ps1
Last active December 21, 2018 06:24
Run a command async on a set of computers
#Requires -Version 3.0
<#
.SYNOPSIS
Wraps Invoke-WmiMethod to run a command async
.DESCRIPTION
Wraps Invoke-WmiMethod to run asynchronously on a number of computers
.PARAMETER Computer
An array of computers
.PARAMETER Command
#Requires -Version 3.0
<#
.SYNOPSIS
Log Archiver for Windows
.DESCRIPTION
This script can be used to archive old log files
.PARAMETER Path
The path to the directory with log files.
.PARAMETER ArchiveDays
@skunkie
skunkie / glpi_import_from_vc.pl
Last active June 17, 2022 08:38
Automatic collection of info from vCenter, to GLPI
#!/usr/bin/perl -w
#
# This tool can be used to push inventory of virtual machines and ESXi hosts from a VIServer in GLPI via FusionInventory plugin
use v5.10;
use strict;
use warnings;
use VMware::VIRuntime;
use POSIX 'ceil';
@skunkie
skunkie / SetStaticIP.ps1
Last active April 24, 2018 10:48
Set static IP address from DHCP
$addressFamily = 'IPv4'
# Retrieve the network adapter
$adapters = Get-NetAdapter | Where-Object {$_.Status -eq 'Up'}
foreach ($adapter in $adapters) {
$ipConfiguration = $adapter | Get-NetIPConfiguration
if ($ipConfiguration.NetIPv4Interface.DHCP -eq 'Disabled') {
continue # 'DHCP is not enabled'
}
$dns = ($ipConfiguration | Get-DnsClientServerAddress -AddressFamily $addressFamily).ServerAddresses
# Remove any existing IPv4 IP and gateway from the adapter
@skunkie
skunkie / SetStaticIPtoCMD.ps1
Created March 13, 2018 09:03
Wrap a PowerShell script into BAT/CMD file
# 1. Remove lines containing only comments and empty lines
# 2. Remove a comment after some code, e.g. some code # a comment
# 3. Join a line with a trailing { to the next line, e.g. if (a condition) {$
# 4. Join a line beginning with a } character to the previous line, e.g. ^}$, or ^ }
# 5. Replace the character ` when it is used to break code in two lines, with a space, e.g. somecode `$
# 6. Replace all \r\n (carriage return and new line characters) with '; '
$text = (Get-Content -Path .\SetStaticIP.ps1 | Where-Object {$_ -notmatch "^\s*?#|^$"} | ForEach-Object {$_.Trim()} | Out-String) `
-replace '\s*?#.*?\r\n', '' `
-replace '{\s*?\r\n\s*?', '{' `
@skunkie
skunkie / nonascii.sh
Created October 14, 2015 12:22
find non-ASCII characters in a string
#!/bin/sh
usage(){
echo "
find non-ASCII characters in a string
Usage: $0 STRING
"
exit 0
}
[settings]
reposroot="/repo"
proxy="http://127.0.0.1:3128"
### EXAMPLE REPO CONFIG ###
# [reposlist]
# epel=true ### use reposync and createrepo
# centos-base=false ### use only createrepo
# vmtools="/opt/scripts/vmtools_osp_sync.sh" ### use a custom command