Windows PowerShell运行中-示例问题

时间:2018-12-06 16:54:29

标签: windows powershell

教科书:运行中的Windows PowerShell (E3,2017年)-第2和3页。

执行下面的以下三个代码块,分别会产生随后的三个错误。

我认识到这可能是一个直截了当的解决方案,但是这是PowerShell的新手,而我花大量时间试图理解为什么在这个过早的学习阶段入门示例不起作用的原因令人沮丧。

如果能提供帮助,请先谢谢您。

可根据要求提供更多详细信息。

代码块1:

Get-ChildItem -Path $env::windir\*.log |
Select-String -List error |
Format-Table Path,LineNumber -AutoSize

代码块1-错误:

Get-ChildItem : Second path fragment must not be a drive or UNC name.
Parameter name: path2
At line:1 char:1
+ Get-ChildItem -Path $env::windir\*.log |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (C:\Windows\system32:String) [Get-ChildItem], ArgumentException
    + FullyQualifiedErrorId : DirArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand

代码块2:

([xml] [System.Net.WebClient]::new().
DownloadString('https://blogs.msdn.microsoft.com/powershell/feed.aspx')).
RSS.Channel.Item |
Format-Table table,link

代码块2-错误:

Method invocation failed because [System.Net.WebClient] does not contain 
a method named 'new'.
At line:1 char:1
+ ([xml] [System.Net.WebClient]::new().
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

代码块3:

using namespace System.Windows.Forms
$Form = [Form] @{
Text = 'My First Form'
}
$button = [Button] @{
Text = 'Push Me!'
Dock = 'Fill'
}
$button.add_click{
$form.Close()
}
$form.Controls.Add($button)
$form.ShowDialog()

代码块3-错误:

At line:1 char:1
+ using assembly System.Windows.Forms
+ ~~~~~
The 'using' keyword is not supported in this version of the language.
At line:2 char:1
+ using namespace System.Windows.Forms
+ ~~~~~
The 'using' keyword is not supported in this version of the language.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ReservedKeywordNotAllowed

0 个答案:

没有答案