Hi folks.
Was hoping someone to help me out with a powershell script problem. I'm quite new to PS and been trying to put together a script that will check a remote machine for attached printers and mapped drives, then output this to a text file.
I got the script to work at first, but then thought it would be nice to have it ping the machine and if no response let you know it's down. However, I've got stuck trying to put the ping function in. If anyone could shed any light on where I'm going wrong that would be great.
Script looks like this so far:

#Get computer name
#
cls
Function GetCompName {
$Compname =Read-Host "Please enter computer name"
}
# Ping status of computer
#
ForEach($MachineName In $CompName)
{$PingStatus = Gwmi Win32_PingStatus -Filter "Address = 'CompName'" |
Select-Object StatusCode
If ($PingStatus.StatusCode -eq 0) {Function GetInfo}
Else
{Write-Host $MachineName Ping Failed -Fore "Red"}}

#PC Printer Information
Function GetInfo {
$prin = gwmi -computer $compname Win32_Printer | Select-Object DeviceID,DriverName, PortName, Comment | Format-List

#PC drive Information
$drv = gwmi -Computer $compname -Class Win32_MappedLogicalDisk | select Name, ProviderName
}

Write-Output $prin, $drv | Out-File -FilePath c:\Results.txt
Write-Host " "
Write-Host " "

[string]$message = "Results can be found in C:\Results.txt - Press any key to continue..."

Write-Host -NoNewLine $Message

$Host.UI.RawUI.FlushInputBuffer()
do { $key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").Ch aracter } while ([int]$key -eq 0)
Write-Host ""


Thanks