Output a script to a text file

param (
#Invoke-Command -Computername $Computername -ScriptBlock {
#Determine Operating System Information and Output only Name,BuildNumber,Version
get-ciminstance -class win32_operatingsystem | format-list Name,BuildNumber,version

#Determine Processor Information and Output only Device ID, Name, MaxClockSpeed
get-ciminstance -class CIM_processor | format-list DeviceID,Name,MaxClockSpeed

#Determine IP Address Configuration
get-ciminstance win32_networkadapterconfiguration | format-table ipaddress,subnetmask,dhcp,defaultgateway

#Acquire DNS Client Server address and output it
Get-DnsClientServerAddress | format-list ServerAddresses

#Determine the amount of system memory in GB
get-ciminstance win32_computersystem | foreach {$_.TotalPhysicalMemory /1GB}

#Determine the amount of of free space (GB) for the c:\ drivey
Get-CimInstance -ClassName cim_logicaldisk | Where-Object {$_.FreeSpace} |
Select-Object @{n='FreeSpace';exp={"{0:N2} GB" -f ($_.FreeSpace / 1GB)}},DeviceID

#Determine last bootup date/time and output computer's name and last boot time
Get-CimInstance win32_operatingsystem | select name,lastbootuptime

#Determine last user login date & time. Output the username and last logon date/time
get-localuser | where-object {$_.Lastlogon} | select-object Name,Lastlogon

#Retrieve all user accounts and output the account name
get-localuser| format-list name

#Determine installed hotfixes & updates. Output only the hotfix ID
get-hotfix | format-list hotfixid

#List all installed applications and output as name,vendor,version
get-ciminstance -class WIn32_product | format-list Name,Vendor,Version

#} #scriptblock

$date = get-date -format "MM,dd,yyyy"
$computername = "Server1,Dc1"

$filename = "C:\$date-$computername.log"

out-file -filepath c:\$date-$computername.log

This is the bottom part I have above.

You cant just use only Out-File like that way. It has to be either connected to the output of a file or you have to pass the the input using -InputObject parameter. Its normally used by connecting to the output of another cmdlet using pipe |

Get-Process | Out-File -FilePath c:\temp\proceses.txt