Skip to content

Instantly share code, notes, and snippets.

View Agazoth's full-sized avatar

Axel B. Andersen Agazoth

View GitHub Profile
@Agazoth
Agazoth / LegacyCommandObject.psm1
Created February 4, 2018 08:42
Gets PSCustomObjects from legacy commands. netstat and arp is allowed so far. Runs on Powershell 5.1 and 6.0
function Get-LegacyCommandObject {
[CmdletBinding()]
param ([ValidatePattern("^(netstat|arp)")]
[string]$CommandLine)
$Result = iex $CommandLine.split(';',2)[0]
$Headers = $Result -match '^\w+(`n`r)*'
foreach ($Line in $Result) {
if ($Line -match '^$'){$Collect = $False;$Properties=$Null;continue}
if ($Headers -contains $Line){$ObjHash=@{}; if ($Line -match ':'){$Parts = $Line.split(':',2).trim();$ObjHash.add($PArts[0],$Parts[1])};$Collect = $true;$CollectParametersHeader=$true;continue}
@Agazoth
Agazoth / Get-Feed.ps1
Last active January 28, 2018 07:27
Gets a newsfeed and lets the user select a specific feed to display in either browser or console
function Get-Feed {
[CmdletBinding()]
param ($Feeduri = 'https://powershell.org/feed/')
$c = 0
$Feeds = Invoke-RestMethod -uri $Feeduri
$FeedObjects = foreach ($Feed in $Feeds){
[PSCustomObject]@{
'No.' = ++$c
Title = $Feed.title
"Publication date" = $Feed.pubDate
@Agazoth
Agazoth / Get-WickedOSandDiskObject.ps1
Last active January 21, 2018 19:38
Gets information about Operating System and Disks - A solution to Puzzle 2 in Iron Scripter 2018 Perquel 2
function Get-WickedOSandDiskObject {
param ($ComputerName=$env:COMPUTERNAME)
$CimSession = New-CimSession -ComputerName $ComputerName
$ComputerObject = Get-CimInstance Win32_OperatingSystem -CimSession $CimSession | Select-Object *,@{n='Disks';e={Get-CimInstance Win32_LogicalDisk -CimSession $CimSession | Select-Object *,@{n='PercentageUsed';e={"{0:P}" –f $(($_.size-$_.Freespace)/$_.size)}}}}
$ComputerObject.psobject.TypeNames.Insert(0, "WickedOSandDiskObject")
$ComputerObject
}
@Agazoth
Agazoth / Get-LocalMonitorInfo.ps1
Last active January 14, 2018 14:20
Iron Scripter 2018 Puzzle 1
$Monitors = Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID
$Computer = Get-CimInstance -Class Win32_ComputerSystem
$Bios = Get-CimInstance -ClassName Win32_Bios
foreach ($Monitor in $Monitors){
$PSObject = [PSCustomObject]@{
ComputerName = $Computer.Name
ComputerType = $Computer.model
ComputerSerial = $Bios.SerialNumber
MonitorSerial = [string]::join('',$monitor.SerialNumberID.Where{$_ -ne 0})
MonitorType = [string]::join('',$monitor.UserFriendlyName.Where{$_ -ne 0})
@Agazoth
Agazoth / Get-MonitorInfo.ps1
Last active April 15, 2023 23:24
Iron Scripter 2018 Puzzle 1 for multiple machines
function Get-MonitorInfo {
[CmdletBinding()]
param ([string[]]$ComputerNames = $env:computername)
foreach ($ComputerName in $ComputerNames){
try {
$CimSession = New-CimSession -ComputerName $ComputerName
} catch {
Write-Warning "Please make sure PSRemoting is enabled on $ComputerName"
Continue
}
@Agazoth
Agazoth / AutoPilotInfoToBusinessStore.ps1
Last active December 4, 2019 08:44
New W10 machine to Autopilot
Powershell
Set-Executionpolicy -unrestricted
Install-Script -Name Get-WindowsAutoPilotInfo -Scope CurrentUser
Get-WindowsAutoPilotInfo C:\Info.csv
&'C:\Program Files (x86)\Internet Explorer\iexplore.exe' https://businessstore.microsoft.com