none
Unknown question. RRS feed

  • Question

  • Don't you love it when a bunch of people who don't know the answer try to answer with a bunch of jibberish? netsh output's to text? Really. You need to create objects with properities and then export. Try this... All you need to do is change the OU under searchbase. This will export everything into a nice CSV for you. Yes it can be done....

    #Queries all servers in ServersOU
    $Servers = (Get-ADComputer -filter * -searchbase "ou=ServersOU, dc=, dc=com" | select name | %{$_.name.trim()})

    #Creates C:\temp if it doesn't exist
    if ( -Not (Test-Path 'C:\temp' ))
     {
      Write-Host 'Creating temp folder'
      New-Item -Path 'C:\temp' -ItemType Directory
     }

    $Report = "C:\temp\FirewallStatus.csv"
    $TotalItems = ($Servers | Measure)
    $TotalItems = $Totalitems.Count

    $Services = @()

        $Table =@()
        $Record = @{
        "ComputerName" = ""
        "ServiceName" = ""
        "ServiceStatus" = ""
        "DomainProfileFirewall" = ""
        "PrivateProfileFirewall" = ""
        "PublicProfileFirewall" = ""
        }

      [int]$Item = '1'  
         
    Foreach ($Server in $Servers)
    {
       
        Write-Host "Working on $Server"
        Write-Host "Working on item $Item of $TotalItems"
        $Item ++

            Try
            {
            $Service = Invoke-command -ComputerName $Server {Get-Service MpsSvc | select DisplayName,Status}
            [string]$Domain = Invoke-command -ComputerName $Server {netsh advfirewall show domain state}
            [string]$Private = Invoke-command -ComputerName $Server {netsh advfirewall show domain state}
            [string]$Public = Invoke-command -ComputerName $Server {netsh advfirewall show domain state}
            }

            Catch
            {
            $ErrorMessage = $_.Exception.Message
            $FailedItem = $_.Exception.ItemName
            }

                #If ($ErrorMessage -eq "" -or $ErrorMessage -eq $Null)
                #{   
                    $Record."ComputerName" = $Server
                    $Record."ServiceName" = $Service.DisplayName
                    $Record."ServiceStatus" = $Service.Status
                    $Record."DomainProfileFirewall" = $Domain
                    $Record."PrivateProfileFirewall" = $Private
                    $Record."PublicProfileFirewall" = $Public
                    $objRecord = New-Object PSObject -property $Record
                    $Table += $objRecord
                #}

                <#ElseIF ($ErrorMessage -ne "")
                {
                Write-Host $ErrorMessage
                $ErrorMessages += $ErrorMessage
                }#>
    }


    $Table | Export-Csv -Path $Report -NoTypeInformation
    $ErrorMessages | Out-File "C:\temp\errormessagesfirewallstatus.txt"

    • Split by jrv Monday, October 23, 2017 9:20 PM
    Monday, October 23, 2017 9:14 PM