I'll get into this quick, basically, I'm trying to get the output of this function to be sent to a file. The file is creating without an issue but it's always 0 bytes. It's not piping the information through and I don't understand why.
First Attempt
function Get-MD5{
<#
.Synopsis
MD5 file hasher
.Description
Generates the MD5 hash of a file you feed in.
.Example
Get-MD5 -FilePath c:\windows\system32\cmd.exe
#>
Param(
[Parameter(Mandatory=$True)]
[string]$FilePath = "C:\Windows\system32\cmd.exe"
)
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($FilePath))).Replace('-', '')
Write-Host `nFile: $FilePath`nMD5: $hash`n | Out-File -FilePath "D:\AyyInfo\ MD5-%computername%-$(((get-date).ToUniversalTime()).ToString("ddMMyyyy_hhmmss")).txt"
}
Second Attempt
function Get-MD5{
<#
.Synopsis
MD5 file hasher
.Description
Generates the MD5 hash of a file you feed in.
.Example
Get-MD5 -FilePath c:\windows\system32\cmd.exe
#>
Param(
[Parameter(Mandatory=$True)]
[string]$FilePath = "C:\Windows\system32\cmd.exe"
)
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($FilePath))).Replace('-', '')
Write-Host `nFile: $FilePath`nMD5: $hash`n > "D:\AyyInfo\ MD5-%computername%-$(((get-date).ToUniversalTime()).ToString("ddMMyyyy_hhmmss")).txt"
}
Final Attempt
function Get-MD5{
<#
.Synopsis
MD5 file hasher
.Description
Generates the MD5 hash of a file you feed in.
.Example
Get-MD5 -FilePath c:\windows\system32\cmd.exe
#>
Param(
[Parameter(Mandatory=$True)]
[string]$FilePath = "C:\Windows\system32\cmd.exe"
)
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($FilePath))).Replace('-', '')
Out-File -FilePath "D:\AyyInfo\ MD5-%computername%-$(((get-date).ToUniversalTime()).ToString("ddMMyyyy_hhmmss")).txt"
}
Any help would be much appreciated.