How can i connect to ad-hoc network using CMD?

I'm trying to connect my computer (PC1) to an existing ad hoc using cmd commands.This ad hoc was created by second computer(PC2),i spend hours to find results but i did find an answers.See this photo to understand me.

I tried these commands :

Netsh wlan export profile  folder=”c:\profiles” name="Profile 1" interface="Wireless Network Connection"


Netsh wlan add profile filename=C:\Users\WirelessUser\Documents\profile1.xml interface="Wireless Network Connection"

But i can't keep my need.

I need some steps to creating a profile for ad hoc (this ad hoc was created by other machine ),or should i use other methods by using cmd ?


1- create an XML file and copy/past these lines:

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{SSID}</name>
<SSIDConfig>
    <SSID>
        <name>{SSID}</name>
    </SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
    <security>
        <authEncryption>
            <authentication>WPA2PSK</authentication>
            <encryption>AES</encryption>
            <useOneX>false</useOneX>
        </authEncryption>
        <sharedKey>
            <keyType>passPhrase</keyType>
            <protected>false</protected>
            <keyMaterial>{password}</keyMaterial>
        </sharedKey>
    </security>
</MSM>
<MacRandomization 
xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
    <enableRandomization>false</enableRandomization>
</MacRandomization>
</WLANProfile>

2- replace the keywords {SSID} (occurs two times) and {password} with the desired values

3- call that file in cmd (navigate first to its location):

netsh wlan add profile filename="file_name.xml"

4- then execute this command:

netsh wlan connect name="SSID"

NB: the same SSID used in XML file!

and boom, it will connect!

Note:

1- Pay attention to spelling the SSID (uppercase and lowercase letters)

2- SSID = "hotspot name"