troubleshooting Question

Cannot get results needed from file last modified to CSV.

Avatar of Harrison Aten
Harrison AtenFlag for United States of America asked on
Powershell
3 Comments1 Solution72 ViewsLast Modified:
Can someone please help with this power-shell script. I am trying to get the out put of an array to report the results to a csv. This is the script and the results. Thank you in advance.

Script:
$Computers = Get-Content 'C:\powershell\list.txt'

Foreach ($Computer in $Computers) {
    set-location "\\$computer\c$\program files\nsclient++"
    if (Test-Path nsclient.ini) {
        $file = Get-Item  nsclient.ini
        $results += New-Object psObject -Property @{'Computer'=$computer;'FileName'=$file.FullName;'LastWriteTime'=$file.lastwritetime}
    }                
   else {
       $results += New-Object psObject -Property @{'Computer'=$computer;'FileName'="File not found";'LastWriteTime'="xx.xx.xx xx:xx:xx"}
    }
}
$results | select-object computer, LastWriteTime |out-file -append 'C:\powershell\filedateini.csv'

Results:
PS C:\powershell> C:\Powershell\getfiledate.ps1
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Powershell\getfiledate.ps1:7 char:9
+         $results += New-Object psObject -Property @{'Computer'=$compu ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
set-location : Cannot find path '\\3MAPPPROD\c$\program files\nsclient++' because it does not exist.
At C:\Powershell\getfiledate.ps1:4 char:5
+     set-location "\\$computer\c$\program files\nsclient++"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\3MAPPPROD\c$\program files\nsclient++:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
 
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Powershell\getfiledate.ps1:7 char:9
+         $results += New-Object psObject -Property @{'Computer'=$compu ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Powershell\getfiledate.ps1:7 char:9
+         $results += New-Object psObject -Property @{'Computer'=$compu ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Powershell\getfiledate.ps1:7 char:9
+         $results += New-Object psObject -Property @{'Computer'=$compu ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Powershell\getfiledate.ps1:7 char:9
+         $results += New-Object psObject -Property @{'Computer'=$compu ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Powershell\getfiledate.ps1:7 char:9
+         $results += New-Object psObject -Property @{'Computer'=$compu ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 

PS Microsoft.PowerShell.Core\FileSystem::\\CherwellDBDev\c$\program files\NSClient++>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros