Home > Software engineering >  get content - Powershell
get content - Powershell

Time:01-13

i wanna change mtu with powershell script and the value in this txt file

  • when i get content it gives me this error
  • Invalid mtu parameter (1492 ). enter image description here
  • what's wrong in this code ?
$GMTU = Get-Content C:\MTU2.txt
$AdapterName = $(Get-NetAdapter | Where { $_.Name -Match 'Ethernet'}).Name
netsh interface ipv4 set subinterface "$AdapterName" mtu=$GMTU store=persistent

CodePudding user response:

It looks like there's a trailing space after the last digit. You can use string.Trim() to remove leading or trailing whitespace:

$GMTU = (Get-Content C:\MTU2.txt -TotalCount 1).Trim()
  •  Tags:  
  • Related