1

The program disables the feature "internet Explorer 11 after looping through a list of servers and exports the results to a csv file with Server Names and the "state" of the Internet explorer as columns as shown below but value component does not show up in the resulting csv file, specifically this value : $Status

ServerName State

genericNameServer It is supposed to be either "disabledPending or "Unknown", but it stays blank

#Filter the list of servers based on the input parameters (filtering in this location prevents having to loop through servers that are not being processed)
$FilteredServers = $AllServers | Where-Object { ($PSItem.OS -like "*$OperatingSystem*") -and ($PSItem.Type -eq $Type) -and ($PSItem.Citrix -eq $False)}

#Iterate through the list of servers
foreach ($Server in $FilteredServers)

    #if the server is 2012/2016
    elseif ((($OperatingSystem -eq '2012') -or ($OperatingSystem -eq '2016')))
    {
        Invoke-Command -ComputerName ($Server.ServerName) -ScriptBlock { 
            #Disable IE
            dism /online /Disable-Feature /FeatureName:Internet-Explorer-Optional-amd64 /NoRestart

            #Get the Interenet Exploere feature 
            $IEStatus = Get-WindowsOptionalFeature -Online -FeatureName Internet-Explorer-Optional-amd64
          
           }

# evaluate if state property is disabledpending or not  and create a variable called Status  with a value of either 'disablepending' or 'status: unknown'
            if ($IEStatus.State -eq 'DisablePending') { $Status = 'DisablePending' }
            else { $Status = 'Unknown' }
                       
        }
    
        $CsvStatus += [PSCustomObject]@{
            ServerName  = $Server.ServerName
            State = ($Status)
        } 
    }
}
$CsvStatus | Export-Csv -Path c"\tem\effectedServer.csv
Maks
  • 11
  • 2
  • It would help if you could describe the purpose of your script. Also, to help clarify the problem, it is good to narrow down your code to a minimal reproducible example. – Bill_Stewart Nov 18 '21 at 17:39
  • 1
    This would be a good time to start learning how to use a debugger, which allows you to run your program line by line (aka single-stepping), at the press of a button. For each line of code, examine the state of _all_ variables and verify if the their values meet your expectations. I can only recommend the debugger build into VSCode with the PowerShell extension. For PS 5.x, PowerShell ISE also works (but is somewhat outdated). – zett42 Nov 18 '21 at 19:18
  • Maybe change State = ($IEStatus.State) to State = $($IEStatus.State). – Miroslav Vasilev Nov 18 '21 at 19:19
  • Bill, thank you for your advise, I edited the post, I hope it makes more sense now. Could you look at and see why the $Status stays blank in the CSV file – Maks Nov 18 '21 at 19:59
  • thank you for the Debugger advise, also $($IEStatus) does not work either , – Maks Nov 18 '21 at 20:11

0 Answers0