Skip to content

Instantly share code, notes, and snippets.

View AlexSen's full-sized avatar
😏

Alex AlexSen

😏
View GitHub Profile
function Get-FileType {
<#
.SYNOPSIS
Try to get the file type based on it's file signature.
.DESCRIPTION
This function uses Get-FileSignature by Boe Prox and a list of
known file signatures to try to find the file type of a given file.
.EXAMPLE
Get-FileType c:\path\to\file.pdf
.LINK
@AlexSen
AlexSen / Copy-PnPModernPages.ps1
Created May 22, 2019 12:22
PnP SharePoint - copy Modern site page to another site
Param(
[Parameter(ParameterSetName = "Inputparameter",Position=1,Mandatory=$True)]
[String]$sharepointUrl,
[Parameter(ParameterSetName = "Inputparameter",Position=2,Mandatory=$True)]
[String]$targeturl,
[Parameter(ParameterSetName = "Inputparameter",Position=3,Mandatory=$True)]
[String]$Sourceurl,
[Parameter(ParameterSetName = "Inputparameter",Position=4,Mandatory=$True)]
[String]$SourceDocumentLib,
[Parameter(ParameterSetName = "Inputparameter",Position=4,Mandatory=$True)]
@AlexSen
AlexSen / Start-FileSystemWatcher.ps1
Created January 8, 2019 15:42 — forked from mobzystems/Start-FileSystemWatcher.ps1
Using a FileSystemWatcher from PowerShell
# Start-FileSystemWatcher.ps1 - File System Watcher in Powershell.
# Brought to you by MOBZystems, Home of Tools
# https://www.mobzystems.com/code/using-a-filesystemwatcher-from-powershell/
[CmdletBinding()]
Param(
# The path to monitor
[Parameter(Mandatory=$true, Position=0)]
[string]$Path,
# Monitor these files (a wildcard)
# Get all files/agrs passed to the script
$SourceFiles = $PsBoundParameters.Values + $args
$FilesInfo = @()
ForEach($FileFullPath in $SourceFiles)
{
# Get file directory
$File = Get-Item -LiteralPath $FileFullPath
# Calculate file MD5
Function Get-MultipartRequestParameters(){
<#
.SYNOPSIS
Function returnds object withi contains parameters needed for invoking CmdLets like Invoke-WebRequest or Invoke-RESTRequest
.DESCRIPTION
Function returnds object withi contains parameters needed for invoking CmdLets like Invoke-WebRequest or Invoke-RESTRequest.
Function automatically recognizes file paths in values and determinates it's Content-Type
.EXAMPLE
@AlexSen
AlexSen / Run-ExternalScript.ps1
Created June 3, 2017 13:49
Script prepares arguments for external script, than runs external script and shows output
# Define external script paths and arguments
$ExternalScript_FullPath = "$((Get-Item $MyInvocation.MyCommand.Path).Directory.FullName)\ExternalScript.ps1"
$ExternalScript_Args = @{
$param = $value
}
# Run External Script and save output to variable
Invoke-Expression "$ExternalScript_FullPath @ExternalScript_Args" | Tee-Object -Variable ExternalScript_Output
# Show output
Function Get-DatesByWeekNumber
{
param(
[int]$year = (Get-Date).Year,
[int]$weekOfYear = (Get-Date -UFormat %W)
)
# Get 1st of january of given year
$jan1 = Get-Date("$year-01-01")
@AlexSen
AlexSen / Runbook VM-ShutDown.ps1
Last active October 16, 2018 17:46
Azure PowerShell Runbook script which iterates through Virtual Machines in all Automation Accounts and performs Stop-VM based in case if VM is not active for predefined amount of time
<#
.SYNOPSIS
TBD
.DESCRIPTION
TBD
.URL https://gist.github.com/Forket/39c966cc2576c65e6373721fd345657a
#>