Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

error with powershell script Out-File : Cannot bind argument to parameter 'FilePath' because it is null.

Posted on 2016-11-22
3
Medium Priority
?
267 Views
Last Modified: 2016-11-26
Hello,
I just started learning powershell and doing training. This is the script that I am practicing. This is exactly how they show in th video from Lynda.com but I am getting this error. Please help. thank you. I am posting the script that I wrote below

Also, I am getting this "message" prompt. See the screenshot. Where is this coming from? This script should not be prompting for "message"

and here is the error
Out-File : Cannot bind argument to parameter 'FilePath' because it is null.
At C:\cfscripts\function1.ps1:45 char:26
+     $computer | out-file $logFile -Append
+                          ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Out-File], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.OutFileCommand

Open in new window

Function Get-DJOSInfo {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true,
        ValueFromPipeline=$true,
        ValueFromPipelineByPropertyName=$true)]
    [Alias('hostname')]
    [string[]]$ComputerName,
    [switch]$nameLog

)
Begin {
   if ($nameLog)
   {
       Write-Verbose "Finding name log file"
       $i = 0
    do {
    $logFile = "names-$i.txt"
    $i++
    } while (Test-Path $logFile)
    Write-verbose "Log file name will be stored $logfile"

    }
else {
write-verbose "Name logging off"
   } 


}
Process {
    if ($nameLog)
    {
        Write-Verbose
         "Name log on"
    }
    else
    {
       Write-Verbose "Name log off" 
    }

    foreach ($computer in $computername) {
    Write-Verbose "Now connecting to $computer"
    if ($nameLog){
    $computer | out-file $logFile -Append
    }
        $os = Get-WmiObject -ComputerName $computer -class Win32_OperatingSystem |
            Select Caption,BuildNumber,OSArchitecture,ServicePackMajorVersion
        $bios = Get-WmiObject -ComputerName $computer -Class Win32_BIOS |
            Select SerialNumber
        $processor = Get-WmiObject -ComputerName $computer -Class Win32_Processor |
            Select AddressWidth -first 1
        $osarchitecture = $os.osarchitecture -replace '-bit',''
        $properties = @{'ComputerName'=$computer;
                        'OSVersion'=$os.Caption;
                        'OSBuild'=$os.BuildNumber;
                        'OSArchitecture'=$osarchitecture;
                        'OSSPVersion'=$os.servicepackmajorversion;
                        'BIOSSerial'=$bios.SerialNumber;
                        'ProcArchitecture'=$processor.addresswidth}
        $obj = New-Object -TypeName PSObject -Property $properties
        Write-Output $obj

#write-host $computername   
}

}

End {}


}


#Get-DJOSInfo -computername server01

Open in new window

error message
0
Comment
Question by:creative555
3 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 41898327
Lines 33 and 34 belong together into a single line - this is the "message" thingy you get.
The out-file error results from - no clue. The script should search for existing log files and create a new one (by incrementing the index number).
You can help yourself by adding -verbose when calling of the procedure; that activates the write-verbose messages, which otherwise are suppressed. They will print some debugging info.
0
 

Author Closing Comment

by:creative555
ID: 41902683
thanks! tested and it worked!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question