$excelpath = 'D:\test.xlsx' $excel = new-object -comobject excel.application $workbook = $excel.Workbooks.Open($excelpath) # Open Excel File $workbook.Worksheets.Add() |Out-Null # Add new sheet $sheet1 = $workbook.Worksheets.Item(1) $sheet1.Name = "ServerList" # Rename new sheet $sheet1.Cells.Item(1, 1) = 'Item' # First Parameter is Row , Second Parameter is Column $serverinfo_sheet = $workbook.Worksheets.Item('ServerInfo') # Find specify Sheet Name $serverinfo_range = $serverinfo_sheet.UsedRange # Used Range $serverinfo_range.EntireColumn.AutoFit() |Out-Null #Used Range Auto Fit $serverinfo_range.Borders.LineStyle = 1 # Used Range border $serverinfo_rowscount = $serverinfo_sheet.Rows.Count # Rows Count