@@ -11,7 +11,7 @@ function Import-HashData
1111 will result in an error and the import will fail.
1212
1313. PARAMETER Path
14- The target file that contains the Specialized object(s).
14+ The target file that contains the Serialized object(s).
1515
1616. PARAMETER UnsafeMode
1717 If supplied, no you allow any command to be executed in the runspace when the object is deserialized.
@@ -32,28 +32,55 @@ function Import-HashData
3232 Website: www.firstpoint.no
3333 Twitter: @ToreGroneng
3434#>
35- [cmdletbinding ()]
36- Param (
35+ [cmdletbinding (
36+ SupportsShouldProcess = $true ,
37+ ConfirmImpact = ' medium'
38+ )]
39+ Param (
3740 [string ]
3841 $Path
3942 ,
4043 [switch ]
4144 $UnsafeMode
4245)
46+ $f = $MyInvocation.InvocationName
47+ Write-Verbose - Message " $f - START"
48+
4349 if (-not (Test-Path - Path $Path ))
4450 {
4551 Write-Error - Message " Unable to find file [$path ]" - ErrorAction Stop
4652 }
4753
48- $data = Get-Content - Path $path - Encoding UTF8 - Raw - ReadCount 0
54+ Write-Verbose - Message " $f - Importing data from [$path ]"
55+
56+ [string ]$data = Get-Content - Path $path - Encoding UTF8 - Raw - ReadCount 0
57+
4958 if ($UnsafeMode.IsPresent )
5059 {
51- Write-Warning - Message " You are importing persisted data without cheching RestrictedLanguage because you supplied the UnSafeMode switch."
52- $script = [scriptblock ]::Create($data )
53- & $script
60+ # fixme this is a hack
61+ $PreviousConfirmPreference = $ConfirmPreference
62+ $ConfirmPreference = " low"
63+ if ($PScmdlet.ShouldProcess ($path , " Unsafe script invokation" ))
64+ {
65+ $ConfirmPreference = $PreviousConfirmPreference
66+ Write-Warning - Message " You are importing persisted data without cheching RestrictedLanguage because you supplied the UnSafeMode switch."
67+ $script = [scriptblock ]::Create($data )
68+ & $script
69+ }
5470 }
5571 else
5672 {
57- Assert-PersistedData - Data $data - ErrorAction Stop
73+ # fixme this is a hack
74+ $PreviousConfirmPreference = $ConfirmPreference
75+ $ConfirmPreference = " high"
76+
77+ if ($PScmdlet.ShouldProcess ($path , " Safe script invokation" ))
78+ {
79+ $ConfirmPreference = $PreviousConfirmPreference
80+ Write-Verbose - Message " $f - Asserting script content"
81+ Assert-ScriptString - Data $data - ErrorAction Stop
82+ }
5883 }
84+
85+ Write-Verbose - Message " $f - END"
5986}
0 commit comments