Add scripts for installing PowerShell
This commit is contained in:
parent
26ef9a12b9
commit
36336e332d
4 changed files with 129 additions and 0 deletions
scripts/Windows/Scripts
|
@ -14,3 +14,49 @@ function ConvertTo-Injection {
|
|||
[System.Convert]::ToBase64String([System.Text.Encoding]::Default.GetBytes($value))
|
||||
)')))"
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes a PowerShell script to a specified location.
|
||||
|
||||
.PARAMETER FileName
|
||||
The name of the file to write the script to.
|
||||
|
||||
.PARAMETER Script
|
||||
The script to write to the file.
|
||||
|
||||
.PARAMETER Replace
|
||||
A value indicating whether the file should be overwritten if it exists.
|
||||
|
||||
.PARAMETER Append
|
||||
A value indicating whether the content should be appended if the file already exists.
|
||||
#>
|
||||
function Write-PSScript {
|
||||
param(
|
||||
[string] $FileName,
|
||||
[string] $Script,
|
||||
[Parameter(ParameterSetName="Replace")]
|
||||
[switch] $Replace,
|
||||
[Parameter(ParameterSetName="Append")]
|
||||
[switch] $Append
|
||||
)
|
||||
|
||||
Import-Module PSScriptAnalyzer;
|
||||
$dirName = Split-Path -Parent $FileName;
|
||||
$content = Invoke-Formatter -ScriptDefinition $Script;
|
||||
$exists = Test-Path -PathType Leaf $FileName;
|
||||
|
||||
if (-not (Test-Path -PathType Container $dirName)) {
|
||||
$null = New-Item -ItemType Directory $dirName;
|
||||
}
|
||||
|
||||
if ($exists -and ($Append.IsPresent)) {
|
||||
Add-Content -Force $FileName "`n$content";
|
||||
} else {
|
||||
if ((-not $exists) -or $Replace.IsPresent) {
|
||||
Set-Content -Force $FileName $content;
|
||||
} else {
|
||||
Write-Host "The file ``$FileName`` already exists!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue