gpt4 book ai didi

powershell - 我不能 'Out-File' 我的整个循环只有一行

转载 作者:行者123 更新时间:2023-12-03 10:03:31 29 4
gpt4 key购买 nike

我创建了一个随 secret 码生成器,我需要将所有 10 个输出输出到一个 .txt 文件中

但我现在只有 1 行输出。

for ($i=1; $i -le 10; $i++){
$caps = [char[]] "ABCDEFGHJKMNPQRSTUVWXY"
$lows = [char[]] "abcdefghjkmnpqrstuvwxy"
$nums = [char[]] "2346789"
$spl = [char[]] "!@#$%^&*?+"

$first = $lows | Get-Random -count 1;
$second = $caps | Get-Random -count 1;
$third = $nums | Get-Random -count 1;
$forth = $lows | Get-Random -count 1;
$fifth = $spl | Get-Random -count 1;
$sixth = $caps | Get-Random -count 1;

$pwd = [string](@($first) + @($second) + @($third) + @($forth) + @($fifth) + @($sixth))
Write-Host $pwd

Out-File .\Documents\L8_userpasswords.txt -InputObject $pwd

}

当我打开 .txt 时,我只看到 1 行输出而不是 10 行。

最佳答案

默认情况下,Out-File 会破坏(覆盖)指定路径(如果存在)。如果文件在脚本执行之前不存在,使用 -Append 附加到文件:

Out-File .\Documents\L8_userpasswords.txt -InputObject $pwd -Append

请注意,每次运行脚本时,这都会附加到文件中。如果您希望每次都重新创建文件,请在进入 for 循环之前检查是否存在并将其删除:

$file = ".\L8_userpasswords.txt"
if (Test-Path -Path $file -PathType Leaf) {
Remove-Item $file
}
for ($i=1; $i -le 10; $i++){
...

关于powershell - 我不能 'Out-File' 我的整个循环只有一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22382672/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com