Is it not possible to Skip Access denied error and move on to next String?

Hi Gents,

I have FOUR computers (Actually two) in a Notepad and have full permission for that file.

PS C:\Temp> hostname
MemberServer
PS C:\Temp> Get-Content C:\Temp\servers.txt
memberserver
localhost
adserver
127.0.0.1

I have NOT given permission to the ‘ADserver’ but i have full permission in memberserver where i logged in now.

If i run the WMI command i’m getting results only for first two computers but it STOPPED working at ADserver and not moving to Memberserver for any Erroraction parameters. Is there any way to fix this without giving permission to ADserver or to skip it?

PS C:\Temp> gwmi win32_bios -ComputerName (Get-Content C:\Temp\servers.txt) -ErrorAction SilentlyContinue

SMBIOSBIOSVersion : 4.2.amazon
Manufacturer : Xen
Name : Revision: 1.221
SerialNumber : ec21a6d3-3b47-2a36-fded-befe820****
Version : Xen - 0

SMBIOSBIOSVersion : 4.2.amazon
Manufacturer : Xen
Name : Revision: 1.221
SerialNumber : ec21a6d3-3b47-2a36-fded-befe820****
Version : Xen - 0

gwmi : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:1

  • gwmi win32_bios -ComputerName (Get-Content C:\Temp\servers.txt) -ErrorAction Sil …
  • CategoryInfo : NotSpecified: (:slight_smile: [Get-WmiObject], UnauthorizedAccessException
  • FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

PS C:\Temp>

Yes, wrap your Get-WMI command in a try/catch statement and wrap that in a foreach loop to manually iterate through the computer list.
For example:

foreach ($ComputerName in (Get-Content C:\Temp\servers.txt)) {
    try {
        Get-WmiObject win32_bios -ComputerName $ComputerName -ErrorAction Stop
    } catch {
        $_.Exception.Message # or nothing if you don't want to see anything about the error
    }
}