Skip to content

Instantly share code, notes, and snippets.

View hansgafriedzal's full-sized avatar

Hans hansgafriedzal

View GitHub Profile
$h = 'C:\windows\system32\drivers\etc\hosts'
@(
"127.0.0.1 `t dev.localdev.info"
) | % {
(cat $h) + $_ | Out-File $h -Encoding ascii
}
# yyyyMMdd_HHmmsszzz | % Replace ':'
dir -File | % {
$d = $_.BaseName.Substring(0,8)
md $d -ea 0
move $_.FullName $d
}
$dir = dir -Directory
@hansgafriedzal
hansgafriedzal / Get-PathCollapsed.ps1
Last active November 27, 2024 16:36
Given a list of paths, remove all paths whose parent is already in the list.
<#
.SYNOPSIS
Given a list of paths, remove all paths whose parent is already in the list.
#>
function Get-PathCollapsed
{
param (
[string[]] $Paths
)
dir | % {
$exif = exiftool -G2 -json $_.FullName | ConvertFrom-Json
$exif.'Camera:Model'
}
$site = Get-SPSite http://site.local/
$query = New-Object -TypeName Microsoft.SharePoint.SPAuditQuery($site)
$query.RowLimit = 10
$query.SetRangeStart((Get-Date).Date)
$query.AddEventRestriction([Microsoft.SharePoint.SPAuditEventType]::ChildMove)
$site.Audit.GetEntries($query) | Out-GridView
@hansgafriedzal
hansgafriedzal / Get-AzureADUserOnPremisesExtensionAttributes.ps1
Last active November 28, 2024 09:37
Gets the service principal auth token using AzureAD module and then get the user and its custom attribute.
param
(
[Parameter(Mandatory = $true)][string]$clientId,
[Parameter(Mandatory = $true)][string]$tenantId,
[Parameter(Mandatory = $true)][string[]]$upn
)
Install-Module AzureAD
Update-Module AzureAD
Get-Process | select name, cpu, workingset64 | group name | %{
[pscustomobject] @{
name = $_.Name
WorkingSet64 = [math]::round(($_.group | measure workingset64 -Sum | % sum)/1gb, 2)
}
} | sort workingset64 -Descending | select -first 10
= (Path as text) => let
Custom1 = Csv.Document(File.Contents(Path),[Delimiter=",", Columns=17, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Custom1, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"timeStamp", type text}, {"elapsed", Int64.Type}, {"label", type text}, {"responseCode", Int64.Type}, {"responseMessage", type text}, {"threadName", type text}, {"dataType", type text}, {"success", type logical}, {"failureMessage", type text}, {"bytes", Int64.Type}, {"sentBytes", Int64.Type}, {"grpThreads", Int64.Type}, {"allThreads", Int64.Type}, {"URL", type text}, {"Latency", Int64.Type}, {"IdleTime", Int64.Type}, {"Connect", Int64.Type}}),
#"Extracted First Characters" = Table.TransformColumns(#"Changed Type", {{"timeStamp", each Text.Start(_, 10), type text}}),
#"Added Custom" = Table.AddColumn(#"Extracted First Characters", "Custom", each #datetime(1970,1,1,0,0,0) + #duration(0,8,0,N
$path = 'log.csv'
cat $path | select -First 1 > out.csv
cat $path | select -skip 1 | where {
$log = $_.Split(',')
$ts = [long] $log[0]
$elapsed = [long] $log[1]
Write-Progress -Activity $ts
$elapsed -gt 7000
} | tee -FilePath .\out.csv -Append

Remove domain from URL

=RIGHT(A1, LEN(A1) - SEARCH(CHAR(127), SUBSTITUTE(A1, "/", CHAR(127), 3)))
  • Input: https://gist.github.com/hello/world/
  • Output: hello/world

Description:

  1. SUBSITUTE() replaces the 3rd slash with a dummy i.e., NBSP (non-breaking space) which is the 127th character in the ANSI set.
  2. SEARCH() returns the location of the dummy.