Commandlet不显示输出

时间:2017-05-23 17:30:32

标签: powershell sharepoint

我面临一个奇怪的问题。当我运行以下脚本时,我没有获得Get-Child命令行开关的输出。

#Check status of Service Applications.
Write-Output -InputObject "SharePoint Service Application Status -"
Get-SPServiceApplication | select DisplayName,Status

Write-Output -InputObject "SharePoint Logfile Check -"
$logFilter = "WIN-RRAS-" + (Get-Date -Format yyyyMMdd) + "*.log"
Get-ChildItem -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\LOGS" -Filter $logFilter

当我在新的ISE窗口中单独运行最后一个命令行开关(Get-ChildItem)时,它显示正确的输出。

上面代码的输出是 -

PS C:\Users\Administrator> C:\Users\Administrator\Desktop\Checklist.ps1
SharePoint Service Application Status -

DisplayName                                                 Status
-----------                                                 ------
Access Services 2010                                        Online
Secure Store Service                                        Online
PowerPoint Conversion Service Application                   Online
State Service                                               Online
Workflow Service Application                                Online
Project Server Service Application                          Online
PerformancePoint Service Application                        Online
Visio Graphics Service                                      Online
Managed Metadata Service                                    Online
App Management Service                                      Online
Security Token Service Application                          Online
Machine Translation Service                                 Online
Application Discovery and Load Balancer Service Application Online
Usage and Health data collection                            Online
Search Administration Web Service for Hello Search!         Online
Word Automation Services                                    Online
User Profile Service                                        Online
Business Data Connectivity Service                          Online
Access Services                                             Online
Hello Search!                                               Online
SharePoint Logfile Check -















PS C:\Users\Administrator> 

知道出了什么问题吗?

2 个答案:

答案 0 :(得分:0)

我认为它可能是一个未正确设置的变量。如果它在新的单独ISE中工作,则表示您当前使用的变量中使用的某些变量未更新或清除。

我看不到任何使用的变量,这会产生奇怪的错误。那么也许你玩过一些环境变量/设置?

当我遇到这样的问题时,我通常会重新启动我的ISE并重新加载脚本。 看看这有帮助吗?

答案 1 :(得分:0)

获取输出(请参阅对象不具有&#34; DisplayName&#34;以及&#34;状态&#34;的所有行)?< / p>

问题是您已经专门告诉PowerShell要显示哪些列(即Select DisplayName, Status),但是第二组对象没有相同的属性,因此这些列只是空白。

如果您只想将两组对象输出到屏幕,则可以在每个对象之后使用| Out-Default

#Check status of Service Applications.
Write-Output -InputObject "SharePoint Service Application Status -"
Get-SPServiceApplication | select DisplayName, Status | Out-Default

Write-Output -InputObject "SharePoint Logfile Check -"
$logFilter = "WIN-RRAS-" + (Get-Date -Format yyyyMMdd) + "*.log"
Get-ChildItem -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\LOGS" -Filter $logFilter | Out-Default

无论如何,关键在于它纯粹是显示问题。您也可以不使用Select语句 - 默认情况下PowerShell会切换到第二组对象不具有相同属性时的列表格式。

正在输出对象,但是在没有任何内容显示的表格中。

更好的选择可能是更改输出对象的属性,使它们(某些)具有相同的名称:

#Check status of Service Applications.
Write-Output -InputObject "SharePoint Service Application Status -"
Get-SPServiceApplication |
    Select @{Label="Name"; Expr={$_.DisplayName}}, 
           @{Label="Last"; Expr={$_.Status}}

Write-Output -InputObject "SharePoint Logfile Check -"
$logFilter = "WIN-RRAS-" + (Get-Date -Format yyyyMMdd) + "*.log"
Get-ChildItem -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\LOGS" -Filter $logFilter | 
    Select Name, @{ Label="Last"; Expr={$_.LastWriteTime}}, Length, FullName