gpt4 book ai didi

powershell - PSCustomObject 是否有其显示到控制台的顺序?

转载 作者:行者123 更新时间:2023-12-04 03:34:44 27 4
gpt4 key购买 nike

<分区>

早上好

我非常喜欢从列出的项目返回的值中进行选择。因此,我正准备从 C:\Users 返回的值中进行选择,这些值被输入到 [PSCustomObject] 类型中,但我发现有些不对劲。我可以像这样将选择列到 [PSCustomObject] 中:

[array]$Userlist = Get-ChildItem C:\users | Sort-Object -Property LastWriteTime -Descending
for($i=0; $i -lt $UserList.BaseName.count; $i++){
[PSCustomObject]@{
'Profile Name' = "$($i): $($UserList.BaseName[$i])"
' Full Path ' = $UserList.FullName[$i]
'Modified Time' = $UserList.LastWriteTime[$i]
}
}

#Output:
Profile Name Full Path Modified Time
------------ ------------- -------------
0: Abraham C:\users\Abraham 4/11/2021 10:26:58 PM
1: Public C:\users\Public 3/28/2021 8:51:28 AM

..但是,当我尝试通过在脚本末尾添加 Read-Host 来进行选择时,我首先得到提示:

[array]$Userlist = Get-ChildItem C:\users | Sort-Object -Property LastWriteTime -Descending
for($i=0; $i -lt $UserList.BaseName.count; $i++){
[PSCustomObject]@{
'Profile Name' = "$($i): $($UserList.BaseName[$i])"
' Full Path ' = $UserList.FullName[$i]
'Modified Time' = $UserList.LastWriteTime[$i]
}
}


$ii = Read-Host -Prompt "Enter The Users Number to Delete"
$i = $ii -split " "
""
foreach($profile in $Userlist.baseName[$i]){
""
"Selection: $profile"
}

#output
Enter The Users Number to Delete: 1 <------ Here its asking first before displaying.
Profile Name Full Path Modified Time
------------ ------------- -------------
0: Abraham C:\users\Abraham 4/11/2021 10:26:58 PM
1: Public C:\users\Public 3/28/2021 8:51:28 AM


Selection: Public

我错过了什么吗?为什么在显示顶部对象之前提示我的 Read-Host?我想在选择之前先看看选择,哈哈

是否有显示顺序?

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