r/PowerShell • • May 06 '26

Question Script for switching network

Hi,

I currently am making a script for ensuring that users are changing from one network to another, through Intune.

Detection: So i first of all use a detection script, that checks the current wifi, and if it is the network, that we are closing soon, then triggers to run the remidiation.

The remidiation consists of using the powershell command:

netsh wlan connect name="PROFILE_NAME"

However, it ofent dont work, because it cant find the network? it only works if the user recentlyhas been in the networks GUI to see what networks are nearby.

I am not sure how to deal with this, and i am hoping you guys got some suggestions.

1 Upvotes

17 comments sorted by

View all comments

Show parent comment

0

u/BlackV May 06 '26

p.s. formatting, you've used code fence (3 back ticks) that only works on new.reddit, 4 spaces indent works on old.reddit and new.reddit

  • open your fav powershell editor
  • highlight the code you want to copy
  • hit tab to indent it all
  • copy it
  • paste here

it'll format it properly OR

<BLANK LINE>
<4 SPACES><CODE LINE>
<4 SPACES><CODE LINE>
    <4 SPACES><4 SPACES><CODE LINE>
<4 SPACES><CODE LINE>
<BLANK LINE>

Inline code block using backticks `Single code line` inside normal text

See here for more detail

Thanks