We help IT Professionals succeed at work.

Cannot get results needed from file last modified to CSV.

Harrison Aten
on
61 Views
Last Modified: 2019-03-19
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++>
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Harrison AtenSystems Engineer

Author

Commented:
Thank you very much work as needed and we can close this post, I really appreciate the time and effort that you spent helping me with this issue. Good to be back at the exchange.
Harrison AtenSystems Engineer

Author

Commented:
Thank you very much work as needed and we can close this post, I really appreciate the time and effort that you spent helping me with this issue. Good to be back at the exchange.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.