Hey all.
I am not “new” to PowerShell, but more complex scripting is something I have not really dug into as much as I need too so am working on things now.
I have hundreds of Web Servers that i need to manage and need to gather some information on them so I can populate a database.
First things first. I have to pull the information. I have the beginnings of a script and am getting output, but it’s formatting the output into a useable format that I am having a hard time with. What I would ultimately like to end up with is a CSV file that I can dabble with and use to insert into a database.
Here is my script so far:
Begin {
$array0 = @()
$array1 = @()
# Sets location of APPCMD.exe - This is needed to pull data from IIS from the script
Set-Location "c:\windows\system32\inetsrv\"
}
# Queries the registry to see what .NET versions are installed
Process{
if((Get-ItemProperty -ErrorAction SilentlyContinue "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727").Version -like "2.*") {
$array0 += "2.0"
}
if((Get-ItemProperty -ErrorAction SilentlyContinue "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup").Version -like "3.0*") {
$array0 += "3.0"
}
if((Get-ItemProperty -ErrorAction SilentlyContinue "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v3.5").Version -like "3.5*") {
$array0 += "3.5"
}
if((Get-ItemProperty -ErrorAction SilentlyContinue "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full").Version -like "4.0*") {
$array0 += "4.0"
}
if((Get-ItemProperty -ErrorAction SilentlyContinue "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full").Version -like "4.5*") {
$array0 += "4.5"
}
# Stores the .NET information into an array for later use
[String]$dotNet = $array0
# Get computer name and domain
$compInfo = gwmi win32_computersystem | Select DNSHostName,Domain | ConvertTo-csv -NoTypeInformation
# Populate Array with Object properties
$array1 += $compInfo
$array1
# Query for site information
[XML]$sites = .\appcmd list Site /config:* /XML
$site1 = $sites.SelectNodes("//SITE")
$sitesOutput = $site1 | Select SITE.NAME,bindings | ConvertTo-csv -NoTypeInformation
$sitesOutput
# Putting it all together
$csvfile = "D:\scripts\" + $env:ComputerName + "_config.csv"
Out-File -FilePath $csvfile
}
(Yeah, I know I have not done anything with the .NET version info yet. ![]()
Now, I get SCREEN output:
"DNSHostName","Domain" "servername","domain.com" "SITE.NAME","bindings" "Default Web Site","http/*:80:,net.tcp/808:*,net.pipe/*,net.msmq/localhost,msmq.formatname/localhost" "AdminApps","http/10.224.96.10:80:" "NotificationServices","http/10.224.96.12:80:" "GoSomeSite","http/10.224.96.16:80:,https/10.224.96.16:443:" "SomeOtherSite","http/10.224.96.14:80:" "Domain","http/10.224.97.19:80:,http/10.224.97.19:80:www1.domain.com"
However, the CSV is empty.
I know the output is messy, but it’s a start and i can get it going. I have researched a bit and am kinda brain dead at the moment. Any help is appreciated and any tips on making things look nicer would be great too! ![]()
Thanks!