Removing Unused Indexes

Removing Unused Indexes.

This is some thought provoking information. For those of you who add indexes to everything…

Advertisements

Powershell – Remove Columns From Fixed Width Files

Here is something that works incredibly well.

This is a quick description enter the file names you wish to use. Powershell then reads in all the data and creates a new file by joining all the elements in the char array to a string. It then takes the row and ends it in a carriage return / line feed. Finally it saves the file.

$fileName = c:\file.txt
$newFileName = c:\newfile.txt
$newFile = “”
Get-Content -Path $filename | ForEach-Object{$newFile += [string]::Join(“”,$_[0..149] + $_[154..777]) + “`r`n”}
$newfile > $newFileName

Powershell – Top Command

For those of you who love the top command in Linux…

 

function Get-Top{

#######################################

##Get-Top

##

##Written By: John Glasgow

#######################################

<#

.SYNTAX

Get-Top [-delay interval] [-pid pid_number]

 

.SYNOPSIS

Emulates the top command from Linux/Unix.

 

.EXAMPLE

To set delay of 5 seconds.

Get-Top -delay 5

 

.EXAMPLE

To watch a particular process.

Get-Top -pid 4408

#>

$delay = 2

$proc = -1

 

for($i = 0; $i -lt $args.Count; $i += 1){

if( $args[$i] -ilike “-d*” ){

$i++

$delay = $args[$i]

}

if( $args[$i] -ilike “-p*” ){

$i++

$proc = $args[$i]

}

if( $args[$i] -ilike “-q*” ){

$i++

$delay = 0

}

}

 

while ($true){

Clear-Host

if($proc -gt 0){Get-Process | Sort-Object -Descending cpu | Where-Object{ $_.Id -eq $proc } | Format-Table}

else{Get-Process | Sort-Object -Descending cpu | Select-Object -First 20 | Format-Table}

Start-Sleep -Seconds $delay

}

}

Set-Alias top Get-Top