sterlingwhe.blogg.se

Powershell import csv
Powershell import csv










powershell import csv

#Write-ErrorLog -hostname "Get-ComputerInfo was failing." -errormsg $errormsg -exception $exception -scriptname "GetComputerInfo.ps1" Write-ErrorLog -hostname "Get-ComputerInfo CmdLet was failing." -env "ALL" -logicalname "ALL" -errormsg $errormsg -exception $exception -scriptname $scriptname -failinglinenumber $failinglinenumber -failingline $failingline -pscommandpath $pscommandpath -positionmsg $pscommandpath -stacktrace $stacktrace Write-Verbose "Start writing to Error log." $pscommandpath = $_.InvocationInfo.PSCommandPath $positionmsg = $_.InvocationInfo.PositionMessage $failingline = "Test-Path -Path $importfile -PathType Leaf" $exception = "Read Get-ComputerInfo CmdLet help to find out more info." $errormsg = "List of server names file $importfile does not exist." Write-Warning "Read Get-ComputerInfo CmdLet help to find out more info." Write-Warning "List of server names file $importfile does not exist." Write-Warning "Get-ComputerInfo CmdLet failed." That will create the list of servers ( $computers) that we want to process with our Get-CPUInfo CmdLet BEGIN | Select-Object -Property hostname, ipaddress, logicalname, environment Step 1 – Read the text file in Get-CPUInfo CmdLet using Get-Content CmdLet.

#Powershell import csv code#

Here are the code snippets of the implementation: The content of text files is very similar to the content of the example from the beginning of this article.ĬPU properties for a list of servers using Get-CPUInfo CmdLet

  • OKFINservers.txt for all servers and all environments, etc.īasically, I segment the CSV repository of all servers with the lists in text files based on the need.
  • OKFINCourseservers.txt for Course environment servers,.
  • OKFINProdservers.txt for Production environment servers,.
  • OKFINTestservers.txt for Test environment servers,.
  • I do not have a strict naming convention for these text files but in order to be organized, I usually name them following similar naming convention as for CSV file. This gives me the possibility to segment all the servers for example by the environment (Test, Course, Acceptance, Production, etc.) so I have text files for only Test servers or only Production servers or Course servers or all the servers in the environment. These text files are used as inputs to decide which servers will be processed with certain CmdLet. I have separate text files that contain only the list of server names and they are a subset of CSV file.

    powershell import csv

    OKFINservers.csv file content example Text Files












    Powershell import csv