This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gwmi Win32_OperatingSystem -CN((icm{while(Read-Host -Pr 'ComputerName' -OV C){$CN+=$C}$CN}))|Select PSComputerName,ServicePackMajorVersion,Version,@{l='BIOSSerial';e={(gwmi Win32_BIOS -CN $_.PSComputerName).SerialNumber}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One-liner, command and parameter names spelled out | |
Invoke-RestMethod -Uri 'www.telize.com/geoip' | Format-Table -Property longitude, latitude, continent_code, timezone | |
# Advanced function wrapping the www.telize.com JSON endpoint | |
function Get-GeoInformation { | |
<# | |
.SYNOPSIS | |
Get IP address geo information |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No semicolons, only one set of curlies, using aliases etc. to keep it as short as possible | |
ipcsv I*|%{$_|Add-Member OSVERSION (gwmi -CN $_.MACHINENAME Win32_OperatingSystem).Caption -P}|epcsv Output.csv | |
# Same as the above, but longer as I am not taking shortcuts with aliases and an incomplete filename | |
Import-Csv Input.csv | %{ $_ | Add-Member OSVERSION (Get-WmiObject -ComputerName $_.MACHINENAME Win32_OperatingSystem).Caption -PassThru } | Export-Csv Output.csv | |
# How I would have done it, had there been no limitations on lenght, semicolons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Specify input and output files | |
$InputCSVFile = '.\input.csv' | |
$OutputCSVFile = '.\output.csv' | |
# Import data from CSV | |
$CSVData = Import-Csv -Path $InputCSVFile | |
# Run trim() (remove leading and trailing whitespace) on all property values | |
$CSVTrimmedData = $CSVData | Foreach-Object { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-RSSFeed { | |
[CmdletBinding()] | |
Param( | |
[Parameter( | |
Mandatory = $True | |
)] | |
[String[]] | |
$Uri | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[pscredential] | |
$Credential | |
, | |
[String] | |
$TaskPath = '' | |
) | |
$TaskName = 'ImageFactory - Build {0} images' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Folder where logfiles are stored | |
$Path = 'C:\TEMP' | |
# Filename pattern for regex match operator (<guid>.log) | |
$Pattern = '^.{8}-.{4}-.{4}-.{4}-.{12}\.log$' | |
$From = 'from@example.com' | |
$To = 'to@example.com' | |
$SmtpServer = 'smtpserver.domain.local' | |
$Subject = 'Todays log file was not found' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([string]$VMNameStr) | |
# Split string by comma, and trim of any whitespace | |
VMNameStr.Split(',').Trim() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Path = 'C:\TEMP\TEST1' | |
$Filter = '*.pdf' | |
$Attribute = [System.IO.FileAttributes]::Archive | |
# Get all files in $Path matching $Filter | |
Get-ChildItem -Path $Path -Filter $Filter -Recurse | |
# Get all files in $Path matching $Filter where $Attribute is set | |
Get-ChildItem -Path $Path -Filter $Filter -Recurse | Where-Object { $_.Attributes -band $Attribute } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VERBOSE: Loading module from path 'C:\Custom Validators and Transforms\TestMod.psm1'. | |
VERBOSE: Exporting function 'Test-OwnClass'. | |
VERBOSE: Exporting function 'Test-ValidatePathExists'. | |
VERBOSE: Exporting function 'Test-PathTransform'. | |
VERBOSE: Importing function 'Test-OwnClass'. | |
VERBOSE: Importing function 'Test-PathTransform'. | |
VERBOSE: Importing function 'Test-ValidatePathExists'. | |
SomeString | |
---------- |
OlderNewer