Skip to content

Instantly share code, notes, and snippets.

View JohnLBevan's full-sized avatar
🏠
Working from home

John Bevan JohnLBevan

🏠
Working from home
View GitHub Profile
@JohnLBevan
JohnLBevan / Common.ps1
Created September 28, 2017 17:03
Infor EAM Cognos Report Exporter. This script is intended to aid in the management of source control for EAM's Cognos Reports by automating the extraction of their definitions into XML files under a suitable directory structure. Placing this structure under GIT source control then gives object level management of the reports' code.
[CmdletBinding(DefaultParameterSetName = 'GetList')]
param (
[Parameter(Mandatory = $true)]
[string]$DbInstance
,
[Parameter(Mandatory = $true)]
[string]$DbCatalog
,
[Parameter(Mandatory = $false)]
[string]$Tenant = '%' #if a tenant is not specified, this will pull back all report defintions from the db
@JohnLBevan
JohnLBevan / Get-WhoIs.ps1
Last active May 9, 2026 19:55
Performs a WhoIs query using SysInternals `whois` tool, then parses the results to a queryable format. NB: Designed with output from "UK.whois-servers.net"; however it seems that not all whois queries return data in the same format!
function Get-WhoIs {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Domain
<# Not Yet Supported ...
,
[Parameter(Mandatory = $false)]
[switch]$v
,
@JohnLBevan
JohnLBevan / SplitXmlFile.ps1
Created September 4, 2017 17:27
Split XML into XML per child element, maintaining original structure
$xml1 = [xml]'<a><b id="3"><c>hello</c></b><b id="4"><c>world</c></b></a>'
$xml1.SelectNodes('/a/b') | %{
$xml2 = New-Object 'System.Xml.XmlDocument'
$root = $xml2.CreateElement("a")
$xml2.AppendChild($root) | out-null
$newNode = $xml2.ImportNode($_, $true)
$root.AppendChild($newNode) | out-null
$xml2.Save("c:\temp\bar_$($newNode.Attributes.GetNamedItem('id').Value).xml")
}
<?xml version="1.0" encoding="UTF-8"?>
<crystal-report-statements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="crystal-report-statements.xsd">
<crystal-statement name="REPPRINTED_STRETF">
<sql-command IsUnique="0">UPDATE R5TRANSACTIONS SET TRA_PRINTED = N'+'
where TRA_code = :cCode1
and TRA_RSTATUS = N'R'</sql-command>
<sql-parameter id="1">:cCode1</sql-parameter>
</crystal-statement>
<crystal-statement name="REPPRINTED_STRCVF">
<sql-command IsUnique="0">UPDATE R5TRANSACTIONS SET TRA_PRINTED = N'+'
@JohnLBevan
JohnLBevan / ShowColumnUsage.sql
Last active August 10, 2017 07:54
Determine which fields are used by specific types of row (i.e. based on a grouping of like values in columns, see which columns have all values set to null, vs which are populated)
declare @tableName sysname = 'ImageLibrary'
, @GroupByColumns nvarchar(max) = 'PictureType' --comma separated list
, @sql nvarchar(max)
select @sql = coalesce(@sql + ', ', 'select ' + coalesce(nullif(@GroupByColumns,'') + ', ','') + 'count(1) cnt, ' )
+ char(10) + 'case when max(' + quotename(name) + ') is null then 0 else 1 end ' + quotename(name)
from sys.columns
where object_id = object_id(@tableName)
set @sql = @sql
+ char(10) + 'from ' + quotename(@tableName)
+ coalesce(char(10) + 'group by ' + nullif(@GroupByColumns,'') + '','')
@JohnLBevan
JohnLBevan / Convert-CorruptCodePageString.ps1
Created August 9, 2017 17:17
Detect corrupted data due to bad encodings in database (or a given string) and suggest the correct value. Based on code from https://stackoverflow.com/questions/10484833/detecting-bad-utf-8-encoding-list-of-bad-characters-to-sniff
Clear-Host
function Invoke-SQLQuery {
[CmdletBinding(DefaultParameterSetName = 'ByQuery')]
param (
[Parameter(Mandatory = $true)]
[string]$DbInstance
,
[Parameter(Mandatory = $true)]
[string]$DbCatalog
@JohnLBevan
JohnLBevan / Remove-ShareAccess.ps1
Created August 3, 2017 16:32
Remove Share Permissions. We had an issue where a user was mistakenly given access to a top level share and those permissions were inherited; then those permissions were removed from the top, but the process was cancelled before this change had propagated (not sure why this works; assume there's more to this story than I was told)... The below c…
function Remove-ShareAccess {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$Domain
,
[Parameter(Mandatory = $true)]
[string]$Username
,
[Parameter(Mandatory = $true)]
@JohnLBevan
JohnLBevan / SPWho2ShowBlockChain.sql
Created July 28, 2017 13:13
sp_who2; show block chain
declare @sp_who2 table
(
spid int
, [status] nvarchar(1000) null
, [login] sysname null
, hostname sysname null
, blkby sysname null
, dbname sysname null
, command nvarchar(1000) null
@JohnLBevan
JohnLBevan / Parse-FileZillaLogs.ps1
Last active July 12, 2017 15:00
Simple FileZilla Server Log Parser Regex
function Parse-FileZillaLogs {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$Path
,
[Parameter()]
[string]$Filter = '*.log'
)
begin {
#should just work... unless it doesn't...
function Get-FormsAuthSession {
[CmdletBinding()]
param (
$url = 'http://example.com'
,$usernameFieldName = 'txtUsername'
,$passwordFieldName = 'txtPassword'
,$cred = (Get-Credential)
)