Moving to a new style guide for PowerShell scripts
Using this: https://poshcode.gitbooks.io/powershell-practice-and-style/
This commit is contained in:
parent
1e41954f62
commit
87ac27b5cc
1 changed files with 41 additions and 41 deletions
|
|
@ -3,69 +3,69 @@
|
||||||
## Init ##
|
## Init ##
|
||||||
#Requires -Version 3.0
|
#Requires -Version 3.0
|
||||||
#Requires -RunAsAdministrator
|
#Requires -RunAsAdministrator
|
||||||
clear
|
Clear-Host
|
||||||
$host.UI.RawUI.WindowTitle = "Wizard Kit: Windows PE Build Tool"
|
$Host.UI.RawUI.WindowTitle = "Wizard Kit: Windows PE Build Tool"
|
||||||
$wd = $(Split-Path $MyInvocation.MyCommand.Path)
|
$WD = $(Split-Path $MyInvocation.MyCommand.Path)
|
||||||
$bin = (Get-Item $wd -Force).Parent.FullName
|
$Bin = (Get-Item $WD -Force).Parent.FullName
|
||||||
$root = (Get-Item $bin -Force).Parent.FullName
|
$Root = (Get-Item $Bin -Force).Parent.FullName
|
||||||
$tmp = "{0}\tmp" -f $bin
|
$Temp = "{0}\tmp" -f $Bin
|
||||||
$errors = 0
|
$Errors = 0
|
||||||
pushd "$wd"
|
Push-Location "$WD"
|
||||||
$host.UI.RawUI.BackgroundColor = "black"
|
$Host.UI.RawUI.BackgroundColor = "black"
|
||||||
$host.UI.RawUI.ForegroundColor = "white"
|
$Host.UI.RawUI.ForegroundColor = "white"
|
||||||
$progressPreference = 'silentlyContinue'
|
$ProgressPreference = 'silentlyContinue'
|
||||||
# clear
|
# Clear-Host
|
||||||
foreach ($v in @('SystemDrive', 'USERPROFILE', 'DISMRoot', 'BCDBootRoot', 'ImagingRoot', 'OSCDImgRoot', 'WdsmcastRoot')) {
|
foreach ($Var in @('SystemDrive', 'USERPROFILE', 'DISMRoot', 'BCDBootRoot', 'ImagingRoot', 'OSCDImgRoot', 'WdsmcastRoot')) {
|
||||||
write-host ('{0}: {1}' -f $v, (gci env:$v).value)
|
Write-Host ('{0}: {1}' -f $Var, (Get-ChildItem Env:$Var).Value)
|
||||||
}
|
}
|
||||||
write-host ""
|
Write-Host ""
|
||||||
write-host ("wd: {0}" -f $wd)
|
Write-Host ("wd: {0}" -f $WD)
|
||||||
write-host ("bin: {0}" -f $bin)
|
Write-Host ("bin: {0}" -f $Bin)
|
||||||
write-host ("root: {0}" -f $root)
|
Write-Host ("root: {0}" -f $Root)
|
||||||
write-host ("tmp: {0}" -f $tmp)
|
Write-Host ("tmp: {0}" -f $Temp)
|
||||||
read-host "Bananas?"
|
Read-Host "Bananas?"
|
||||||
exit
|
exit
|
||||||
|
|
||||||
## Functions ##
|
## Functions ##
|
||||||
function download-file {
|
function Download-File {
|
||||||
param ([String]$path, [String]$name, [String]$url)
|
param ([String]$Path, [String]$Name, [String]$Url)
|
||||||
$outfile = "{0}\{1}" -f $path, $name
|
$OutFile = "{0}\{1}" -f $Path, $Name
|
||||||
|
|
||||||
Write-Host ("Downloading: {0}" -f $name)
|
Write-Host ("Downloading: {0}" -f $Name)
|
||||||
New-Item -Type Directory $path 2>&1 | Out-Null
|
New-Item -Type Directory $Path 2>&1 | Out-Null
|
||||||
try {
|
try {
|
||||||
invoke-webrequest -uri $url -outfile $outfile
|
Invoke-Webrequest -Uri $Url -OutFile $OutFile
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host (" ERROR: Failed to download file." ) -foregroundcolor "Red"
|
Write-Host (" ERROR: Failed to download file." ) -ForegroundColor "Red"
|
||||||
$errors += 1
|
$Errors += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function find-dynamic-url {
|
function Find-DynamicUrl {
|
||||||
param ([String]$source_page, [String]$regex)
|
param ([String]$SourcePage, [String]$RegEx)
|
||||||
$d_url = ""
|
$Url = ""
|
||||||
|
|
||||||
# Get source page
|
# Get source page
|
||||||
invoke-webrequest -uri $source_page -outfile "tmp_page"
|
Invoke-Webrequest -Uri $SourcePage -OutFile "tmp_page"
|
||||||
|
|
||||||
# Search for real url
|
# Search for real url
|
||||||
$d_url = Get-Content "tmp_page" | Where-Object {$_ -imatch $regex}
|
$Url = Get-Content "tmp_page" | Where-Object {$_ -imatch $RegEx}
|
||||||
$d_url = $d_url -ireplace '.*(a |)href="([^"]+)".*', '$2'
|
$Url = $Url -ireplace '.*(a |)href="([^"]+)".*', '$2'
|
||||||
$d_url = $d_url -ireplace ".*(a |)href='([^']+)'.*", '$2'
|
$Url = $Url -ireplace ".*(a |)href='([^']+)'.*", '$2'
|
||||||
|
|
||||||
# Remove tmp_page
|
# Remove tmp_page
|
||||||
Remove-Item "tmp_page"
|
Remove-Item "tmp_page"
|
||||||
|
|
||||||
return $d_url
|
return $Url
|
||||||
}
|
}
|
||||||
function wk_pause {
|
function WK-Pause {
|
||||||
param([string]$message = "Press Enter to continue... ")
|
param([string]$Message = "Press Enter to continue... ")
|
||||||
Write-Host $message
|
Write-Host $Message
|
||||||
$x = read-host
|
Read-Host
|
||||||
}
|
}
|
||||||
|
|
||||||
## Build ##
|
## Build ##
|
||||||
# TODO #
|
# TODO #
|
||||||
|
|
||||||
## Done ##
|
## Done ##
|
||||||
popd
|
Pop-Location
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue