Back to top

FREE eBook: The Most USEFUL PowerShell CmdLets and more…

Grab a copy!

How To Create, Write And Save An Excel File Using PowerShell

How To Create An Excel File Using PowerShell
Approx Reading Time: 17 minutes

Creating Excel Reports using PowerShell is very important since Excel as the application is widely used especially in out of the IT world and sometimes a very useful way of presenting the data.

I have written my own Save-ToExcel PowerShell CmdLet and after reading this article you can expect the following result presented with screenshots.

In the following syntax result of Get-ErrorFromEventLog CmdLet (another of my own functions) has been sent down the PowerShell Pipeline as input to the Save-ToExcel CmdLet which will create Excel file in the folder.

Get-ErrorFromEventLog -computers "localhost" -errorlog -client "OK" -solution "FIN" -days 3 -Verbose | Save-ToExcel -ExcelFileName "Get-ErrorsInEventLogs" -title "Get errors from Event Logs on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Errors from Event Logs" -sendemail -client "OK" -solution "FIN"

Here is the resulting Excel Report that shows all the errors from Event Logs on the machine:

Excel File as a result of running Save-ToExcel Function

We can even send this Excel file as an attachment to some email account right from the Save-ToExcel CmdLet.

Email sent with attachment Excel file zipped.

Save-ToExcel Function Explained

Save-ToExcel Function is part of the Efficiency Booster PowerShell Project. This project is the library of PowerShell CmdLets that helps us to accomplish our everyday IT tasks in a more efficient way so we can have more time doing some other tasks.

In order to follow me along please download the source code from here. Save-ToExcel Function is part of the Utils module and the script file is in the 02utils folder.

Save-ToExcel script file location

An important feature of the Save-ToExcel function is that accepts the result of some PowerShell CmdLet sent down the PowerShell Pipeline as input in order to create the Excel file for that resultset.

Excel file is saved in the PSreports folder in [My] Documents for the user that runs the code.

INFO: I have thoroughly explained the PowerShell Pipeline concept in the article How PowerShell Pipeline Works, so please read it for more info.

Input Parameters Of Save-ToExcel Function

Save-ToExcel Function has many input parameters and I will try to give a short description for each of them.

#Input ParameterExplanation
1InputObjectObjects from Pipeline
2ExcelFileNameName of the Excel file
3titleTitle of Excel Workbook
4authorAuthor of Excel Workbook
5WorkSheetNameExcel Worksheet Name
6errorlogTurning on/off logging of errors
7sendemailTurning on/off sending an email with Excel file
8clientTwo letters client's shortcode
9solutionClient's solution (FIN - Financial, HR - Human Resource)
Save-ToExcel Input Parameters Explained

Here is the code for input parameters:

Function Save-ToExcel {
[CmdletBinding()]
param (
    [Parameter(Mandatory=$true,
                ValueFromPipeline=$true, 
                HelpMessage="Input rows to be saved as Excel file.")] 
    [PSobject[]]$InputObject,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel file name.")]
    [string]$ExcelFileName,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel workbook title.")]
    [string]$title,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel workbook author.")]
    [string]$author,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel worksheet name.")]
    [string]$WorkSheetName,
    
    [Parameter(HelpMessage="Write to error log file or not.")]
    [switch]$errorlog,
    
    [Parameter( HelpMessage="Send email.")]
    [switch]$sendemail,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Client for example OK = O client, BK = B client")]
    [string]$client,
     
    [Parameter(Mandatory=$true,
                HelpMessage="Solution, for example FIN = Financial solution, HR = Humane Resource solution")]
    [string]$solution    
)
}

INFO: Creation of input parameters for every function is a very important decision and I have written an article with many examples of parameters How To Create Parameters In PowerShell.

Begin Block Of Save-ToExcel Function

The BEGIN input processing method (block) runs only one time and it is very useful for pre-processing initialization.

In Save-ToExcel Function we do two things in BEGIN block:

  1. Create an empty array of objects.
  2. Test if the folder, where we want to save our Excel file, exists and if not we create the folder.
BEGIN { 
    
    #Creat an empty array
    $objects = @()

    $reportsfolder = "$home\Documents\PSreports"
        
        if  ( !( Test-Path -Path $reportsfolder -PathType "Container" ) ) {
            
            Write-Verbose "Create reports folder in: $reportsfolder"
            New-Item -Path $reportsfolder -ItemType "Container" -ErrorAction Stop
        }
        
}

INFO: If you want to know more about Begin, Proces, and End input processing methods I have written article PowerShell Function Begin Process End Blocks Explained With Examples.

Process Block Of Save-ToExcel Function

The PROCESS input processing method (block) runs on a record-by-record basis for each object sent through PowerShell Pipeline.

Implementation of PROCESS block in Save-ToExcel function is very simple:

  1. We just add objects sent to function from PowerShell Pipeline to the array of objects created in the BEGIN block.
PROCESS { 

    $objects += $InputObject
    
}

INFO: PowerShell Pipeline is one of the essential concepts in Windows PowerShell and I highly encourage you to read about it in the article How PowerShell Pipeline Works.

End Block Of Save-ToExcel Function

The END input processing method (block) runs only one time and it is very useful for post-processing clean up.

Interestingly enough implementation of END block in Save-ToExcel Function is the main processing rather than post-processing since here we have most of the functionality. This approach to process all data in one batch in END block rather than row by row in PROCESS block is because Excel is very slow for record-by-record processing using PowerShell. In order, to avoid the performance issues I have decided to put the main functionality in the END block and do as one batch.

I will explain the code in steps and at the end show the whole END block code.

How To Create, Write, And Save Excel File Using PowerShell (Steps)

Step 1: Set up the culture to EN-US

TIP: This is a very important step for us who use other than English culture settings. I live in Norway and my all culture settings are for Norwegians and this was the main cause of my code breaking until I fixed it with the line of code that follows.

[System.Threading.Thread]::CurrentThread.CurrentCulture = "en-US"

Step 2: Create Temporary CSV file

We create a temporary CSV file using Export-Csv CmdLet with data from the objects sent through the PowerShell Pipeline. We will use this temporary CSV file when we create an Excel workbook just to past the data into the worksheet.

#Temporary .csv file with GUID name has been created first.
$temporaryCsvFile = ($env:temp + "\" + ([System.Guid]::NewGuid()).ToString() + ".csv") 
#Delimiter ";" helps that result is parsed correctly. Comma delimiter parses incorrectly.
$objects | Export-Csv -ErrorAction Stop -path $temporaryCsvFile -noTypeInformation -Delimiter ";"
Write-Verbose "Temporary csv file saved: $temporaryCsvFile"

TIP: Use as delimiter “;” semicolon instead of “,” comma in Export-CSV CmdLet in order to get data parsed correctly.

Step 3: Create An Excel Object

Now is the time to create Excel Object using COM.

$excelObject = New-Object -ComObject Excel.Application -ErrorAction Stop

IMPORTANT: We need Excel installed on the server that will process this function.

Step 4: Optionally, make Excel object visible/invisible

Since I like to automate my CmdLets and run them scheduled there was no need for me to make Excel workbook visible. However, while I was developing the code I would turn on the visibility just for testing or debugging purposes.

$excelObject.Visible = $false 

Step 5: Create Excel Workbook

We create the excel workbook passing the temporary CSV file created in Step 2. In addition, we give a title to our Workbook and Author.

NOTE: Since we use the Open method and pass the temporary CSV file with data, Excel will create a workbook with one worksheet instead workbook with empty 3 worksheets if we use the Add method.

$workbookObject = $excelObject.Workbooks.Open($temporaryCsvFile)  
$workbookObject.Title = ("$title " + (Get-Date -Format D)) 
$workbookObject.Author = "$author"
Excel Workbook Title marked yellow

Step 6: Create Excel Worksheet

Now we can create our first Excel Worksheet object.

$worksheetObject = $workbookObject.Worksheets.Item(1)

Step 7: Customize and Style Excel Worksheet as needed

Now we can customize our Excel Worksheet to give it a name, autofit the columns, and use some predefined Excel table style for the better-formatted result.

#Method TextToColumns is important to convert .csv file data into right columns in Excel file.
$colA=$worksheetObject.range("A1").EntireColumn
$colrange=$worksheetObject.range("A1")
$xlDelimited = 1
$xlTextQualifier = 1
$colA.TextToColumns($colrange,$xlDelimited,$xlTextQualifier,$false,$false,$false,$true)
     
$worksheetObject.UsedRange.Columns.Autofit() | Out-Null
$worksheetObject.Name = "$WorkSheetName"
        
#Style of table in Excel worksheet.
$xlSrcRange = 1
$XlYes = 1
#Syntax - expression.Add(SourceType, Source, LinkSource, HasHeaders, Destination)
$listObject = $worksheetObject.ListObjects.Add($xlSrcRange, $worksheetObject.UsedRange, $null, $XlYes, $null) 
$listObject.Name = "User Table"
$listObject.TableStyle = "TableStyleMedium6" # Style Cheat Sheet in French/English: http://msdn.microsoft.com/fr-fr/library/documentformat.openxml.spreadsheet.tablestyle.aspx   
WorkSheet got a name (marked red) and blue style for header and rows

Step 8: Save Excel File and Close Excel Workbook

We can save our Excel File and close Excel Workbook.

$workbookObject.SaveAs($excelFile,51) # http://msdn.microsoft.com/en-us/library/bb241279.aspx 
$workbookObject.Saved = $true
$workbookObject.Close()

Step 9: Clean up open Excel Application and Workbook

Now is the part that is typical for END block and that is clean up of used resources. We clean up Excel Application and Workbook and send information to Garbage Collector to do that for us.

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbookObject) | Out-

$excelObject.Quit() 

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelObject) | Out-Null

[System.GC]::Collect() 
[System.GC]::WaitForPendingFinalizers()

TIP: While I was writing and debugging this code I have used Process Explorer from Sysinternals Tools Suite in order to see what is happening with the Excel process created in the background in order to be able to release all the resources after processing finished.

INFO: If you want to know more about PowerShell Debugging please read this article with many useful examples How To Debug PowerShell Scripts.

Step 10: Delete Temporary CSV file created in Step 2

Do not forget to delete the temporary CSV file created in step 2. This step is another use of END block in post-processing clean up of the resources fashion.

if(Test-Path -path $temporaryCsvFile) { 
        Remove-Item -path $temporaryCsvFile -ErrorAction Stop
        Write-Verbose "Temporary csv file deleted: $temporaryCsvFile" 
}

Step 11: Optionally, send Excel file as a zipped attachment to some email account

I have implemented the possibility to send email using my own Send-Email CmdLet.

            if ( $sendemail ) {
        
                $errorlogfile = "$home\Documents\PSlogs\Error_Log.txt"
                $attachments = "$errorlogfile","$excelFile"
            
                Write-Verbose "Sending email."
                Send-Email -Attachments $attachments -Priority "Normal" -errorlog -client $client -solution $solution
                Write-Verbose "Email sendt."
             }

DISCLAIMER: This feature will not work until Send-Email CmdLet is customized to your own SMTP server settings.

Step 12: Error Handling

All the code that we have discussed in previous steps has been wrapped in a try block in order to have the possibility of trapping the errors. In the catch block, we handle the errors writing them in an external Error Log text file. For writing errors in an external file, we can use my own Write-ErrorLog CmdLet.

} catch {
        Write-Warning "SaveToExcel function failed"
        Write-Warning "Error message: $_"

        if ( $errorlog ) {

            $errormsg = $_.ToString()
            $exception = $_.Exception
            $stacktrace = $_.ScriptStackTrace
            $failingline = $_.InvocationInfo.Line
            $positionmsg = $_.InvocationInfo.PositionMessage
            $pscommandpath = $_.InvocationInfo.PSCommandPath
            $failinglinenumber = $_.InvocationInfo.ScriptLineNumber
            $scriptname = $_.InvocationInfo.ScriptName

            Write-Verbose "Start writing to Error log."
            Write-ErrorLog -hostname "SaveToExcel has failed" -errormsg $errormsg -exception $exception -scriptname $scriptname -failinglinenumber $failinglinenumber -failingline $failingline -pscommandpath $pscommandpath -positionmsg $pscommandpath -stacktrace $stacktrace
            Write-Verbose "Finish writing to Error log."
        } 
    } 

INFO: Error handling is important in each programming language since no one likes programs with bugs. PowerShell is no exception to that and I have written an article on the subject with an example function that writes errors in external text file How To Log PowerShell Errors And Much More.

Regions Of Save-ToExcel Function

I like to organize my code in regions using region and end region tags so when the code is collapsed I can see what the code is all about.

Save-ToExcel is no exception to that rule and consist of three regions:

  1. No region since this breaks functionality for comment-based Help content.
  2. Save-ToExcel function “region”.
  3. Execution examples region which contains different calls to the function.
Regions collapsed

INFO: If you want to learn how to write your own function help content please read How To Write PowerShell Help (Step by Step).

How To Use Excel Reports – Examples

I am sure everyone has their own needs regarding usage of Excel reports created using PowerShell but let me just quickly give you my few examples.

  1. For documentation purposes, I was creating Excel reports with different information about the environment working:
    • CPU properties of all servers in the environment
    • OS information
    • Network information
    • Memory information
    • Printer information
    • Application installation
  2. For maintenance purposes:
    • Errors from Event Logs
  3. For capacity planning:
    • Free Disk Space

Save-ToExcel Function Source Code

DISCLAIMER: Save-ToExcel function is part of the Efficiency Booster PowerShell Project and as such utilize other CmdLets that are part of the same project. So the best option for you in order for this function to work without any additional customization is to download the source code of the whole project from here.

Here is the source code of Save-ToExcel function:

<#
.SYNOPSIS
Save Powershell output objects as Excel file.
.DESCRIPTION
Save Powershell cmdlet output objects as Excel file.
In order to overcome performance issue of writting to Excel row by row in Powershell.
This function uses trick to improve performance and that is to save Powershell objects from pipe into temporary .csv file first and later to use that file to create and format Excel file fast.
.PARAMETER InputObject
Any object that will be saved as Excel file. Send through PowerShell pipeline.
.PARAMETER ExcelFileName
Prefix of Excel file name. File name has Time stamp at the and in name with date and time.
.PARAMETER title
Title property of Excel workbook.
.PARAMETER author
Author property of Excel woorkbook.
.PARAMETER WorkSheetName
Name of Excel Worksheet.
.PARAMETER errorlog
write to error log or not.
.PARAMETER client
OK - O client
BK - B client
.PARAMETER solution
FIN - Financial 
HR - Humane Resource 
.PARAMETER sendemail
Turns on or off sending of emails from this CmdLet.
.EXAMPLE
Get-OSInfo -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "OS_Info" -title "OS Info for servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "OS Info" -client "OK" -solution "FIN" 
.EXAMPLE
Get-Printer -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "Printers_With_Error" -title "Printers with errors on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Printers with errors" -client "OK" -solution "FIN" 
.EXAMPLE
Get-Printer -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "Printers_With_Error" -title "Printers with errors on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Printers with errors" -sendemail -client "OK" -solution "FIN" 
.EXAMPLE
Get-DiskFreeSpace -filename "OKFINservers.txt" -client "OK" -solution "FIN" -Verbose -errorlog | Save-ToExcel -ExcelFileName "Free_disk_space" -title "Free disk space on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Free disk space" -sendemail -client "OK" -solution "FIN" 
.EXAMPLE
Get-ErrorFromEventLog -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -days 3 -Verbose | Save-ToExcel -ExcelFileName "Get-ErrorsInEventLogs" -title "Get errors from Event Logs on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Errors from Event Logs" -sendemail -client "OK" -solution "FIN" 
.EXAMPLE
Get-ErrorFromEventLog -filename "OKFINkursservers.txt" -errorlog -client "OK" -solution "FIN" -days 3 -Verbose | Save-ToExcel -ExcelFileName "Get-ErrorsInEventLogs" -title "Get errors from Event Logs on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Errors from Event Logs" -client "OK" -solution "FIN" 

.INPUTS
System.Management.Automation.PSCustomObject

InputObjects parameter pipeline both by Value and by Property Name value. 

.OUTPUTS
System.Boolen

.NOTES
FunctionName : Save-ToExcel
Created by   : Dejan Mladenovic
Date Coded   : 10/31/2018 19:06:41
More info    : https://improvescripting.com/

.LINK 
Export-Csv
New-Object -ComObject
#>
Function Save-ToExcel {
[CmdletBinding()]
param (
    [Parameter(Mandatory=$true,
                ValueFromPipeline=$true, 
                HelpMessage="Input rows to be saved as Excel file.")] 
    [PSobject[]]$InputObject,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel file name.")]
    [string]$ExcelFileName,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel workbook title.")]
    [string]$title,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel workbook author.")]
    [string]$author,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Excel worksheet name.")]
    [string]$WorkSheetName,
    
    [Parameter(HelpMessage="Write to error log file or not.")]
    [switch]$errorlog,
    
    [Parameter( HelpMessage="Send email.")]
    [switch]$sendemail,
    
    [Parameter(Mandatory=$true, 
                HelpMessage="Client for example OK = O client, BK = B client")]
    [string]$client,
     
    [Parameter(Mandatory=$true,
                HelpMessage="Solution, for example FIN = Financial solution, HR = Humane Resource solution")]
    [string]$solution
    
    
)
BEGIN { 
    
    #Creat an empty array
    $objects = @()

    $reportsfolder = "$home\Documents\PSreports"
        
        if  ( !( Test-Path -Path $reportsfolder -PathType "Container" ) ) {
            
            Write-Verbose "Create reports folder in: $reportsfolder"
            New-Item -Path $reportsfolder -ItemType "Container" -ErrorAction Stop
        }
        
}
PROCESS { 

    $objects += $InputObject
    
}
END { 

    $date = Get-Date -UFormat "%Y-%m-%d_%H-%M-%S"

    $excelFile = "$home\Documents\PSreports\$ExcelFileName" + "-" + "$client" + "-" + "$solution" + "-" + $date + ".xlsx"

    try {
        
        #Write Excel file only if there are some Input objects!!!!!
        if ( $objects ) {

            [System.Threading.Thread]::CurrentThread.CurrentCulture = "en-US"

            #Temporary .csv file with GUID name has been created first.
            $temporaryCsvFile = ($env:temp + "\" + ([System.Guid]::NewGuid()).ToString() + ".csv") 
            #Delimiter ";" helps that result is parsed correctly. Comma delimiter parses incorrectly.
            $objects | Export-Csv -ErrorAction Stop -path $temporaryCsvFile -noTypeInformation -Delimiter ";"
            Write-Verbose "Temporary csv file saved: $temporaryCsvFile"
        
            $excelObject = New-Object -ComObject Excel.Application -ErrorAction Stop
            Write-Verbose "Excel sheet created."
            $excelObject.Visible = $false    

            $workbookObject = $excelObject.Workbooks.Open($temporaryCsvFile)  
            $workbookObject.Title = ("$title " + (Get-Date -Format D)) 
            $workbookObject.Author = "$author"
        
            $worksheetObject = $workbookObject.Worksheets.Item(1) 
        
            #Method TextToColumns is important to convert .csv file data into right columns in Excel file.
            $colA=$worksheetObject.range("A1").EntireColumn
            $colrange=$worksheetObject.range("A1")
            $xlDelimited = 1
            $xlTextQualifier = 1
            $colA.TextToColumns($colrange,$xlDelimited,$xlTextQualifier,$false,$false,$false,$true)
     
            $worksheetObject.UsedRange.Columns.Autofit() | Out-Null
            $worksheetObject.Name = "$WorkSheetName"
        
            #Style of table in Excel worksheet.
            $xlSrcRange = 1
            $XlYes = 1
            #Syntax - expression.Add(SourceType, Source, LinkSource, HasHeaders, Destination)
            $listObject = $worksheetObject.ListObjects.Add($xlSrcRange, $worksheetObject.UsedRange, $null, $XlYes, $null) 
            $listObject.Name = "User Table"
            $listObject.TableStyle = "TableStyleMedium6" # Style Cheat Sheet in French/English: http://msdn.microsoft.com/fr-fr/library/documentformat.openxml.spreadsheet.tablestyle.aspx   

            $workbookObject.SaveAs($excelFile,51) # http://msdn.microsoft.com/en-us/library/bb241279.aspx 
            $workbookObject.Saved = $true
            $workbookObject.Close() 
            [System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbookObject) | Out-Null  

            $excelObject.Quit() 
            [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelObject) | Out-Null
            [System.GC]::Collect() 
            [System.GC]::WaitForPendingFinalizers()    
            Write-Verbose "Excel application process deleted from the system."
        
            if(Test-Path -path $temporaryCsvFile) { 
                Remove-Item -path $temporaryCsvFile -ErrorAction Stop
                Write-Verbose "Temporary csv file deleted: $temporaryCsvFile" 
            }
        
            if ( $sendemail ) {
        
                $errorlogfile = "$home\Documents\PSlogs\Error_Log.txt"
                $attachments = "$errorlogfile","$excelFile"
            
                Write-Verbose "Sending email."
                Send-Email -Attachments $attachments -Priority "Normal" -errorlog -client $client -solution $solution
                Write-Verbose "Email sendt."
             }
        
        }
    } catch {
        Write-Warning "SaveToExcel function failed"
        Write-Warning "Error message: $_"

        if ( $errorlog ) {

            $errormsg = $_.ToString()
            $exception = $_.Exception
            $stacktrace = $_.ScriptStackTrace
            $failingline = $_.InvocationInfo.Line
            $positionmsg = $_.InvocationInfo.PositionMessage
            $pscommandpath = $_.InvocationInfo.PSCommandPath
            $failinglinenumber = $_.InvocationInfo.ScriptLineNumber
            $scriptname = $_.InvocationInfo.ScriptName

            Write-Verbose "Start writing to Error log."
            Write-ErrorLog -hostname "SaveToExcel has failed" -errormsg $errormsg -exception $exception -scriptname $scriptname -failinglinenumber $failinglinenumber -failingline $failingline -pscommandpath $pscommandpath -positionmsg $pscommandpath -stacktrace $stacktrace
            Write-Verbose "Finish writing to Error log."
        } 
    } 
}


}
#region Execution examples
#Get-OSInfo -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "OS_Info" -title "OS Info for servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "OS Info" -client "OK" -solution "FIN" -errorlog -Verbose

#Get-Printer -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "Printers_With_Error" -title "Printers with errors on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Printers with errors" -client "OK" -solution "FIN" 

#Get-Printer -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "Printers_With_Error" -title "Printers with errors on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Printers with errors" -sendemail -client "OK" -solution "FIN" 

#Get-DiskFreeSpace -filename "OKFINservers.txt" -client "OK" -solution "FIN" -Verbose -errorlog | Save-ToExcel -ExcelFileName "Free_disk_space" -title "Free disk space on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Free disk space" -sendemail -client "OK" -solution "FIN" 

#Get-ErrorFromEventLog -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -days 3 -Verbose | Save-ToExcel -ExcelFileName "Get-ErrorsInEventLogs" -title "Get errors from Event Logs on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Errors from Event Logs" -sendemail -client "OK" -solution "FIN" 

#Get-ErrorFromEventLog -filename "OKFINkursservers.txt" -errorlog -client "OK" -solution "FIN" -days 3 -Verbose | Save-ToExcel -ExcelFileName "Get-ErrorsInEventLogs" -title "Get errors from Event Logs on servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "Errors from Event Logs" -client "OK" -solution "FIN" 

#Get-CPUInfo -filename "OKFINservers.txt" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "Get-CPUinfo" -title "Get CPU info of servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "CPU Info" -client "OK" -solution "FIN" 

#Get-CPUInfo -computers "localhost" -errorlog -client "OK" -solution "FIN" -Verbose | Save-ToExcel -ExcelFileName "Get-CPUinfo" -title "Get CPU info of servers in Financial solution for " -author "ImproveScripting.com With Dejan" -WorkSheetName "CPU Info" -client "OK" -solution "FIN" 

#endregion

About Dejan Mladenović

Hey Everyone! I hope that this article you read today has taken you from a place of frustration to a place of joy coding! Please let me know of anything you need for Windows PowerShell in the comments below that can help you achieve your goals!
I have 18+ years of experience in IT and you can check my Microsoft credentials. Transcript ID: 750479 and Access Code: DejanMladenovic
Credentials
About Me...

My Posts | Website

Dejan Mladenović

Hey Everyone! I hope that this article you read today has taken you from a place of frustration to a place of joy coding! Please let me know of anything you need for Windows PowerShell in the comments below that can help you achieve your goals! I have 18+ years of experience in IT and you can check my Microsoft credentials. Transcript ID: 750479 and Access Code: DejanMladenovic
Credentials About Me...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Content