各位早安,
我非常喜欢从列出的项目返回的值中进行选择。因此,我正在从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
在脚本末尾添加 a 来进行选择时,我首先得到该提示:
[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
在显示顶部对象之前提示我?在我选择大声笑之前我想看看选择
是否有显示顺序?