@@ -417,11 +417,9 @@ function Add-Persistence
417417 [String ]
418418 $PersistenceScriptName = ' Update-Windows' ,
419419
420- [ValidateNotNullOrEmpty ()]
421420 [String ]
422421 $PersistentScriptFilePath = " $PWD \Persistence.ps1" ,
423422
424- [ValidateNotNullOrEmpty ()]
425423 [String ]
426424 $RemovalScriptFilePath = " $PWD \RemovePersistence.ps1" ,
427425
@@ -446,35 +444,49 @@ function Add-Persistence
446444 throw ' You provided invalid user-level persistence options.'
447445 }
448446
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
450460 $Leaf = Split-Path $PersistentScriptFilePath - Leaf - ErrorAction Stop
451461 $PersistentScriptFile = ' '
452462 $RemovalScriptFile = ' '
453463
454- if ($Path -eq ' ' )
464+ if ($PersistentPath -eq ' ' )
455465 {
466+ # i.e. Only a file name was provided implying $PWD
456467 $PersistentScriptFile = " $ ( $PWD ) \$ ( $Leaf ) "
457468 }
458469 else
459470 {
460- $PersistentScriptFile = " $ ( $ Path) \$ ( $Leaf ) "
471+ $PersistentScriptFile = " $ ( Resolve- Path $PersistentPath ) \$ ( $Leaf ) "
461472 }
462473
463- $Path = Split-Path $RemovalScriptFilePath - ErrorAction Stop
474+ $RemovalPath = Split-Path $RemovalScriptFilePath - ErrorAction Stop
464475 $Leaf = Split-Path $RemovalScriptFilePath - Leaf - ErrorAction Stop
465- if ($Path -eq ' ' )
476+ if ($RemovalPath -eq ' ' )
466477 {
478+ # i.e. Only a file name was provided implying $PWD
467479 $RemovalScriptFile = " $ ( $PWD ) \$ ( $Leaf ) "
468480 }
469481 else
470482 {
471- $RemovalScriptFile = " $ ( $ Path) \$ ( $Leaf ) "
483+ $RemovalScriptFile = " $ ( Resolve- Path $RemovalPath ) \$ ( $Leaf ) "
472484 }
473485
474486 if ($PSBoundParameters [' FilePath' ])
475487 {
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 ))
478490 }
479491 else
480492 {
0 commit comments