Powershell modify CSV - powershell

I read a lot of questions here about this and i don't find what i search ...
I start scripting with powershell (just for information :p )
I want to modify a CSV file, exported from a database with information like "FirstName,LastName,OtherMail,IDAurion,Department". I have to add some titles to the HEADER, and i have to take informations in the CSV to concatenate some informations and put them in another CSV file.
I don't know if i explain well, i put you my script :
$OriginalCSV = "$PSScriptRoot\original.csv"
function Remove-StringLatinCharacters
{
PARAM ([string]$String)
[Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($String))
}
Import-Csv -path $OriginalCSV -Encoding Default | ForEach-Object {
$OtherMail = $_.OtherMail
$IDAurion = $_.IDAurion
$Department = $_.Department
$FirstnameCSV = $_.FirstName
$FirstName = $FirstnameCSV -replace '(^\s+|\s+$)',''
$FirstnameNoLatin = Remove-StringLatinCharacters $FirstName
$FirstnameNoLatinNoSpace = $FirstnameNoLatin -replace '\s','-'
$FirstnameFirstLetterUpper = $Firstname.Substring(0,1).ToUpper()
$LastNameCSV = $_.LastName
$LastName = $LastnameCSV -replace '(^\s+|\s+$)',''
$LastnameNoLatin = Remove-StringLatinCharacters $LastName
$LastnameNoLatinNoSpace = $LastnameNoLatin -replace '\s',''
$LastnameFirstLetterUpper = $Lastname.Substring(0,1).ToUpper()
$UserPrincipalNameCSV = $FirstnameCSV + "." + $LastNameCSV + "#campus.ocellia.fr"
$UserPrincipalNameConcatene = $FirstnameNoLatinNoSpace + "." + $LastNameNoLatinNoSpace + "#email.fr"
$UserPrincipalName = $UserPrincipalNameConcatene.ToLower()
$MailNickName = $FirstnameNoLatinNoSpace.substring(0,1).toupper() + $($FirstnameNoLatin.substring(1).tolower() -replace '\s','') + $LastnameNoLatinNoSpace.toupper()
$Password = $FirstnameFirstLetterUpper + $LastnameFirstLetterUpper + $IDAurion + "$"
$Number = 0
Get-Content $OriginalCSV |
ForEach-Object{
If($Number -eq 0){
$_ + ",MailNickName" + ",Password" + ",UserPrincipalName"
$Number = 1
}
Else {
$_ + "," + $MailNickName + "," + $Password + "," + $UserPrincipalName
}
} | Out-File $PSScriptRoot\Modified-CSV.csv
}
This work for 1 line, but not for multiples line ...
Edit :
This is the examples for input CSV and how i want the resulting output CSV:
Input csv :
Firstname,Lastname,OtherMail,ID,Department
Pierre,DUPONT,pierre.dupont#mail.com,123456,Paris
Marie,CHANTAL,marie.chantal#mail.com,456789,Marseille
Output csv:
Firstname,Lastname,OtherMail,ID,Department,MailNickName,Password,UserPrincipalName
Pierre,DUPONT,pierre.dupont#mail.com,123456,Paris,PierreDupont,PD123456,p.dupont#entreprise.com
Marie,CHANTAL,marie.chantal#mail.com,456789,Marseille,MarieCHANTAL,MC456789,m.chantal#entreprise.com

I'm guessing this is what you're trying to do but since we don't have a minimal reproducible example it's quite hard to tell. I also attempted to improve your code, there was a lot of redundancy.
$OriginalCSV = "$PSScriptRoot\original.csv"
$ModifiedCSV = "$PSScriptRoot\modified.csv"
$txtInfo = (Get-Culture).TextInfo
function Remove-StringLatinCharacters
{
PARAM ([string]$String)
[Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($String))
}
(Import-Csv -Path $OriginalCSV -Encoding Default | ForEach-Object {
$OtherMail = $_.OtherMail.Trim()
$IDAurion = $_.IDAurion.Trim()
$Department = $_.Department.Trim()
$FirstnameCSV = $_.FirstName.Trim()
$LastNameCSV = $_.LastName.Trim()
$firstName = (Remove-StringLatinCharacters $FirstName) -replace '\s','-'
$lastName = (Remove-StringLatinCharacters $LastName) -replace '\s'
$UserPrincipalName = "$FirstnameCSV.$LastNameCSV#campus.ocellia.fr"
$UserPrincipalNameConcat = "$firstName.$lastName#email.fr".ToLower()
$MailNickName = $txtInfo.ToTitleCase($firstName) + $lastName.ToUpper()
$Password = "{0}{1}$IDAurion$" -f $firstName.ToUpper()[0],$lastName.ToUpper()[0]
[pscustomobject]#{
FirstNameCSV = $FirstnameCSV
LastNameCSV = $LastNameCSV
OtherMail = $OtherMail
IDAurion = $IDAurion
Department = $Department
MailNickName = $MailNickName
Password = $Password
UserPrincipalNameCAMPUS = $UserPrincipalName
UserPrincipalNameEMAILFR = $UserPrincipalNameConcat
}
} | ConvertTo-Csv -NoTypeInformation) -replace '"' |
Out-File $ModifiedCSV

Related

Script that doesn't validate argument

I have this script, it searches a Word document for "Detection Method Type", then pulls the value from the 5th line along, say "C:\program files\test\notepad.exe", the script should then split it to $filepath = C:\program files\test and $file = notepad.exe.
I get the following error when trying to pass the above to new-cmdetectionclausefile:
New-CMDetectionClauseFile : Cannot validate argument on parameter 'FileName'. System.Management.Automation.ValidationMetadataException
At line:8 char:70
+ ... new-CMdetectionClauseFile -path $filepathexe -filename $file -Existe ...
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [New-CMDetectionClauseFile], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ConfigurationManagement.PowerShell.Cmdlets.Dcm.NewDetectionClauseFile*
ERROR:
the problem happens with the $file even though it's populated
pre-requisites:
myscript
configurationmanager.ps1
docx that contains: Detection Method Type C:\program files\test\notepad.exe
script:
param($documentPath)
function get-documentclause{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)][string]$documentPath
)
$documentPath = "D:\Documents\Packaging Scripts\test.docx"
<#
cells have an end-of-0cell marker of two chars (bytes 13 and 7)
we will need to trim these later
convert bytes to char and join as string
#>
$endOfCellMarker = -join #([char][byte]13, [char][byte]7)
# instantiate Word Com Object
$wordApplication = New-Object -ComObject Word.Application
<#
open the document:
param 1 = FileName
param 2 = ConfirmConversions
param 3 = ReadOnly$doclause
(param 2 only needed because this method accepts only positional parameters)
see https://learn.microsoft.com/en-us/office/vba/api/word.documents.open
#>
$wordDocument = $wordApplication.Documents.Open($documentPath, $false, $true)
$doclause = ""
$regclause = ""
$fileclause = ""
try{
#check to see if document is a table or paragraph
$count = 0
foreach($tables in $wordDocument.Tables){
$count++
}
#if document is true (paragraph) else it will be treated as table
if($count -eq 1){
$count = 0
foreach($para in $wordDocument.Paragraphs){
#Write-Host $para.range.text
#Write-Host "$count"
#$wordtolookfor = $para.Range(3).Text
$word = $para.Range.text
#$word
#pause
if ($word -like "*Detection Method Type*"){
$num = $count + 5
#Write-Host $wordDocument.Paragraphs($num).range.text
$doclause = $wordDocument.Paragraphs($num).range.text
} #end of if
$count++
}#end of foreach
} else {$doclause = $wordDocument.Tables.Item(8).cell(4,2).range.text}
}catch{}
#test if the clause makes sense
$doclause = $doclause.ToString().Trim()
#test if detection method contains exe or registry path
if(($doclause -like "*.exe*") -xor ($doclause -like "*CurrentVersion\Uninstall*")){
if($doclause -like "*.exe*") {
[string]$filepathexe = split-path -parent $doclause
[string]$file = $doclause.Split("\") | Select-Object -last 1
$fileclause = new-CMdetectionClauseFile -path $filepathexe -filename $file -Existence
} #end of exe clause
#if file does contain reg run the following
elseif($doclause -like "*CurrentVersion\Uninstall*") {
#selects the first backslash
$hive = $doclause.Split("\") | Select-Object -First 1
#replaces the underscore withnothing
$hive = $hive.Replace("_","")
#removes the first 4 characters HKEY
$hive = $hive.substring(4)
#produce the rest of the key
$path = $doclause.Split("\") | Select-Object -last 7
$path = $path -join "\"
$path = Split-Path $path -Parent
#get final value
$regvalue = Split-Path -Leaf $doclause
$regclause = New-CMDetectionClauseRegistryKeyValue -Hive $hive -KeyName $path -PropertyType String -ValueName $regvalue -Existence
} #end of reg clause
else {
$regclause = ""
$fileclause = ""
}
} #end of testing clause
else {$doclause = ""}
$nothing = ""
# close the file and do not save changes
$wordDocument.Close([ref] [Microsoft.Office.Interop.Word.WdSaveOptions]::wdDoNotSaveChanges)
# end the WINWORD.EXE process
$wordApplication.Quit()
if($regclause){
return $regclause
#return #($hive,$path,$regvalue) this works but testing if previous would have worked too
}
elseif($fileclause){return $fileclause}
else {
Return $nothing
$regclause = ""
$fileclause = ""
}
}
answer found
before
$fileclause = new-CMdetectionClauseFile -path $filepathexe -filename $file -Existence
add:
$asd = [string]$file -replace"\u007",""
$asd2 = [string]$asd -replace"t|n|r",""`
then change
$fileclause = new-CMdetectionClauseFile -path $filepathexe -filename $asd2 -Existence
exporting $file to a text file you get the expect result plus a "[]" symbol, loading that in to notepad++ it can be resolved to 0007 which is Unicode for a bell symbol, remove that and what not.

Is it possible to autocomplete a Read-Host prompt with previous Get command output. Without saving an output file

I am writing a script to deploy VM hosts and I want to run a Get command to show them available options and then use their input with autocomplete from previous GET command. I do this because I want to avoid any typos that can be made during manual input.
I have tried using Select-string but I think it saves to .txt file and I don't want this to be saved in a txt file. I would rather have it saved in variable.
Get-VMHost | Select-Object -Property Name | Format-Table -Property Name
$VMHost = Read-Host -Prompt 'Please select the host for your VM
I expect the user to be able to autocomplete string with output from previously executed GET command. Please help if you can
Here is a New-ChoicePrompt function I use for similar purposes.
function New-ChoicePrompt { [cmdletBinding()]
param(
[parameter(mandatory=$true)]$Choices,
$Property,
$ReadProperty,
$ExprLabel,
[switch]$AllowManualInput,
[Scriptblock]$ReadPropertyExpr,
$ManualInputLabel = "Type my own"
)
if ( $choices[0] -isnot [string] -and !$property ) {"Please include New-ChoicePrompt -Property unless -Choices is an array of strings."; break}
if ( $choices[0] -is [string] -and ($property -or $ReadProperty) ) {"When New-ChoicePrompt -Choices is an array of strings, please omit -Property and -ReadProperty."; break}
#if ( $choices[0] -isnot [string] -and $allowManualInput ) {"When New-ChoicePrompt -Choices is a PSobject, please omit -AllowManualInput"; break}
$x = 0; $script:options = #()
$script:propty = $property
$script:choices = $choices
$manualInputLabel = "<" + $manualInputLabel + ">"
foreach ($item in $choices) { $value = $null
$x += 1
if ($property) { $value = $item | select -expand $property } `
else {$value = $item}
if ($readProperty) {
$readVal = $item | select -expand $readProperty
$row = new-object -type psObject -property #{Press = $x; 'to select' = $value; $readproperty = $readVal}
} ` #close if readProperty
elseif ($readPropertyExpr) `
{
$readVal = & $ReadPropertyExpr
$row = new-object -type psObject -property #{Press = $x; 'to select' = $value; $ExprLabel = $readVal}
}` #close if readPropertyExpr
else { $row = new-object -type psObject -property #{'to select' = $value; Press = $x} }
$script:options += $row
} #close foreach
if ($AllowManualInput) {
$row = new-object -type psObject -property #{'to select' = $manualInputLabel; Press = ($x + 1) }
$script:options += $row
} #close if allowManualInput
if ($ReadProperty) { $script:options | Select Press, "to select", $readproperty | ft -auto }
elseif ($ReadPropertyExpr) { $script:options | Select Press, "to select", $ExprLabel | ft -auto }
else { $script:options | Select Press, "to select" | ft -auto }
} #end function new-choicePrompt
Here is a usage example.
$vmhosts = Get-VMHost | sort Name
if ($vmhosts.count -gt 1) {
do {
new-choicePrompt -choices $vmhosts -property name
$in = read-host -prompt 'Please select a target host'
$range = $options | select -expand press
} #close do
until ($range -contains $in)
$selection = $options | where {$_.press -eq $in} | select -expand 'To select'
$choice = $choices | where {$_.#($propty) -eq $selection}
$vmHost = $choice
} else {$vmhost = $vmhosts} #close if multiple hosts
"Target host: " + $vmhost.name
If it was a function parameter, you could limit the values with [ValidateSet] like from here: https://www.mssqltips.com/sqlservertip/4205/powershell-parameters-part-ii--validateset-and-validatepattern/ It ends up supporting tab completion as well. If you set it to mandatory, it will prompt for it as well, if it's not given.
Function Pass-Set {
Param(
[ValidateSet("oro","plata")][string]$specificstring
)
Process
{
Write-Host "It must be one of two words; in this case $specificstring."
}
}
pass-set -specificstring oro
It must be one of two words; in this case oro.
pass-set -specificstring plata
It must be one of two words; in this case plata.
pass-set -specificstring plata2
Pass-Set : Cannot validate argument on parameter 'specificstring'. The argument "plata2" does not belong to the set "oro,plata" specified by the
ValidateSet attribute. Supply an argument that is in the set and then try the command again.
At line:1 char:26
+ pass-set -specificstring plata2
+ ~~~~~~
+ CategoryInfo : InvalidData: (:) [Pass-Set], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Pass-Set

How to handle looping to create file using powershell?

I have INI file and I want to get specific section. The items in the section that I choose are 24 items. I want to use all the item to write in a file. I tried this, It works, but it looks like bad way to write 24 times to do the process. Is there any other way to do that more beautiful? The section of my INI file like this
Input ini:
[Code]
A1=12,34,56
A2=23,45,67
A3=34,56,78,9,10
...
A24=a1,b2,c3,d4,e5
Script:
Function F_ML
{
$FilePath = "C:\Users\File.ini"
$section = "Code"
$R_1 = "A1"
$R_2 = "A2"
$R_3 = "A3"
$R_4 = "A4"
$R_5 = "A5"
$R_6 = "A6"
$R_7 = "A7"
$R_8 = "A8"
$R_9 = "A9"
$R_10 = "A10"
$R_11 = "A11"
$R_12 = "A12"
$R_13 = "A13"
$R_14 = "A14"
$R_15 = "A15"
$R_16 = "A16"
$R_17 = "A17"
$R_18 = "A18"
$R_19 = "A19"
$R_20 = "A20"
$R_21 = "A21"
$R_22 = "A22"
$R_23 = "A23"
$R_24 = "A24"
$store = "C:\Users\"
$FilePath
$input_file = $FilePath
$ini_file = #{}
Get-Content $input_file | ForEach-Object {
$_.Trim()
} | Where-Object {
$_ -notmatch '^(;|$)'
} | ForEach-Object {
if ($_ -match '^\[.*\]$') {
$section = $_ -replace '\[|\]'
$ini_file[$section] = #{}
} else {
$key, $value = $_ -split '\s*=\s*', 2
$ini_file[$section][$key] = $value
}
}
#--------
$Path_Store = $store
#---------
$Get_1 = $ini_file.($section).($R_1)
$L_1 = $Get_1.Substring(0,3)
$Get_2 = $ini_file.($section).($R_2)
$L_2 = $Get_2.Substring(0,3)
$Get_3 = $ini_file.($section).($R_3)
$L_3 = $Get_3.Substring(0,3)
#---------
$Outer = ";********************"
$Header = ";*******************"
$ML = "12345"
$FB = ";Initial=1a2b"
#----------
$B_ID_1 = ";Build=" + $ML + "#" + "S" + $L_1 + "#" + "D" + $L_1
$CRM_1 = ";CRM=" + $R_1
$Output_1 = $Header, $B_ID_1, $FB, $CRM_1 , $Outer | Out-File $Path_Store\A1
$B_ID_2 = ";Build=" + $ML + "#" + "S" + $L_2 + "#" + "D" + $L_2
$CRM_2 = ";CRM=" + $R_2
$Output_2 = $Header, $B_ID_2, $FB, $CRM_2 , $Outer | Out-File $Path_Store\A2
$B_ID_3 = ";Build=" + $ML + "#" + "S" + $L_3 + "#" + "D" + $L_3
$CRM_3 = ";CRM=" + $R_3
$Output_3 = $Header, $B_ID_3, $FB, $CRM_3 , $Outer | Out-File $Path_Store\A3
#---------
}
$call = F_ML
My expectation, I can make this way shorter and the output is getting 24 output file.
Output Sample
Output File 1
;********************
;Build=12345#S12#D12
;Initial=1a2b
;CRM=A1
;********************
Output File 2
;********************
;Build=12345#S23#D23
;Initial=1a2b
;CRM=A2
;********************
Try below...
$IniContent = Get-Content -Path $IninPath
$IniContent | ForEach-Object -Process {
$Split = $_ -split '=';
$OutPutfilePath = "c:\temp\$($Split[0]).txt"
$first = ($Split[1] -split ',')[0]
$append = "#S{0}D{1}" -f $first,$first
# create a herestring to build the output
#"
;********************
;Build=$Ml$append
$FB
;CRM=$($Split[0])
;********************
"# | Out-File -Path $OutPutfilePath -Force
}
Use a ForEach to manipulate a string and Invoke the Expression.
1..24 | ForEach-Object { Invoke-Expression -Command (
'$R_{0} = "A{0}"' -f $_
)}
.
.
.
1..24 | ForEach-Object { Invoke-Expression -Command (
'$Get_{0} = $ini_file.($section).($R_{0}) `
$L_{0} = $Get_{0}.Substring(0,3)' -f $_
)}
.
.
.
1..24 | ForEach-Object { Invoke-Expression -Command (
'$B_ID_{0} = ";Build=" + $ML + "#" + "S" + $L_{0} + "#" + "D" + $L_{0}
$CRM_{0} = ";CRM=" + $R_{0}
$Output_{0} = $Header, $B_ID_{0}, $FB, $CRM_{0} , $Outer | Out-File $Path_Store\A{0}' -f $_
)}
{0} will be replaced by the value behind -f so it will be replaced Foreach number from 1 to 24...
Would this work?
All I did here was use your existing code to run everything in a loop from 1 to 24, removing the duplicated code. I reformatted it a little so it was a little easier for me to read.
Essentially, the variable $i will be a number from 1 to 24, while the variable $R will be "A" and whatever number is in $i (essentially A + $i)
Function F_ML
{
$section = "Code"
$store = "C:\Users\"
$input_file = "C:\Users\File.ini"
$ini_file = #{}
for ($i=1; $i -le 24; $i++)
{
$R = "A$($i)"
Get-Content $input_file |
ForEach-Object `
{
$_.Trim()
} |
Where-Object `
{
$_ -notmatch '^(;|$)'
} |
ForEach-Object `
{
if ($_ -match '^\[.*\]$')
{
$section = $_ -replace '\[|\]'
$ini_file[$section] = #{}
}
else
{
$key, $value = $_ -split '\s*=\s*', 2
$ini_file[$section][$key] = $value
}
}
#--------
$Path_Store = $store
#---------
$Get = $ini_file.($section).($R)
$L = $Get.Substring(0,3)
#---------
$Outer = ";********************"
$Header = ";*******************"
$ML = "12345"
$FB = ";Initial=1a2b"
#----------
$B_ID = ";Build=" + $ML + "#" + "S" + $L + "#" + "D" + $L
$CRM = ";CRM=" + $R
$Output = $Header, $B_ID, $FB, $CRM , $Outer | Out-File $Path_Store\$R
}
}

Powershell script saving on UTC time

i had implemented powershell script for extract data from sharepoint to CSV file. Currently my file was saving as per my time zone. But i want to save the file with UTC time. means under script i want to convert time format my time to UTC time. Can anyone please correct my script. Below script lines i am using.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web = get-spweb http://testsharepoint/sharepoint/
$caseLib = $web.lists | where {$_.title -eq "Library"}
$query=new-object Microsoft.SharePoint.SPQuery
$query.ViewFields = "<FieldRef Name='LinkFilename'/><FieldRef Name='DocumentSetDescription'/>"
$query.RowLimit=5000
$ListName1 = "Test_"
$ExportFolder1 = “C:\export\”
$ExportName1 = Get-Date -f “yyyyMMdd”
$ExportPath1 = $ExportFolder1 + $ListName1 + $ExportName1 + “.csv”
$ListName = "Data_"
$ExportFolder = “\\servername\Data\”
$ExportName = Get-Date -f “yyyyMMdd”
$ExportPath = $ExportFolder + $ListName + $ExportName + “.csv”
do
{
$caseLibItems=$caseLib.GetItems($query)
$query.ListItemCollectionPosition=$caseLibItems.ListItemCollectionPosition
$listItemsTotal = $caseLibItems.Count
$x = 0
for($x=0;$x -lt $listItemsTotal; $x++)
{
$Description = $caseLibItems[$x]["DocumentSetDescription"]
$str = ""
if('$Description; -ne $null)
$str = $caseLibItems[$x]["LinkFilename"].ToString() + '}' + $Description
}
else
{
$str = $caseLibItems[$x]["LinkFilename"].ToString()
}
Write-Output $str| Out-File $ExportPath1 -Append
}
Quite easy as PowerShell has a .ToUniversalTime() method. Changing the below would be the easiest without changing everything else.
$ExportName = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")
$ExportName1 = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")

Powershell - StreamWriter only write first line

I´m working on a code that is supposed to import-csv - change the content, and then export to csv.
I´ve tried to export with Export-Csv - but it only writes the lenght of the string
I also tried with StreamWriter - but it only writes $Resultat once
I am new to PowerShell :-)
$workfile = import-csv "X:\powershell\converter\test.csv" -Delimiter ';'
ForEach ($item in $workfile)
{
$Id = $item.("ID")
$Maaler = $item.("Maaler")
$Fra = $item.("Fra")
$Til = $item.("Til")
#Dato gymnastik
$Tilto = $item.("Til")
$Tilto = $Tilto.substring(0,10)
$Til = $Til.substring($Til.length - 8, 8)
$Forbrug = $item.("Forbrug")
$Enhed = $item.("Enhed")
$aflaesningstype = $item.("Aflæsningstype?")
$T = ".000+02:00"
$Resultat = $Tilto + "T" + $Til + $T + ',"' + $Maaler + '","' + '","' + '","' + '","' + '","' + $Forbrug + '","' + $Enhed + '","' + '255"'
Write-output "$Resultat"
}
$Resultat | Export-Csv "X:\powershell\behandlet\Output $(get-date -f dd-MM-yyyy-hh-mm-ss).csv" -Delimiter ',' -NoType
#$fhStream = [System.IO.StreamWriter] "X:\powershell\behandlet\Output $(get-date -f dd-MM-yyyy-HH-mm-ss).csv"
#$fhStream.WriteLine($Resultat)
#$fhStream.Close()
The Write-output shows the output in the right way
Can anyone see what I am doing wrong ?
Try this:
$workfile = import-csv "X:\powershell\converter\test.csv" -Delimiter ';'
$result = New-Object System.Collections.ArrayList
ForEach ($item in $workfile)
{
$Id = $item.("ID")
$Maaler = $item.("Maaler")
$Fra = $item.("Fra")
$Til = $item.("Til")
#Dato gymnastik
$Tilto = $item.("Til")
$Tilto = $Tilto.substring(0,10)
$Til = $Til.substring($Til.length - 8, 8)
$Forbrug = $item.("Forbrug")
$Enhed = $item.("Enhed")
$aflaesningstype = $item.("Aflæsningstype?")
$T = ".000+02:00"
$result += $Tilto + "T" + $Til + $T + ',"' + $Maaler + '","' + '","' + '","' + '","' + '","' + $Forbrug + '","' + $Enhed + '","' + '255"'
}
$result | Out-File "X:\powershell\behandlet\Output $(get-date -f dd-MM-yyyy-hh-mm-ss).csv"