Skip to content

Instantly share code, notes, and snippets.

View Sarafian's full-sized avatar

Alex Sarafian Sarafian

View GitHub Profile
@Sarafian
Sarafian / ConvertFrom-XML.ps1
Last active November 13, 2020 11:11
XML to JSON (CODIT)
<#
.SYNOPSIS
Converts [xml] objects to memory object
.DESCRIPTION
Converts [xml] objects to memory object with some control over attribute values and property names
.PARAMETER AttributesGroupProperty
Name of property for values read from node attributes
.PARAMETER LowerCasePropertyNames
Convert all property names lower case
.EXAMPLE
@Sarafian
Sarafian / Install.sh
Created January 21, 2020 10:15
Install Ruby and Jenkins on Visual Studio Online environment.
# Install ruby-build
sudo apt install ruby-build -y
# Install Ruby 2.4.0
rbenv install 2.4.0
# Add rbenv initialization to profile
echo 'export PATH="$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
@Sarafian
Sarafian / Filtering.ps1
Created April 21, 2019 18:13
Samples for tweet asking for name inspiration
<# Goal
In between null and arrays need to be transparently resolved
Filter an in memory typed structure generated from the followign xml
example expression dataElementsMaster.dataElementsIndiv.serviceRequest.ssr.type -eq CTCE
instead of
$pnrRetrieveResponse.dataElementsMaster.dataElementsIndiv | Where-Object {
($_.serviceRequest -ne $null) -and
($_.serviceRequest.ssr -ne $null) -and
($_.serviceRequest.ssr.type -eq "CTCE")
}
@Sarafian
Sarafian / Disconnect-RemoteSessions.ps1
Created May 10, 2018 09:21
Disconnect/Terminate remote sessions
<#
.Synopsis
Disconnects your user from remote computers
.DESCRIPTION
This scripts uses the quser and qwinsta to scan for session on a remote computer and then rwinsta to disconnect it
.NOTES
.LINK
@Sarafian
Sarafian / Disconnect-RemoteSessions.ps1
Last active June 15, 2018 12:21
This scripts uses the quser to scan for session on a remote computer and then rwinsta to disconnect it
<#
.Synopsis
Disconnects your user from remote computers
.DESCRIPTION
This scripts uses the quser to scan for session on a remote computer and then rwinsta to disconnect it
.NOTES
.LINK
@Sarafian
Sarafian / Docker-Prune.txt
Last active May 3, 2018 13:44
How to remove unused Docker containers and images. Copy from comment in [gist](https://gist.github.com/ngpestelos/4fc2e31e19f86b9cf10b#gistcomment-1940551)
docker container prune # Remove all stopped containers
docker volume prune # Remove all unused volumes
docker image prune # Remove unused images
docker system prune # All of the above, in this order: containers, volumes, images
@Sarafian
Sarafian / Export-ModuleDocumentation.ps1
Created January 16, 2017 12:06
Export a module's documentation in markdown
#requires -module platyPS
<#
.SYNOPSIS
Export a module's documentation in markdown.
.DESCRIPTION
Export a module's documentation in markdown.
@Sarafian
Sarafian / New-RandomPassword.ps1
Last active May 2, 2017 09:42
Generate new random password with PowerShell
function New-RandomPassword
{
param(
[Parameter(Mandatory=$false)]
[int]$Length=8
)
begin {
}
@Sarafian
Sarafian / Test-PesterInvocation.ps1
Created April 27, 2017 09:12
Check if powershell code is executed as part of a Pester test
function Test-PesterInvocation {
$commandStack=Get-PSCallStack | Select-Object -ExpandProperty Command
#region Render
<#
for($i=$commandStack.Count-1;$i -ge 0;$i--)
{
$prefix="+".PadRight($commandStack.Count-1-$i,'-')
Write-Host ($prefix+$commandStack[$i])
}
@Sarafian
Sarafian / Start-MyRemoteDesktopConnection.ps1
Created April 11, 2017 06:46
Start PowerShell ISE or execute scripts as if the Windows System account was
<#
.Synopsis
Starts a remote desktop connection
.DESCRIPTION
Starts a remote desktop connection
.EXAMPLE
Start-MyRemoteDesktopConnection
#>
function Start-MyAsSystem
{