Skip to content

Instantly share code, notes, and snippets.

@milesgratz
milesgratz / find-recursive-files-move-to-parent.ps1
Created April 13, 2017 11:41
Find recursive text files and move to parent folder
# Define parent folder
$Parent = "C:\temp\Parent"
# Search for text files recursively
$Files = Get-ChildItem -Path $Parent -Filter *.txt -Recurse
# Loop through files, moving to Parent folder
foreach ($File in $Files)
{
Try
@milesgratz
milesgratz / Get-NetworkAdapter-PSv2.ps1
Created April 12, 2017 18:43
Get-NetworkAdapter (PowerShell v2 example)
$NetAdapterList = (gwmi -Query "SELECT * FROM Win32_NetworkAdapter")
$NetAdapterConfigList = (gwmi -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")
$Results = @()
foreach ($NetAdapter in $NetAdapterList){
$NetAdapterConfig = $NetAdapterConfigList | Where-Object { $_.Index -eq $NetAdapter.DeviceID }
If ($NetAdapterConfig -ne $null)
{
$Object = New-Object PSCustomObject
@milesgratz
milesgratz / Use-Proxy.ps1
Last active April 12, 2017 15:26
Use-Proxy function suggestion (#powershell irc-bridge)
Function Use-Proxy {
$proxy = 'http://my.proxy.server:80/'
$WebRequest_params = @{
Uri = 'http://www.example.com'
Method = 'Head'
DisableKeepAlive = $true
UseBasicParsing = $true
}
Try {
Function Write-Log {
param(
$Message,
$logPath,
$Color = "Yellow"
)
Write-Host "$Message" -ForegroundColor $Color
If ($logPath -ne $null)
{