2

So, the problem is that I must create a 300 ini files. In CSV file I have a computer names and MAC addresses. Ini files must be named as MAC addresses. For that I have solution:

$data = Import-CSV d:\import.csv
ForEach ($i in $data){

$name = $i.name
$MAC = $i.MAC

New-Item -ItemType file -name $_.MAC.ini
}

But in this code I need to put some txt in those inies. For example:

some value
some text
some value=$_.name
and more txt

The content must have the name of computer in some value which is in the same line as MAC address in CSV.

Here I need a help to do it. In first place I tried with Add-Content, but no luck :(

1 Answer 1

2
Import-CSV d:\import.csv | %{ 
    "some value`r`nsome text`r`nsome value=$($_.name)`r`nand more txt" | sc "$($_.MAC).ini" 
}

% is shorthand for Foreach-Object and sc is an alias for Set-Content.

Be sure your MAC addresses use dashes and not colons, since colons are invalid in filenames.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks mate! You are my savior!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.