PLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum!<\/a><\/p>\n<\/blockquote>\n<\/aside>\nYou deserve a gazillion points for calling out a long term spicehead for not actually giving relevant info and doing the whole “Grandmother, egg, suck” routine <\/p>","upvoteCount":7,"datePublished":"2021-07-13T17:49:22.000Z","url":"https://community.spiceworks.com/t/adding-dhcp-reservations-with-powershell/805410/5","author":{"@type":"Person","name":"Huw3481","url":"https://community.spiceworks.com/u/Huw3481"}},{"@type":"Answer","text":"
From what you posted, it looks like your CSV file might be off?<\/p>\n
if you run this, does everything look ok?<\/p>\n
import-csv \"C:\\YourInputFile.csv\"\n<\/code><\/pre>\nLook at the code example I posted above, and try it like so<\/p>\n
e,g,<\/p>\n
$csv = Import-Csv \"c:\\TempPath\\IPres.csv\" \n\nforeach($row in $csv){\n\n $reservation = @{\n ScopeID = $row.scopeID\n IPAddress = $row.ipaddress\n ClientID = $row.clientID\n Description = $row.description \n }\n\n try{\n Add-DhcpServerv4Reservation @reservation -Verbose -ErrorAction Stop\n }\n catch{\n $Error[0].exception.message\n }\n}\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2021-07-13T17:57:30.000Z","url":"https://community.spiceworks.com/t/adding-dhcp-reservations-with-powershell/805410/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"If I run your first command ( import-csv “C:\\YourInputFile.csv” ) nothing happens.<\/p>\n
I had tried your version and nothing happened either, and tried again with the error coding and nothing is returned.<\/p>","upvoteCount":0,"datePublished":"2021-07-13T18:04:55.000Z","url":"https://community.spiceworks.com/t/adding-dhcp-reservations-with-powershell/805410/7","author":{"@type":"Person","name":"martinpeverley","url":"https://community.spiceworks.com/u/martinpeverley"}},{"@type":"Answer","text":"
Have you tried turning it off and going down the pub instead?<\/p>","upvoteCount":6,"datePublished":"2021-07-13T18:36:16.000Z","url":"https://community.spiceworks.com/t/adding-dhcp-reservations-with-powershell/805410/8","author":{"@type":"Person","name":"r0b","url":"https://community.spiceworks.com/u/r0b"}},{"@type":"Answer","text":"
Hi, Since you have created the .csv file and added the required details.<\/p>\n
You can just run this command to import .csv and create DHCP reservations.<\/p>\n
Example code:<\/p>\n
Import-Csv “Insert path of csv file” | Add-DhcpServerv4Reservation<\/p>\n
The above code will add all the rows listed in your .csv file.<\/p>\n
If you don’t want to see errors, then add -erroraction silentlycontinue at the end of the code<\/p>","upvoteCount":0,"datePublished":"2021-07-14T04:02:26.000Z","url":"https://community.spiceworks.com/t/adding-dhcp-reservations-with-powershell/805410/10","author":{"@type":"Person","name":"philsterz","url":"https://community.spiceworks.com/u/philsterz"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Neally:<\/div>\n
\nDouble check and make sure the CSV is a good correct format.<\/p>\n<\/blockquote>\n<\/aside>\n
Thank you Microsoft for showing me a format like so:<\/p>\n
ScopeId,IPAddress,Name,ClientId,Description 10.10.10.0,10.10.10.10,Computer1,1a-1b-1c-1d-1e-1f,Reserved for Computer1 20.20.20.0,20.20.20.11,Computer2,2a-2b-2c-2d-2e-2f,Reserved for Computer2 30.30.30.0,30.30.30.12,Computer3,3a-3b-3c-3d-3e-3f,Reserved for Computer3\n<\/code><\/pre>\nEven though each entry should be on it’s own line, like this:<\/p>\n
ScopeId,IPAddress,Name,ClientId,Description\n10.10.10.0,10.10.10.10,Computer1,1a-1b-1c-1d-1e-1f,Reserved for Computer1\n20.20.20.0,20.20.20.11,Computer2,2a-2b-2c-2d-2e-2f,Reserved for Computer2\n30.30.30.0,30.30.30.12,Computer3,3a-3b-3c-3d-3e-3f,Reserved for Computer3\n<\/code><\/pre>\nFFS, something so simple.<\/p>\n
Thanks for the help, I was just going about to give up this morning because even the “Import-Csv” wasn’t showing anything, so I checked on that and this jumped out at me \" Each column in the CSV file becomes a property of the custom object and the items in rows become the property values.\"<\/p>\n
Cue the headslap and much rejoicing.<\/p>","upvoteCount":11,"datePublished":"2021-07-14T11:39:54.000Z","url":"https://community.spiceworks.com/t/adding-dhcp-reservations-with-powershell/805410/11","author":{"@type":"Person","name":"martinpeverley","url":"https://community.spiceworks.com/u/martinpeverley"}},{"@type":"Answer","text":"
In the spirit of giving back, or because it pissed me off, I did open a GitHub change request for the documentation being incorrect. Just received notification today that they have fixed it, so “Yay!”<\/p>","upvoteCount":2,"datePublished":"2021-09-13T17:13:40.000Z","url":"https://community.spiceworks.com/t/adding-dhcp-reservations-with-powershell/805410/12","author":{"@type":"Person","name":"martinpeverley","url":"https://community.spiceworks.com/u/martinpeverley"}}]}}
Neally
(Neally)
July 13, 2021, 5:37pm
2
Limey:
but it’s not working
Can you give more info? what you provided is not really helpful.
provide the code you are running [ we can’t read minds ;¬) ]
provide the EXACT format of your CSV file, as that’s important to know for the Powershell code
provide the error or details about what exactly is not working or not working as expected
provide the article you are following so we know what you are talking about
optionally provide OS and powershell version used
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don't say "Need help" or "PowerShell Help", actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…
3 Spice ups