Solved

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

Posted on 2016-11-22
3
20 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 68

Accepted Solution

by:
Qlemo earned 500 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
A procedure for exporting installed hotfix details of remote computers using powershell
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now