Skip to content

Instantly share code, notes, and snippets.

param(
[string] $dataSource = "$PSScriptRoot\dbf\da_md_wpa.dbf", # path to dbf file
[string] $sqlCommand = "SELECT * FROM [da_md_wpa$]", # Sheet/Table Name
[System.Management.Automation.PsCredential] $credential
)
$authentication = "Integrated Security=SSPI;"
if($credential)
{
$plainCred = $credential.GetNetworkCredential()
# This is just an example, AutoIT is more robust, but safety measures and error handling to make this more robust can definitely be scripted, e.g. monitor events for actions, monitor processes, wait for, validations etc.
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
start cmd
start-sleep -Seconds 1
[Microsoft.VisualBasic.Interaction]::AppActivate(“cmd.exe”)
start-sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait(“Hello”)
# Sample: Get user's AD group membership without AD module
$username = 'username' # username
$email = 'user@email.com' # email goes here
<#
# Example with .NET class:
$Search = New-Object System.DirectoryServices.DirectorySearcher("(&(ObjectCategory=Person)(ObjectClass=User)(cn=$username))")
$results = $Search.FindAll()
$results.properties["Memberof"]
@mavericksevmont
mavericksevmont / PSGUITemplate.ps1
Last active October 13, 2020 19:02
GUI Template PowerShell
# Load assemblies
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Wind")
[void] [System.Windows.Forms.Application]::EnableVisualStyles()
# Start functions
function YourFunction($var){
$command = {param($var)
@mavericksevmont
mavericksevmont / books.md
Created May 30, 2020 21:50 — forked from abstractart/books.md
Free Programming Ebooks - O'Reilly Media. Codeship free ebooks here - https://bit.ly/2oQ0knQ
@mavericksevmont
mavericksevmont / Invoke-SSE.ps1
Last active April 27, 2020 04:14
PowerShell and Server Side Events
#READ SERVER SIDE EVENTS
# I'll properly functionify this later
$Url = 'https://api.pipedream.com/sources/MyIDHere/sse'
$token = 'token'
$request = [System.Net.WebRequest]::CreateHttp($Url)
$request.Headers.Add("Authorization", "Bearer $token")
$request.AllowReadStreamBuffering = $false
$response = $request.GetResponse()
$stream = $response.GetResponseStream()
function Get-DatePicker
{
[CmdletBinding()]
[OutputType([System.DateTime])]
Param([string]$windowTitle=$null)
Add-type -AssemblyName "System.windows.forms"
$winForm = New-object Windows.Forms.Form
if([string]::IsNullOrEmpty($windowTitle)){
$winForm.Text = "DatePicker Control"
@mavericksevmont
mavericksevmont / GUITest.ps1
Last active January 28, 2020 16:17
PowerShell GUI test
# Form details
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Wind")
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(600,400)
# Start functions
@mavericksevmont
mavericksevmont / .ps1
Created March 19, 2019 18:15
Ping-Machines
# Name: Ping-Machines
# This is a script created for educational purposes, no puppies were harmed while using write-host
# The purpose of this script is to be improved with new features, style and best practices
# https://www.youtube.com/playlist?list=PL-CiBNPRVIA2KhV94GXuIv2_nQGvyrkJs
Write-Host "Script is running" -ForegroundColor Cyan -BackgroundColor Black
$Hosts = Get-Content 'C:\temp\MyScript\Hosts.txt' # Source list of devices to ping
$Output = 'C:\temp\MyScript\PingResults.txt' # Results output file location