Curly brackets in variables


hi guys, here' problem:

get-dhcpserverv4optionvalue -scopeid 172.19.1.0 -all -optionid 132 | set-dhcpserverv4optionvalue -scopeid 172.19.2.0 -value {0x35, 0x35, 0x32}

work fine powershell prompt.

import-csv .\nodi.csv -delimiter ";" | foreach {
    if ($_.value -ne "-") {
        get-dhcpserverv4optionvalue -scopeid 172.19.1.0 -all -optionid 132 | set-dhcpserverv4optionvalue -scopeid $_.scopeid -value $_.value
        }
}

doesn't work: 

set-dhcpserverv4optionvalue : parameters option value set option id 132 not match option definition on dhcp server saga.
@ c:\dhcpscripts\set-scopeoption43.ps1:6 char:78
+         get-dhcpserverv4optionvalue -scopeid 172.19.1.0 -all -optionid 132 | set ...
+                                                                              ~~~
    + categoryinfo          : invalidargument: (132:root/microsoft/...erv4optionvalue) [set-dhcpserverv4optionvalue], cimexception
    + fullyqualifiederrorid : win32 87,set-dhcpserverv4optionvalue

csv contents:

scopeid,value

172.19.2.0,{0x35, 0x35, 0x32}

172.19.3.0,{0x35, 0x35, 0x33}

172.19.4.0,{0x35, 0x35, 0x34}

if change, in script, $_.value with, example, {0x35, 0x35, 0x32} works. problem passing value csv file. when inserting write-host $_.value in script, display values correctly curly brackets.

any suggestion?


dario palermo

hmm, okay.  there's 1 other possibility here.  if -value parameter accepts pipeline input, , pass scriptblock literal, instead of converting script block string, instead it's executing script block , passing on result.  in case, you'd wind passing string array containing "53", "53", "52"  (the decimal representations of 0x35, 0x35, 0x34), etc.

to know sure what's happening, try running these commands , let me know ones work:

get-dhcpserverv4optionvalue -scopeid 172.19.1.0 -all -optionid 132 | set-dhcpserverv4optionvalue -scopeid 172.19.2.0 -value "0x35, 0x35, 0x32"  get-dhcpserverv4optionvalue -scopeid 172.19.1.0 -all -optionid 132 | set-dhcpserverv4optionvalue -scopeid 172.19.2.0 -value "0x35", "0x35", "0x32"  get-dhcpserverv4optionvalue -scopeid 172.19.1.0 -all -optionid 132 | set-dhcpserverv4optionvalue -scopeid 172.19.2.0 -value "53", "53", "50"  

i assume last 1 work, middle 1 may well. here's modification of code should work:

import-csv .\nodi.csv -delimiter ";" | foreach {     if ($_.value -ne "-") {         $value = $_.value -replace '^\s*{\s*|\s*}\s*$' -split '\s*,\s*'         get-dhcpserverv4optionvalue -scopeid 172.19.1.0 -all -optionid 132 |        set-dhcpserverv4optionvalue -scopeid $_.scopeid -value $value     } } 



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607