如何在 PowerShell 中使用 Set-NetConnectionProfile 更改 NetConnectionProfile 的名称

Kis*_*han 5 powershell powershell-ise powershell-2.0 powershell-3.0

我尝试使用如何使用 Set-NetConnectionProfile 更改 NetConnectionProfile 的名称

$Profile=Get-NetConnectionProfile -InterfaceIndex 35
$Profile.Name = "Network1"            
Run Code Online (Sandbox Code Playgroud)

错误是

"Name" is a ReadOnly property.
 At line:1 char:1
+ $Profile.Name = "Network1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) []
+ FullyQualifiedErrorId : ReadOnlyCIMProperty
Run Code Online (Sandbox Code Playgroud)

如何更改名称的只读属性??帮我

小智 6

您可以通过直接注册表版本来执行此操作。

在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles 项下

您可以看到网络配置文件密钥(通过它的 uuid),并且可以更改适当的网络 ProfileName 值。

  • `Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\"` ➜ `$UUID = "{01234ABC-...}"` ➜ `$VALUE = "Network1"` ➜ `(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\$UUID").ProfileName` ➜ `Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion \NetworkList\Profiles\$UUID" -名称 ProfileName -值 $VALUE` (2认同)

小智 1

当您读取这些名称时,Name 属性是只读的。

$Profile=Get-NetConnectionProfile -InterfaceIndex 35
Run Code Online (Sandbox Code Playgroud)

您正在尝试获取特定的配置文件索引名称。然后将其声明为“Network1”

了解如何按属性名称使用 PowerShell 值绑定

http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/25/learn-about-using-powershell-value-binding-by-property-name.aspx

了解和使用 PowerShell 配置文件

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/04/understanding-and-using-powershell-profiles.aspx