2011-05-31 95 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}