1

Im trying to run:

netsh lan show interfaces  | findstr /i "GUID" > test.txt
set /p ethguid=<test.txt
echo %ethguid:~23%> test2.txt
set /p ethguidclean=<test2.txt
echo %ethguidclean%
powershell.exe -Command " Rename-Item "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{%ethguidclean%}" -NewName "11111111-1111-1111-1111-111111111111" "
pause

but i fails with error:

Rename-Item : A positional parameter cannot be found that accepts argument '8b384d18-7877-44ea-9b48-5f634a0ff1f6'.
At line:1 char:2
+  Rename-Item HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Rename-Item], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameItemCommand

and if I run command directly in powershell it works! what am I doing wrong?

4
  • 3
    Look at your "s you're not passing a single command string, but a strange sequence of strings. Commented Feb 7, 2023 at 7:47
  • I think you should retrieve the GUID using PowerShell too! netsh.exe is reportedly soon to be removed from future versions of Windows, and is not needed for this task. Example PS command: Get-NetAdapter | Where-Object { ($_.AdminStatus -Eq 'Up' -And $_.MediaConnectState -Eq 1) -And $_.NdisPhysicalMedium -Eq 14 } | Select-Object -ExpandProperty InterfaceGuid. Now as you're already using PowerShell for the registry change, you already have the subkey string you need! Commented Feb 7, 2023 at 11:29
  • 1
    For example instead of using the retrieved GUID, in the registry string, you could use $(Get-NetAdapter | ? { ($_.AdminStatus -Eq 'Up' -And $_.MediaConnectState -Eq 1) -And $_.NdisPhysicalMedium -Eq 14 }).InterfaceGuid directly... Commented Feb 7, 2023 at 11:36
  • will look into these suggestions thanks! Commented Feb 7, 2023 at 12:40

1 Answer 1

1

Change inside double quotes to single:

powershell.exe -Command " Rename-Item 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{%ethguidclean%}' -NewName '11111111-1111-1111-1111-111111111111' "
Sign up to request clarification or add additional context in comments.

Comments

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.