在 XML 文件中,您可以看到 Export-CliXml 如何更改 SecureString 的表示形式并将其转换为十六进制值的列表。在 Windows 上,SecureString 数据已安全加密,并且只有加密数据的人员(并且正在使用该计算机时)才能读取。在 Linux 和 macOS 上并非如此。由于此处缺少 Windows 加密API,因此仅对 SecureString 进行编码而不是加密。
# define your different environments $action = @{ 'Azure' = "$PSScriptRoot\azure.ps1" 'Teams' = "$PSScriptRoot\teams.ps1" 'Office' = "$PSScriptRoot\office.ps1" }
# run a new PowerShell for each environment, and run the # associated "spin-up" script: $action.Keys | ForEach-Object { $path = $action[$_] Start-Process-FilePath powershell -ArgumentList"-noexit -noprofile -executionpolicy bypass -file ""$path""" }
# set the console title bar $host.UI.RawUI.WindowTitle = 'Administering Office' # read the common credential from file $cred = Import-Clixml-Path"$PSScriptRoot\secret.xml"
[Enum]::GetNames([System.Environment+SpecialFolder]) | ForEach-Object { # ...for each, create a new object with the constant, the associated path # and the code required to get that path [PSCustomObject]@{ Name = $_ Path = [Environment]::GetFolderPath($_) } }