0

I have this code wich work great for only one item if I add a new item it just delete the older one

I've tried many way but I can't find how to do this can you help me?

Import-Module WebAdministration
$HostName = $env:computername
$DateNow = Get-Date -format d

$WebServerEngine_MajorVersion = get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\  | foreach >{$_.MajorVersion}
$WebServerEngine_MinorVersion = get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\  | foreach {$_.MinorVersion}
$IIS_Version = [string]$WebServerEngine_MajorVersion + "." + [string]$WebServerEngine_MinorVersion

$Webs = Get-Website | select name

if ($Webs) {
    ForEach ($Web in $Webs) {
    $InfoServer = new-object psobject
    $InfoServer | add-member noteproperty HostName $HostName
    $InfoServer | add-member noteproperty Date_report $DateNow
    $InfoServer | add-member noteproperty IIS_Version $IIS_Version
    $InfoServer | add-member noteproperty SiteName $Web.name
    }
}
0

You are overwriting the $InfoServer object on each iteration through the loop. Try adding a Write-Output $InfoServer command at the end of the loop. This will send the data back out to the pipeline. Try this:

if ($Webs) {
    ForEach ($Web in $Webs) {
        $InfoServer = new-object psobject
        $InfoServer | add-member noteproperty HostName $HostName
        $InfoServer | add-member noteproperty Date_report $DateNow
        $InfoServer | add-member noteproperty IIS_Version $IIS_Version$InfoServer | add-member noteproperty SiteName $Web.name
        Write-Output $InfoServer
    }
}
  • the output is perfect but I need to reuse the output not only write it on screen – Keven Sep 10 '14 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.