Link to home
Start Free TrialLog in
Avatar of Bobby Batts
Bobby BattsFlag for United States of America

asked on

PowerShell: Cannot find path Error

The attached script suddenly not working.  I am getting an error indicating that 'Cannot find path'.  The script was working great prior to this error.  I can open the .csv file using Notepad. I check the permissions on the folder and the file.  Full access has been granted.

Can someone advise as to what may be the issue and what troubleshooting I should consider?

review the following error:
PS C:\WinUpVer> C:\Fix\GetWmiObj08AutoWinUpV4.ps1
Get-Content : Cannot find path 'C:\WinUpVer\Updates.csv' because it does not exist.
At C:\Fix\GetWmiObj08AutoWinUpV4.ps1:1 char:13
+ $servers = (Get-Content .\Updates.csv)
+             ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\WinUpVer\Updates.csv:String) [Get-Conte
   nt], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Thanks,

Lipotech
 

PS C:\WinUpVer>
$servers = (Get-Content .\Updates.csv)
$servers | ForEach-Object {
  $Server = $_
  "Processing $Server ... " | Write-Host -NoNewline -ForegroundColor White
  Try {
    $QFEGroups = Get-WmiObject -Class "Win32_QuickFixEngineering" -ComputerName $Server -ErrorAction Stop |
      Select-Object -Property `
        "Description",
        "HotfixID",
        @{Name="InstalledOn"; Expression={([DateTime]($_.InstalledOn)).ToLocalTime()}} |
      Group-Object -Property Description
    $LastHotfix = ($QFEGroups | ? {$_.Name -eq "Hotfix"}).Group | Sort-Object -Property InstalledOn | Select-Object -Last 1
    $LastUpdate = ($QFEGroups | ? {$_.Name -eq "Update"}).Group | Sort-Object -Property InstalledOn | Select-Object -Last 1
    $LastSecurityUpdate = ($QFEGroups | ? {$_.Name -eq "Security Update"}).Group | Sort-Object -Property InstalledOn | Select-Object -Last 1
    "" | Select-Object -Property `
      @{Name="ComputerName"; Expression={$Server}},
      @{Name="Hotfix"; Expression={$LastHotfix.HotfixID}},
      @{Name="HF_InstalledOn"; Expression={$LastHotfix.InstalledOn}},
      @{Name="Update"; Expression={$LastUpdate.HotfixID}},
      @{Name="UP_InstalledOn"; Expression={$LastUpdate.InstalledOn}},
      @{Name="Security Update"; Expression={$LastSecurityUpdate.HotfixID}},
      @{Name="SU_InstalledOn"; Expression={$LastSecurityUpdate.InstalledOn}},
      "Error"
    "OK." | Write-Host -ForegroundColor Green
  } Catch {
    $_.Exception.Message | Select-Object -Property `
      @{Name="ComputerName"; Expression={$Server}},
      "Hotfix",
      "HF_InstalledOn",
      "Update",
      "UP_InstalledOn",
      "Security Update",
      "SU_InstalledOn",
      @{Name="Error"; Expression={$_}}
    $_.Exception.Message | Write-Host -ForegroundColor Red
  }
} | Export-Csv -NoTypeInformation -Path "C:\WinUpVer\WinUpdateVerify.csv"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bobby Batts

ASKER

Qlemo,

Issue resolved. I determined it was a credentials issue.  What is odd is that I used the same credentials multiple times to execute this script and it ran successfully. Suddenly it failed to execute with the original credentials.

Question: How did you move the attached script into a code block? Not sure how I would accomplish that task.

Thank you for your response.

Lipotech