Brian
asked on
Export PowerShell Results to HTML
Hello Experts,
I have the following PowerShell Script that I received help with. I need to be able to convert the results to and HTML, CSV and Txt file. I need the results for each format. Please see my PowerShell below.
I have the following PowerShell Script that I received help with. I need to be able to convert the results to and HTML, CSV and Txt file. I need the results for each format. Please see my PowerShell below.
$bios = Get-WmiObject -Class Win32_BIOS
$cpu = Get-WmiObject -Class Win32_Processor
$os = Get-WmiObject -Class Win32_OperatingSystem
$sys = Get-WmiObject -Class Win32_ComputerSystem
$key = Get-WmiObject -Class SoftwareLicensingService
$sysProperties = [ordered]@{
'-- PC --' = ''
'Domain' = $sys.domain
'PC Name' = $os.pscomputername
'User Name' = $sys.UserName
'-- Model --' = ''
'Manufacturer' = $sys.manufacturer
'Model' = $sys.model
'Serial Number' = $bios.serialnumber
'Product Number' = $sys.SystemSKUNumber
'-- Hardware --' = ''
'Processor' = $cpu.Name
'Installed RAM' = $sys.totalphysicalmemory / 1GB -as [int]
'-- OS --' = ''
'Edition' = $os.caption
'OS System Type' = $os.osarchitecture
'OS Build' = $os.buildnumber
'Product Key' =$key.OA3xOriginalProductKey;
}
$Separator = '-' * ($sysProperties.Values | Measure-Object -Property Length -Maximum).Maximum
@($sysProperties.Keys) | Where-Object {$_ -like '--*'} | ForEach-Object {$sysProperties[$_] = $Separator}
$sysProperties
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Below is how I added what you suggested:
$bios = Get-WmiObject -Class Win32_BIOS
$cpu = Get-WmiObject -Class Win32_Processor
$os = Get-WmiObject -Class Win32_OperatingSystem
$sys = Get-WmiObject -Class Win32_ComputerSystem
$key = Get-WmiObject -Class SoftwareLicensingService
$sysProperties = [ordered]@{
'-- PC --' = ''
'Domain' = $sys.domain
'PC Name' = $os.pscomputername
'User Name' = $sys.UserName
'-- Model --' = ''
'Manufacturer' = $sys.manufacturer
'Model' = $sys.model
'Serial Number' = $bios.serialnumber
'Product Number' = $sys.SystemSKUNumber
'-- Hardware --' = ''
'Processor' = $cpu.Name
'Installed RAM' = $sys.totalphysicalmemory / 1GB -as [int]
'-- OS --' = ''
'Edition' = $os.caption
'OS System Type' = $os.osarchitecture
'OS Build' = $os.buildnumber
'Product Key' =$key.OA3xOriginalProductKey;
}
$Separator = '-' * ($sysProperties.Values | Measure-Object -Property Length -Maximum).Maximum
@($sysProperties.Keys) | Where-Object {$_ -like '--*'} | ForEach-Object {$sysProperties[$_] = $Separator}
$sysProperties | ConvertTo-HMTL | Out-File C:\Temp\Results.html
ASKER
I was able to get the PowerShell cmd to create the .html file. But the results are not correct. Please see below:
Count
IsReadOnly
Keys
Values
IsFixedSize
SyncRoot
IsSynchronized
17
False
System.Collections.Special ized.Order edDictiona ry+Ordered Dictionary KeyValueCo llection
System.Collections.Special ized.Order edDictiona ry+Ordered Dictionary KeyValueCo llection
False
System.Object
False
Count
IsReadOnly
Keys
Values
IsFixedSize
SyncRoot
IsSynchronized
17
False
System.Collections.Special
System.Collections.Special
False
System.Object
False
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Odd, works fine in the ISE, but pasting the entire thing in the console gives the error.
This works with the commented out portions deleted.
This works with the commented out portions deleted.
$bios = Get-WmiObject -Class Win32_BIOS
$cpu = Get-WmiObject -Class Win32_Processor
$os = Get-WmiObject -Class Win32_OperatingSystem
$sys = Get-WmiObject -Class Win32_ComputerSystem
$key = Get-WmiObject -Class SoftwareLicensingService
$sysProperties = [pscustomobject][ordered]@{
'Domain' = $sys.domain
'PC Name' = $os.pscomputername
'User Name' = $sys.UserName
'Manufacturer' = $sys.manufacturer
'Model' = $sys.model
'Serial Number' = $bios.serialnumber
'Product Number' = $sys.SystemSKUNumber
'Processor' = $cpu.Name
'Installed RAM' = $sys.totalphysicalmemory / 1GB -as [int]
'Edition' = $os.caption
'OS System Type' = $os.osarchitecture
'OS Build' = $os.buildnumber
'Product Key' =$key.OA3xOriginalProductKey;
}
$sysProperties
ASKER
If I copy and paste the following code above in PS Command and PS ISE it runs fine. But if I run the code in Post ID: 42232878 were we are trying to export the results to .txt or .html I get that error that I screenshot.
With the last code in #a42233464 it still creates the $sysProperties object, from which you can then pipe to either of the following.
$sysProperties | ConvertTo-HMTL | Out-File C:\Temp\Results.html -encoding ascii
$sysProperties | Export-CSV C:\Temp\Results.csv
ASKER
@footech, thank you. It worked... The only odd thing though is when I export to .csv it add this #TYPE System.Management.Automati on.PSCusto mObject to the first row and column of the csv file. Everything below that is fine though.
You can add the -NoTypeInformation parameter to Export-CSV to avoid that.
ASKER
Thank you very much for all your help!!!
ASKER
ConvertTo-HTML : The term 'ConvertTo-HTML' is not recognized as the name of a cmdlet, function, script file, or operable program.