开发者

PowerShell: Remove Trailing "..."

I'm trying to create a powershell script that will get the list of scheduled tasks. I've got far enough to get a complete list of tasks, however I need to remove the trailing "..."

How do you do that?

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

Output:

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                            ...
Conf开发者_如何学编程igNotification                       ...
Calibration Loader                       ...


Don't use Format-Table (ft) since it will attempt to fit the data within the number of columns available in the console and you've limited the space for the "line" column to 44 chars. Try this instead:

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


$tasks | Select-String -pattern "Disabled" | ForEach-Object
{ $_ -replace "Disabled", ""} | ForEach-Object { $_ -replace "Could not start",
""} | ForEach-Object { $_.Trim() }

Does exactly as I wanted.


I'm not sure what $tasks has in it so I wrote this based off get-service but it should work in your case:

$tasks | Select-String -pattern "Disabled" | ft @{Expression=
{$intLength = 44; if($_.Line.length -lt $intLength) {$intLength=$_.Line.length} $_.Line.substring(0,$intLength)};Label="Line"}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜