私は会社の疑似検索エンジンを作成しています。私は戻って私にただ一つの曲を与えるまでコンテンツを表示し、選択することができます。あなたはその1曲を選択しようとすると返されるエラーは、次のとおりです。
1個のpowershellスクリプトのリターン1を選択できません
$SearchInput = Read-Host "Enter song name here:"
$Items = Get-ChildItem C:\Users\adammcgurk\Desktop\Songs -Recurse -Filter *$SearchInput*
$Index = 1
$Count = $Items.Count
foreach ($Item in $Items) {
$Item | Add-Member -MemberType NoteProperty -Name "Index" -Value $Index
$Index++
}
$Items | Select-Object Index, Name | Out-Host
$Input = Read-Host "Select an item by index number (1 to $Count)"
$Selected = $Items[$Input - 1]
Write-Host "You have selected $Selected"
最終的な目標はことです:
Unable to index into an object of type System.IO.FileInfo.
At C:\Users\adammcgurk\Documents\WorkOnSearch.ps1:83 char:20
+$Selected = $Items[ <<<< $Input - 1]
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : CannotIndex
は、問題のコードの一部です。 1つだけが返されたときに1つの曲を選択することができます。何か助けてくれてありがとう!
ありがとうございました!私は$ Itemsをチェックすることにしました。私も変数を変更しました –