@@ -417,11 +417,9 @@ function Add-Persistence
417
417
[String ]
418
418
$PersistenceScriptName = ' Update-Windows' ,
419
419
420
- [ValidateNotNullOrEmpty ()]
421
420
[String ]
422
421
$PersistentScriptFilePath = " $PWD \Persistence.ps1" ,
423
422
424
- [ValidateNotNullOrEmpty ()]
425
423
[String ]
426
424
$RemovalScriptFilePath = " $PWD \RemovePersistence.ps1" ,
427
425
@@ -446,35 +444,49 @@ function Add-Persistence
446
444
throw ' You provided invalid user-level persistence options.'
447
445
}
448
446
449
- $Path = Split-Path $PersistentScriptFilePath - ErrorAction Stop
447
+ $Result = Get-Item $PersistentScriptFilePath - ErrorAction SilentlyContinue
448
+ if ($Result -and $Result.PSIsContainer )
449
+ {
450
+ throw ' You must provide a file name with the PersistentScriptFilePath option.'
451
+ }
452
+
453
+ $Result = Get-Item $RemovalScriptFilePath - ErrorAction SilentlyContinue
454
+ if ($Result -and $Result.PSIsContainer )
455
+ {
456
+ throw ' You must provide a file name with the RemovalScriptFilePath option.'
457
+ }
458
+
459
+ $PersistentPath = Split-Path $PersistentScriptFilePath - ErrorAction Stop
450
460
$Leaf = Split-Path $PersistentScriptFilePath - Leaf - ErrorAction Stop
451
461
$PersistentScriptFile = ' '
452
462
$RemovalScriptFile = ' '
453
463
454
- if ($Path -eq ' ' )
464
+ if ($PersistentPath -eq ' ' )
455
465
{
466
+ # i.e. Only a file name was provided implying $PWD
456
467
$PersistentScriptFile = " $ ( $PWD ) \$ ( $Leaf ) "
457
468
}
458
469
else
459
470
{
460
- $PersistentScriptFile = " $ ( $ Path) \$ ( $Leaf ) "
471
+ $PersistentScriptFile = " $ ( Resolve- Path $PersistentPath ) \$ ( $Leaf ) "
461
472
}
462
473
463
- $Path = Split-Path $RemovalScriptFilePath - ErrorAction Stop
474
+ $RemovalPath = Split-Path $RemovalScriptFilePath - ErrorAction Stop
464
475
$Leaf = Split-Path $RemovalScriptFilePath - Leaf - ErrorAction Stop
465
- if ($Path -eq ' ' )
476
+ if ($RemovalPath -eq ' ' )
466
477
{
478
+ # i.e. Only a file name was provided implying $PWD
467
479
$RemovalScriptFile = " $ ( $PWD ) \$ ( $Leaf ) "
468
480
}
469
481
else
470
482
{
471
- $RemovalScriptFile = " $ ( $ Path) \$ ( $Leaf ) "
483
+ $RemovalScriptFile = " $ ( Resolve- Path $RemovalPath ) \$ ( $Leaf ) "
472
484
}
473
485
474
486
if ($PSBoundParameters [' FilePath' ])
475
487
{
476
- Get-ChildItem $FilePath - ErrorAction Stop
477
- $Script = [IO.File ]::ReadAllText((Resolve-Path $Path ))
488
+ $null = Get-ChildItem $FilePath - ErrorAction Stop
489
+ $Script = [IO.File ]::ReadAllText((Resolve-Path $FilePath ))
478
490
}
479
491
else
480
492
{
0 commit comments