could not find a part c:\scipts\control.csv

Welcome Forums General PowerShell Q&A could not find a part c:\scipts\control.csv

Viewing 4 reply threads
  • Author
    Posts
    • #226530
      Participant
      Topics: 1
      Replies: 1
      Points: 17
      Rank: Member

      I wrote this script below to get applications that is install on remote desktops, I got admin rights to run it on remote desktops, I am getting the following error ‘c:\scipts\control.csv’

      Foreach ($computer in (“GC C:\Scripts\computer.txt”)){
      Invoke-command -computerName “$computer” -ScriptBlock {
      Get-ItemProperty “HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*” | Select-Object DispalyName,`
      DisplayVersion, Publisher, @{Name=”Installdate”; Expression={([DateTime]::ParseExact($_InstallDate, ‘yyyymmdd’, $null)).toshortdatestring()}}
      _ Export-csv -path c:\scipts\control.csv
      }
      }

      • This topic was modified 3 weeks, 1 day ago by Ashtonnew.
    • #226533
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      Winston, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code or error messages or sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      You should collect the result of the loop in a variable and export this to your local CSV file …

      $Result = foreach ($computer in (Get-Content -Path C:\Scripts\computer.txt)) {
          Invoke-command -computerName $computer -ScriptBlock {
              Get-ItemProperty 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | 
                  Select-Object -Property DispalyName, DisplayVersion, Publisher, 
                      @{Name = 'Installdate'; Expression = { ([DateTime]::ParseExact($_.InstallDate, 'yyyyMMdd', $null)).toshortdatestring() } },
                      @{Name = 'Computername';Expression = {$computer}}
          }
      }
      
      $Result  | Export-csv -path c:\scipts\control.csv
    • #226545
      Participant
      Topics: 6
      Replies: 93
      Points: 427
      Helping Hand
      Rank: Contributor

      I wrote a function to get software listings from local and remote systems. What I found was that you also need to get listings from both registry hives and remove duplicates to get the most accurate listing. At least that is what I did. I started out using WMI Win32_Product but found out not only does it take forever, it causes a re-validation of the software component which creates tons of banter in the event logs.

      'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall'
      'SOFTWARE\\Wow6432Node\Microsoft\\Windows\\CurrentVersion\\Uninstall'

      Then, I ran into issues where null/blank entries would cause an unrecoverable error that I was never able to solve (even with try/catch) and moved to [Microsoft.Win32.Registry]::OpenBaseKey('LocalMachine', 'Default') and [Microsoft.Win32.Registry]::OpenRemoteBaseKey('LocalMachine', $hostTocheck) for remote systems.

      You also need to watch for DisplayName being null.

    • #226548
      Participant
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero

      Here’s a function I wrote some time ago. I used it as part of a script to automate removal of a program. I had some weird issue with 2 PCs that after reboot the get-service would fail the first attempt no matter how long I waited but would work second time so there is a retry. It also will try to start remote registry if needed and then set it back to the state/startuptype it was. It seemed sufficient and reliable.

      https://gist.github.com/krzydoug/547bb2ea16986587f10a0497781644da

    • #227134
      Participant
      Topics: 1
      Replies: 1
      Points: 17
      Rank: Member

      Thanks guys, will try it tomorrow when go to work

Viewing 4 reply threads
  • You must be logged in to reply to this topic.