我在C:\Hans\Hans4\
目錄中有一個名爲Eric Clapton - Nothing But The Blues - Full Concert (1994) [HQ].URL
的文件。爲什麼此PowerShell腳本會產生錯誤?
代碼來創建,這是低於(儘管無論發生文件內容的錯誤)
$fileContents = @"
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://example.com/
IDList=
"@
New-Item -Path "C:\Hans\Hans4" `
-Name "Eric Clapton - Nothing But The Blues - Full Concert (1994) [HQ].URL" `
-ItemType "file" `
-Value $fileContents `
-Force
當我運行的我得到一個錯誤
Get-ChildItem 'C:\Hans' -Recurse | Resolve-ShortcutFile > Output.txt
的代碼引用下面
功能如下function Resolve-ShortcutFile {
param(
[Parameter(
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position = 0)]
[Alias("FullName")]
[string]$fileName
)
process {
if ($fileName -like "*.url") {
Get-Content $fileName | Where-Object {
$_ -like "url=*"
} |
Select-Object @{
Name='ShortcutFile'
Expression = {Get-Item $fileName}
}, @{
Name='Url'
Expression = {$_.Substring($_.IndexOf("=") + 1)}
}
}
}
}
這是錯誤消息
Get-Content : An object at the specified path C:\Hans\Hans4\Eric Clapton - Nothing But The Blues - Full Concert (1994) [HQ].URL does not exist, or has been filtered by the -Include or -Exclude parameter. At line:33 char:28 + Get-Content $fileName | Where-Object { + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (System.String[]:String[]) [Get-Content], Exception + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetContentCommand
爲什麼我得到這個錯誤?
對於遊客到這個問題:http://meta.stackoverflow.com/questions/340658/can-someone-help-a-new-guy-to-be-good-in-asking-questions-這裏 –
它不應該是C:\漢斯,但C:\羅馬 – ManOnAMission