While using the WebAdministration module seems like the best approach, you could try regex for this looping over the lines the command c:\windows\system32\inetsrv\appcmd list sites returns and parse the values you need from them.
Since I cannot test this for real myself, I'm using your example output from c:\windows\system32\inetsrv\appcmd list sites as a string array:
$siteList = 'SITE "A" (id:1,bindings:http//:csdev.do.com,state:Stopped)',
'SITE "B" (id:2,bindings:tsd-gr2,state:Stopped)',
'SITE "C" (id:3,bindings:http/1028:8091:,http/19.28:80:ddprem.do.com,state:Stopped)',
'SITE "D" (id:4,bindings:http/109.149.232:80,state:Stopped)'
$regex = [regex] '^SITE "(?<site>\w+)".+id:(?<id>\d+),bindings:(?:.+:(?<url>\w+\.do\.com))?'
$siteList | ForEach-Object {
$match = $regex.Match($_)
while ($match.Success) {
$url = if ($match.Groups['url'].Value) { $match.Groups['url'].Value } else { 'null' }
'{0},{1},{2}' -f $match.Groups['site'].Value, $match.Groups['id'].Value, $url
$match = $match.NextMatch()
}
}
Result:
A,1,csdev.do.com
B,2,null
C,3,ddprem.do.com
D,4,null
Regex details:
^ Assert position at the beginning of the string
SITE\ " Match the characters “SITE "” literally
(?<site> Match the regular expression below and capture its match into backreference with name “site”
\w Match a single character that is a “word character” (letters, digits, etc.)
+ Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
" Match the character “"” literally
. Match any single character that is not a line break character
+ Between one and unlimited times, as many times as possible, giving back as needed (greedy)
id: Match the characters “id:” literally
(?<id> Match the regular expression below and capture its match into backreference with name “id”
\d Match a single digit 0..9
+ Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
,bindings: Match the characters “,bindings:” literally
(?: Match the regular expression below
. Match any single character that is not a line break character
+ Between one and unlimited times, as many times as possible, giving back as needed (greedy)
: Match the character “:” literally
(?<url> Match the regular expression below and capture its match into backreference with name “url”
\w Match a single character that is a “word character” (letters, digits, etc.)
+ Between one and unlimited times, as many times as possible, giving back as needed (greedy)
\. Match the character “.” literally
do Match the characters “do” literally
\. Match the character “.” literally
com Match the characters “com” literally
)
)? Between zero and one times, as many times as possible, giving back as needed (greedy)
WebAdministrationmodule instead of parsingappcmdoutput.Import-Module WebAdministration)? Is IIS actually running?