Samples/ImportCallhomeDetails/InFile/readInFile.ps1
# ------------------------------------------------------------------ # Lenovo Copyright # # (C) Copyright Lenovo 2024 - present. # # LIMITED AND RESTRICTED RIGHTS NOTICE: # If data or software is delivered pursuant a General Services # Administration (GSA) contract, use, reproduction, or disclosure # is subject to restrictions set forth in Contract No. GS-35F-05925. # ------------------------------------------------------------------ try { Import-Module ImportExcel -ErrorAction Stop } catch { throw ` "`nImportExcel module is not installed." + ` "`nPlease get the module from https://www.powershellgallery.com/packages/ImportExcel" } function ReadContent () { param ( [Parameter(Mandatory = $true)] [string] $File ) $File = [IO.Path]::GetFullPath($File) if (-not (Test-Path -Path $File)) { throw "File '$($File)' does not exist." } Write-Host "Using $File to generate devices/addresses lists ..." $fileName = [System.IO.Path]::GetFileName($File) if ([System.IO.Path]::GetExtension($fileName) -eq ".csv") { return Import-Csv -Path $File } elseif ([System.IO.Path]::GetExtension($fileName) -eq ".xlsx") { return Import-Excel -Path $File -WorksheetName * -Raw } } # EOF |