Skip to content

Instantly share code, notes, and snippets.

@ismits
ismits / Invoke-SqlQuery.ps1
Created Sep 24, 2019
PowerShell run a TSQL query on a SQL Server instance and return the query results
View Invoke-SqlQuery.ps1
<#
.Synopsis
Run the TSQL query on a SQL Server instance and return the query results. Use SELECT rather than PRINT to get output.
.Description
Run the TSQL query on a SQL Server instance and return the query results. Use SELECT rather than PRINT to get output.
#>
function Invoke-SqlQuery([string]$ComputerName = $Env:COMPUTERNAME,
[string]$InstanceName = "MSSQLSERVER",
[string]$Database = [System.String]::Empty,
@ismits
ismits / UpdateXml.ps1
Created Sep 24, 2019
Update Xml via PowerShell
View UpdateXml.ps1
function UpdateXml([string]$InputFile = $(Throw "Please provide a path to the input XML file in the InputFile parameter."),
[string]$OutputFile = $InputFile,
[string]$ParentXPath = $(Throw "Please provide an XPath expression to where you want to append/edit a child XML element in the ParentXPath parameter."),
[string]$ElementName = $(Throw "Please provide the name of the XML element to append/edit."),
[string]$ElementAttributeName,
[string]$ElementAttributeValue)
{
if (Test-Path -Path $InputFile)
{
Write-Log "Loading XML document from file: $InputFile"
@ismits
ismits / Configure-IISAppPoolMaxMemory.ps1
Created Sep 24, 2019
Configure IIS AppPool Max Memory via PowerShell
View Configure-IISAppPoolMaxMemory.ps1
function Configure-IISAppPoolMaxMemory([string]$AppPoolName = "ApplicationPoolDefaults",
[int]$MaxMem = 20)
{
[int]$ExitCode = 0
# Ensure WebAdministration module is loaded.
if ((Get-Module -Name WebAdministration) -eq $null)
{
Write-Log "Importing module: WebAdministration"
Import-Module -Name WebAdministration -ErrorAction SilentlyContinue | Write-Log
@ismits
ismits / Configure-IE.ps1
Created Sep 24, 2019
Configure IE First Run and basic settings
View Configure-IE.ps1
function Configure-IE
{
Write-Log "Disabling IE first run customize prompts"
$RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Internet Explorer\Main"
New-RegKey $RegPath
Write-Log (New-ItemProperty -Path $RegPath -Name "DisableFirstRunCustomize" -Value 1 -PropertyType "DWORD" -Force)
$RegPath = "HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Internet Explorer\Main"
New-RegKey $RegPath
Write-Log (New-ItemProperty -Path $RegPath -Name "DisableFirstRunCustomize" -Value 1 -PropertyType "DWORD" -Force)
@ismits
ismits / ClearIECookies.cmd
Created Aug 20, 2019
Command line to clear out IE cookies
View ClearIECookies.cmd
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
@ismits
ismits / DisablingServicesOnServer2016wDE.ps1
Created Aug 15, 2019 — forked from hpaul-osi/DisablingServicesOnServer2016wDE.ps1
Disable unnecessary services that on Windows Server 2016 Desktop Experience (based on MS Security Blog recommendations)
View DisablingServicesOnServer2016wDE.ps1
# Disable extraneous services on Server 2016 Desktop Experience
# https://blogs.technet.microsoft.com/secguide/2017/05/29/guidance-on-disabling-system-services-on-windows-server-2016-with-desktop-experience/
Configuration DisablingServicesOnServer2016wDE
{
param(
[String]$ComputerName = "localhost",
[ValidateSet('ShouldBeDisabledOnly','ShouldBeDisabledAndDefaultOnly','OKToDisable','OKToDisablePrinter','OKToDisableDC')]
[String]$Level = 'OKToDisable'
)
@ismits
ismits / Disable-UAC.ps1
Created Jul 3, 2019
Disable UAC via PowerShell
View Disable-UAC.ps1
function Disable-UAC
{
Write-Log "Disabling User Access Control (UAC)..."
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
New-RegKey $RegPath
Write-Log (New-ItemProperty -Path $RegPath -Name "EnableLUA" -Value 0 -PropertyType "DWORD" -Force)
Write-Log (New-ItemProperty -Path $RegPath -Name "ConsentPromptBehaviorAdmin" -Value 0 -PropertyType "DWORD" -Force)
Write-Log ("Disabling User Access Control (UAC) complete.")
return $true
}
@ismits
ismits / Get-AsyncResult
Created Jul 2, 2019
PowerShell function to wait for an async task to complete and return the result when completed
View Get-AsyncResult
function Get-AsyncResult {
[CmdletBinding()]
[OutputType('Object')]
param (
[Parameter(Mandatory = $true, Position = 1)]
[object] $Task
)
Write-PSFMessage -Level Verbose -Message "Building the Task Waiter and start waiting." -Target $Task
$Task.GetAwaiter().GetResult()
@ismits
ismits / Oracle.psm1
Last active May 1, 2019
PowerShell module for Oracle DB
View Oracle.psm1
<#
.NOTES
Name: Oracle.psm1
Author: Immanuel Smits
Version History:
1.0 - 7/12/2016 - Initial Release.
.SYNOPSIS
Module to provide database access to PowerShell
.DESCRIPTION
Expanded description of what the script does.
@ismits
ismits / Invoke-ShellCommand.ps1
Created May 1, 2019
PowerShell invoke shell command
View Invoke-ShellCommand.ps1
function Invoke-ShellCommand
{
param (
$Command,
$Arguments,
$WorkingDirectory
)
$psi = New-object System.Diagnostics.ProcessStartInfo