I realize you are asking how to do this programmatically, however, the following should provide enough information to create a PS script to run at startup.
Remote Access Raspberry Pi via Powershell
1.) Run the Windows 10 IoT Core Watcher utility (C:\Program Files (x86)\Microsoft IoT\WindowsIoTCoreWatcher.exe) on your development PC and copy your Raspberry Pi IP address by right-clicking on the detected device and selecting Copy IP Address.
◦Click the windows "Start" button
◦Type "WindowsIoTCoreWatcher" to pull it up in the search results
◦You may want to right click on the program name and select "Pin to Start" to pin it to your start screen for easy access
◦Press Enter to run it
◦Your device should appear in the list within 5 seconds or so. If it does not, close the Windows 10 IoT Core Watcher, and relaunch it again
2.) Launch an administrator PowerShell console on your local PC. The easiest way to do this is to type "powershell" in the Search the web and Windows textbox near the Windows Start Menu. Windows will find PowerShell on your machine. Right-click the Windows PowerShell entry and select Run as administrator. The PS console will show.
3.) You may need to start the WinRM service on your desktop to enable remote connections. From the PS console type the following command:
net start WinRM
4.) From the PS console, type the following command, substituting '' with the IP value copied in prev:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value <machine-name or IP Address>
5.Type Y and press Enter to confirm the change.
6.Now you can start a session with you Windows IoT Core device. From you administrator PS console, type:
Enter-PSSession -ComputerName <IP Address> -Credential localhost\Administrator
7.In the credential dialog enter the following default password:
p@ssw0rd
Note: The connection process is not immediate and can take up to 30 seconds.
If you successfully connected to the device, you should see the IP address of your device before the prompt.
Renaming your Device and Setting the Date and Time
1.To change the computer name, use the setcomputername utility. In PowerShell, type the following command.
setcomputername
2.The date and time on the Pi must be correct for the security tokens used to publish to Azure later in the lab to be valid. To check the current time zone setting on the Pi, type:
tzutil /g
3.If the time zone reported is not correct, you can find a list of valid time zones using (you may need to increase the buffer size on your powershell window):
tzutil /l
4.To set the time zone, locate the id of the time zone you want from the step above, then use:
tzutil /s "Your TimeZone Name"
For example, for "Pacific Standard Time"
tzutil /s "Pacific Standard Time"
5.To check the date on the Raspberry Pi, type
Get-Date
6.If the date or time is incorrect, use the Set-Date utility
Set-Date "mm/dd/yy hh:mm:ss AM/PM"
For Example, if it was 12:15 pm on January 3rd, 2016:
Set-Date "01/03/16 12:15 PM"
7.Reboot the device for the change to take effect. You can use the shutdown command as follows:
shutdown /r /t 0
Set-Date
command. – Chronic