2011-05-31 108 views
0

我想創建一個PowerShell腳本,它將獲得計劃任務的列表。我已經足夠得到一個完整的任務列表,但我需要刪除尾隨「...」PowerShell:刪除尾隨「...」

你是如何做到這一點?

$tasks | Select-String -pattern "Disabled" | ft @{Expression 
={$_.Line};Label="Line";width=44} 

輸出:

Line 
---- 
AD RMS Rights Policy Template Management ... 
AD RMS Rights Policy Template Management ... 
Proxy         ... 
UserTask         ... 
UserTask-Roam       ... 
Consolidator        ... 
KernelCeipTask       ... 
UsbCeip         ... 
ScheduledDefrag       ... 
Scheduled        ... 
Microsoft-Windows-DiskDiagnosticDataColl ... 
Microsoft-Windows-DiskDiagnosticResolver ... 
Notifications       ... 
WinSAT         ... 
ActivateWindowsSearch     ... 
ConfigureInternetTimeService    ... 
DispatchRecoveryTasks     ... 
ehDRMInit        ... 
InstallPlayReady       ... 
mcupdate         ... 
MediaCenterRecoveryTask     ... 
ObjectStoreRecoveryTask     ... 
OCURActivate        ... 
OCURDiscovery       ... 
PBDADiscovery       ... 
PBDADiscoveryW1       ... 
PBDADiscoveryW2       ... 
PeriodicScanRetry      ... 
PvrRecoveryTask       ... 
PvrScheduleTask       ... 
RecordingRestart       ... 
RegisterSearch       ... 
ReindexSearchRoot      ... 
SqlLiteRecoveryTask      ... 
UpdateRecordPath       ... 
CorruptionDetector      ... 
DecompressionFailureDetector    ... 
HotStart         ... 
LPRemove         ... 
SystemSoundsService      ... 
GatherNetworkInfo      ... 
Background Synchronization    ... 
Logon Synchronization     ... 
AnalyzeSystem       ... 
RacTask         ... 
RegIdleBackup       ... 
WindowsParentalControls     ... 
WindowsParentalControlsMigration   ... 
AutoWake         ... 
GadgetManager       ... 
SessionAgent        ... 
SystemDataProviders      ... 
SR          ... 
Interactive        ... 
IpAddressConflict1      ... 
IpAddressConflict2      ... 
MsCtfMonitor        ... 
SynchronizeTime       ... 
ResolutionHost       ... 
QueueReporting       ... 
BfeOnServiceStartTypeChange    ... 
UpdateLibrary       ... 
ConfigNotification      ... 
Calibration Loader      ... 
+0

這是回答:但不能提交; $ tasks |選擇字符串模式「禁用」| ForEach-Object {$ _ -replace「Disabled」,「」}} | ForEach-Object {$ _ -replace「Could not start」, 「」} | ForEach-Object {$ _。Trim()} – nals 2011-05-31 20:26:31

回答

0

我不知道什麼$任務中有所以我寫了這個基於關閉GET-服務,但它應該工作你的情況:

$tasks | Select-String -pattern "Disabled" | ft @{Expression= 
{$intLength = 44; if($_.Line.length -lt $intLength) {$intLength=$_.Line.length} $_.Line.substring(0,$intLength)};Label="Line"} 
1
$tasks | Select-String -pattern "Disabled" | ForEach-Object 
{ $_ -replace "Disabled", ""} | ForEach-Object { $_ -replace "Could not start", 
""} | ForEach-Object { $_.Trim() } 

完全按照我的意願。

2

請勿使用Format-Table(ft),因爲它會嘗試將數據放入控制檯中可用的列數內,並且已將「行」列的空間限制爲44個字符。試試這個:

$tasks | Select-String -pattern "Disabled" | Foreach {$_.Line}