locked
Export csv format issue RRS feed

  • Question

  • $Username = 'abc'
    $Password = '#jaadfaR'
    $pass = ConvertTo-SecureString -AsPlainText $Password -Force
    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
    $sb = {
        Import-Module WebAdministration
    $pools = Get-ChildItem -Path IIS:\AppPools | ? {$_.name -notlike "* .net*" -and $_.name -notlike "*default*" -and $_.name -notlike "*ASP*"}
    $pools | % {
    write-host "QueueLength $($_.queueLength)"
    write-host "processModel.idletimeout.TotalMinutes $($_.processModel.idletimeout.TotalMinutes)"
    write-host "PeriodicRecycling $($_.recycling.periodicRestart.time.TotalMinutes)"
    write-host "scheduled restart is set to $(($_.recycling.periodicRestart.schedule.collection | %{$_.value.tostring()}))"
    write-host "rapidFailProtection is $($_.failure.rapidFailProtection)"
    }
    }
    Invoke-command –computername (Get-Content "D:\Install_Files\Instrumentation\server.txt") -credential $Cred –scriptblock $sb|export-csv "D:\Install_Files\Instrumentation\iis.csv" -NoTypeInformation

    Tuesday, June 26, 2018 5:32 AM

Answers

  • Write-Host cannot crate output to a file and it cannot create a CSV.  You need to create custom objects and pass them back.


    \_(ツ)_/

    • Marked as answer by Anish57 Tuesday, June 26, 2018 7:02 AM
    Tuesday, June 26, 2018 5:42 AM

All replies

  • whenever i run this command its printing the actual result in screen not in the csv. Any hints ?
    Tuesday, June 26, 2018 5:36 AM
  • Write-Host cannot crate output to a file and it cannot create a CSV.  You need to create custom objects and pass them back.


    \_(ツ)_/

    • Marked as answer by Anish57 Tuesday, June 26, 2018 7:02 AM
    Tuesday, June 26, 2018 5:42 AM
  • Thanks a lot jrv. 
    Tuesday, June 26, 2018 7:02 AM
  • glad you saw it.  Write-Host can only output to the screen and a CSV requires an object array/collection.


    \_(ツ)_/

    Tuesday, June 26, 2018 7:04 AM