troubleshooting Question

Turning Powershell output into Column CSV file

Avatar of Ed Walsh
Ed WalshFlag for United States of America asked on
Powershell
19 Comments1 Solution180 ViewsLast Modified:
I have a powershell script to pull information from IIS, currently it just drops the output on the screen and for the time that was fine, but now we need to drop the output into columns in a csv file. This will then be imported into a Database to allow us to query for more information.

I am having issues with getting this into columns and into a CSV file output. Any help is appreciated.

-------------------------
Set-ExecutionPolicy RemoteSigned
#
Import-Module WebAdministration

Get-WebApplication | `
ForEach-Object {

Write-Host "Web Application: $($_.path)"
"Physical Path: $($_.PhysicalPath)"
"Application Pool: $($_.ApplicationPool)"


$test_webconfig_exists = test-path "$($_.PhysicalPath)\Web.config"

if($test_webconfig_exists)
{
$webConfigFile = [xml](Get-Content "$($_.PhysicalPath)\Web.config")

foreach($connString in $webConfigFile.configuration.connectionStrings.add)
{
  Write-Host "-----------------"
  Write-Host "Connection String $($connString.name): $($connString.connectionString)"
  $dbRegex = "((Initial\sCatalog)|((Database)))\s*=(?<ic>[a-z\s0-9]+?);"
  $found = $connString.connectionString -match $dbRegex
  if ($found)
  {
  Write-Host "~~~~~~~~~~~~~~~~~~~~"
   Write-Host "Database: $($Matches["ic"])"
  Write-Host "~~~~~~~~~~~~~~~~~~~~"
  }
  #Write-Host "-----------------"
}
}

if($test_webconfig_exists -eq "")
{
Write-Host "Missing Web.Config File: Yes"
} Else
{
Write-Host "Missing Web.Config File: No"
}
Write-Host "**======================================================**"

}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 19 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros