> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/powershell-programming-and-relative-experience/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/powershell-programming-and-relative-experience/chapter2_remote_controlling_by_windows_powershell/23environment-setting.md).

# 2.3.Environment Setting

* Procedure
  * Initialize -> Enable -> During testing
* 1.Initialize:
  * 1.Create a account/ Password for DUT, that's important
    * if you did not create password, you will not be allowed to Enable-PSRemoting.

      ![](/files/-M4M0_6aDXfwJngYECd-)
  * 2.Enable powershell script for Windows

    ```
     %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command  "Set-ExecutionPolicy unrestricted -force"
    ```
  * 3.Setting network environment:
    * Attach Ethernet and Set a Static IP.
    * Turn off firewall or add rule to enable remote control.

      ```
       netsh advfirewall set allprofiles state off
      ```
    * Change connection type to private or work connection, otherwise you will not be allowed to Enable-PSRemoting. ![](/files/-M4M0_6czyytPqGIL9oa)

      ```
           $NLMType = [Type]::GetTypeFromCLSID('DCB00C01-570F-4A9B-8D69-199FDBA5723B')
             $INetworkListManager = [Activator]::CreateInstance($NLMType)
             $NLM_ENUM_NETWORK_CONNECTED  = 3
             $NLM_NETWORK_CATEGORY_PUBLIC = 0x00
             $NLM_NETWORK_CATEGORY_PRIVATE = 0x01
             $UNIDENTIFIED = "Unidentified network"
             $INetworks = $INetworkListManager.GetNetworks($NLM_ENUM_NETWORK_CONNECTED)

              foreach ($INetwork in $INetworks)
              {
                  $Name = $INetwork.GetName()
                  $Category = $INetwork.GetCategory()

                  if (($Category -eq $NLM_NETWORK_CATEGORY_PUBLIC) )
                  {
                      $INetwork.SetCategory($NLM_NETWORK_CATEGORY_PRIVATE)
                  }
              }
      ```
  * 4.Enable Powershell Remote ability :

    ```
      %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "Enable-PSRemoting -Force"
    ```
  * 5.Check details again before remote control :

    ```
        cd wsman::localhost\client 
        Set-Item TrustedHosts *  -force
        Restart-Service WinRm
        cd c:\windows\system32
        Set-PSSessionConfiguration  -Name Microsoft.PowerShell -force
        winrm quickconfig -quiet

        Enable-PSRemoting -Force
        set-executionpolicy unrestricted -force
        set-executionpolicy allsigned -force
        set-executionpolicy remotesigned -force
    ```
  * 6.Set auto login if you need:

    ```
        REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
        REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d %1 /f
        REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d %2 /f
        REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d %3 /f
    ```
  * 7.Enable Powershell Remote ability every time login to desktop if you need:
  * 8.Make sure that the DUT can be login: ![](/files/-M4M0_6epnXvjJdAH0iN)
  * Summary:
    * All we have to do to initialize remote control:
      * 1.Make sure that account/ password were valid
      * 2.Make sure that ethernet was attatched
      * 3.Make sure that IP is valid or not
      * 4.Run scripts
* 2.Enable:
  * Summary:
    * All we have to do to initialize remote control:
      * 1.Make sure that account/ password were valid
      * 2.Make sure that ethernet was attatched
      * 3.Make sure that IP is valid or not
      * 4.Run scripts

        ```
        %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "Enable-PSRemoting -Force"
        ```
* 3.During testing
  * Something need to notice:
    * 1.You must let computer auto login if the computer needs to reboot during testing

      ```
         REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
         REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d %1 /f
         REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d %2 /f
         REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d %3 /f
      ```
    * 2.The computer need to enable remote control every time log in to the desktop
