I am attempting to write a script that finds active interface connections and sets any that are set to Public to Private. Here is my very humble first attempt at this idea.
get-wmiobject win32_networkadapter -filter "netconnectionstatus = 2" | select netconnectionid, name InterfaceIndex, netconnectionstatus | ForEach-Object Set-NetConnectionProfile -interfaceindex {$_.InterfaceIndex} -NetworkCategory Private
When I run this command I get a number of errors.
ForEach-Object : Input name "Set-NetConnectionProfile" cannot be resolved to a method. At line:1 char:140 + ... ionstatus | ForEach-Object Set-NetConnectionProfile -interfaceindex { ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (@{netconnection...ectionstatus=2}:PSObject) [ForEach-Object], PSArgumentException + FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand ForEach-Object : Input name "Set-NetConnectionProfile" cannot be resolved to a method. At line:1 char:140 + ... ionstatus | ForEach-Object Set-NetConnectionProfile -interfaceindex { ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (@{netconnection...ectionstatus=2}:PSObject) [ForEach-Object], PSArgumentException + FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand ForEach-Object : Input name "Set-NetConnectionProfile" cannot be resolved to a method. At line:1 char:140 + ... ionstatus | ForEach-Object Set-NetConnectionProfile -interfaceindex { ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (@{netconnection...ectionstatus=2}:PSObject) [ForEach-Object], PSArgumentException + FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand ForEach-Object : Input name "Set-NetConnectionProfile" cannot be resolved to a method. At line:1 char:140 + ... ionstatus | ForEach-Object Set-NetConnectionProfile -interfaceindex { ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (@{netconnection...ectionstatus=2}:PSObject) [ForEach-Object], PSArgumentException + FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand
I tried the usual Google searching and searched this forum for scripts containing to Set-NetConnectionProfile to see if I could get some ideas but I came up empty. I was hoping someone here might be able to provide some guidance.
Thanks!