Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Hyphens from output

Status
Not open for further replies.

mefanning

MIS
Apr 26, 2010
19
US
I have a script that pulls the SHA1 hash off a file and sends the output to a logfile. Currently the output separates includes hyphens. I'm curious if I can edit the output as it is written to remove the hyphens, or if I need edit the logfile after it has been written to.

$Log = "C:\Temp\Log.txt"

Function Get-Hash{

$file = $Suspect
$algorithm = 'SHA1'


$fileStream = [system.io.file]::eek:penread((resolve-path $file))
$hasher = [System.Security.Cryptography.HashAlgorithm]::create($algorithm)
$hash = $hasher.ComputeHash($fileStream) #$fileStream.close()$fileStream.dispose()

[system.bitconverter]::tostring($hash)

}

get-process | ForEach-Object {$_.Modules} | foreach {

if (!$_.Company)
{$Suspect = $_.FileName
$HashOut = Get-Hash $Suspect
Add-Content $Log ($_.FileName + " " + $HashOut) }
}
 
You just need to remove hyphens?

Here is a simple example. You can use the -replace parameter of any variable to perform this operation.

PS C:\so> $numberswhashes = "12-45--5-5646-","770-97-606-","41124"
PS C:\so> $numberswhashes
12-45--5-5646-
770-97-606-
41124
PS C:\so> $numberswhashes -replace '-',''
124555646
77097606
41124
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top