Now, when it is time to use the secrets, you need a way to convert secure strings back to plain text. This is what this script does: 现在,当需要使用这些机密信息时,您需要一种将安全字符串转换回纯文本的方法。此脚本的操作:
1 2 3 4 5 6 7
$hash = Import-Clixml-Path$Path # important: MUST cast $keys to [string[]] or else you cannot modify the hash # in the loop: [string[]]$keys = $hash.Keys $keys | ForEach-Object { $hash[$_] = [PSCredential]::new('xyz', $hash[$_]).GetNetworkCredential().Password }
Name ConfirmImpact SupportsShouldProcess -------------------------------------- Get-Random Medium False Remove-Item Medium True Stop-Process Medium True
PS> Get-Command-Verb Remove | Get-ConfirmInfo | Where-Object ConfirmImpact -eq High
Name ConfirmImpact SupportsShouldProcess -------------------------------------- Remove-CIAccessControlRule High True Remove-CIVApp High True Remove-CIVAppNetwork High True Remove-CIVAppTemplate High True Remove-BCDataCacheExtension High True Remove-ClusterAffinityRule High True Remove-ClusterFaultDomain High True (...)
默认情况下,当 $ConfirmImpact 设置为 “High“ 时,PowerShell 将在你运行设置了 ConfirmImpact 为 High 的cmdlet 或函数时自动要求确认(所以你只会在运行像 AD 账户这样不能轻易恢复的东西的 cmdlets 时看到确认对话框弹出)。
作为用户,您可以调整这个风险缓解系统。如果你在一个十分敏感的生产系统上工作,你可能想把 $ConfirmPreference 降低到 Medium 或甚至 Low,以在运行 PowerShell 命令或脚本时获得更多的确认。当设置为 “Low“时,即使创建一个新文件夹也会触发自动确认:
1 2 3 4 5 6 7 8 9 10
PS> $ConfirmPreference = 'Low'
PS> New-Item-Path c:\testfolder
Confirm Are you sure you want to perform this action? Performing the operation "Create File" on target "Destination: C:\testfolder". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):