scripts: auto-create log directory in Write-Log
All checks were successful
release / build-and-release (push) Successful in 22s
All checks were successful
release / build-and-release (push) Successful in 22s
C:\Windows\Setup\Scripts\ does not exist on a fresh Windows install. Add New-Item -Force before Add-Content so the first log write creates the directory automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0c4c8d82fa
commit
24882839f3
13 changed files with 13 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ $ErrorActionPreference = "Continue"
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message, [string]$Level = "INFO")
|
param([string]$Message, [string]$Level = "INFO")
|
||||||
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
$line = "[$(Get-Date -Format 'HH:mm:ss')] [$Level] $Message"
|
||||||
|
$null = New-Item -ItemType Directory -Force -Path (Split-Path $LogFile -Parent) -ErrorAction SilentlyContinue
|
||||||
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
Add-Content -Path $LogFile -Value $line -Encoding UTF8
|
||||||
switch ($Level) {
|
switch ($Level) {
|
||||||
"OK" { Write-Host $line -ForegroundColor Green }
|
"OK" { Write-Host $line -ForegroundColor Green }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue