Disable-PSRemoting

Mencegah titik akhir PowerShell menerima koneksi jarak jauh.

Sintaks

Disable-PSRemoting
       [-Force]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]

Deskripsi

Disable-PSRemoting Cmdlet memblokir akses jarak jauh ke semua konfigurasi titik akhir sesi Windows PowerShell di komputer lokal. Ini termasuk titik akhir apa pun yang dibuat oleh PowerShell 6 atau yang lebih tinggi.

Untuk mengaktifkan kembali akses jarak jauh ke semua konfigurasi sesi, gunakan Enable-PSRemoting cmdlet . Ini termasuk titik akhir apa pun yang dibuat oleh PowerShell 6 atau yang lebih tinggi. Untuk mengaktifkan akses jarak jauh ke konfigurasi sesi yang dipilih, gunakan parameter AccessMode cmdlet Set-PSSessionConfiguration . Anda juga dapat menggunakan Enable-PSSessionConfiguration cmdlet dan Disable-PSSessionConfiguration untuk mengaktifkan dan menonaktifkan konfigurasi sesi untuk semua pengguna. Untuk informasi selengkapnya tentang konfigurasi sesi, lihat about_Session_Configurations.

Catatan

Bahkan setelah berjalan Disable-PSRemoting , Anda masih dapat membuat koneksi loopback pada komputer lokal. Koneksi loopback adalah sesi jarak jauh PowerShell yang berasal dari dan terhubung ke komputer lokal yang sama. Sesi jarak jauh dari sumber eksternal tetap diblokir. Untuk koneksi loopback, Anda harus menggunakan kredensial implisit di sepanjang parameter EnableNetworkAccess . Untuk informasi selengkapnya tentang koneksi loopback, lihat New-PSSession.

Untuk menjalankan cmdlet ini, mulai Windows PowerShell dengan opsi Jalankan sebagai administrator .

Contoh

Contoh 1: Mencegah akses jarak jauh ke semua konfigurasi sesi

Contoh ini mencegah akses jarak jauh ke semua konfigurasi titik akhir sesi PowerShell di komputer.

Disable-PSRemoting

WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
 or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these
 steps:
    1. Stop and disable the WinRM service.
    2. Delete the listener that accepts requests on any IP address.
    3. Disable the firewall exceptions for WS-Management communications.
    4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
       members of the Administrators group on the computer.

Contoh 2: Mencegah akses jarak jauh ke semua konfigurasi sesi tanpa permintaan konfirmasi

Contoh ini mencegah akses jarak jauh semua konfigurasi titik akhir sesi PowerShell di komputer tanpa meminta.

Disable-PSRemoting -Force

WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
 or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these
 steps:
    1. Stop and disable the WinRM service.
    2. Delete the listener that accepts requests on any IP address.
    3. Disable the firewall exceptions for WS-Management communications.
    4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
       members of the Administrators group on the computer.

Contoh 3: Efek menjalankan cmdlet ini

Contoh ini menunjukkan efek penggunaan Disable-PSRemoting cmdlet. Untuk menjalankan urutan perintah ini, mulai PowerShell dengan opsi Jalankan sebagai administrator .

Setelah menonaktifkan konfigurasi sesi, New-PSSession cmdlet mencoba membuat sesi jarak jauh ke komputer lokal (juga dikenal sebagai "loopback"). Karena akses jarak jauh dinonaktifkan pada komputer lokal, perintah gagal.

Disable-PSRemoting -Force
New-PSSession -ComputerName localhost

WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
 or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
    1. Stop and disable the WinRM service.
    2. Delete the listener that accepts requests on any IP address.
    3. Disable the firewall exceptions for WS-Management communications.
    4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
       members of the Administrators group on the computer.

New-PSSession : [localhost] Connecting to remote server localhost failed with the following error
 message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ New-PSSession -ComputerName localhost -ConfigurationName PowerShell.6
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OpenError: (System.Management.A\u2026tion.RemoteRunspace:RemoteRunspace)
 [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed

Contoh 4: Efek menjalankan cmdlet ini dan Enable-PSRemoting

Contoh ini menunjukkan efek pada konfigurasi sesi menggunakan Disable-PSRemoting cmdlet dan Enable-PSRemoting .

Disable-PSRemoting digunakan untuk menonaktifkan akses jarak jauh ke semua konfigurasi titik akhir sesi PowerShell. Parameter Paksa menekan semua permintaan pengguna. Get-PSSessionConfiguration cmdlet dan Format-Table menampilkan konfigurasi sesi di komputer.

Output menunjukkan bahwa semua pengguna jarak jauh dengan token jaringan ditolak akses ke konfigurasi titik akhir. Grup administrator di komputer lokal diizinkan mengakses konfigurasi titik akhir selama mereka terhubung secara lokal (juga dikenal sebagai loopback) dan menggunakan kredensial implisit.

Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize

Enable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize

Name                          Permission
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell32        NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
WithProfile                   NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed

Name                          Permission
----                          ----------
microsoft.powershell          BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow BUILTIN\Administrators AccessAllowed
microsoft.powershell32        BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       BUILTIN\Administrators AccessAllowed
WithProfile                   BUILTIN\Administrators AccessAllowed

Enable-PSRemoting Cmdlet mengaktifkan kembali akses jarak jauh ke semua konfigurasi titik akhir sesi PowerShell di komputer. Parameter Paksa menekan semua permintaan pengguna dan memulai ulang layanan WinRM tanpa meminta. Output baru menunjukkan bahwa deskriptor keamanan AccessDenied telah dihapus dari semua konfigurasi sesi.

Contoh 5: Koneksi loopback dengan konfigurasi titik akhir sesi yang dinonaktifkan

Contoh ini menunjukkan bagaimana konfigurasi titik akhir dinonaktifkan, dan menunjukkan cara membuat koneksi loopback yang berhasil ke titik akhir yang dinonaktifkan. Disable-PSRemoting menonaktifkan semua konfigurasi titik akhir sesi PowerShell.

Disable-PSRemoting -Force
New-PSSession -ComputerName localhost

WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
 or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
    1. Stop and disable the WinRM service.
    2. Delete the listener that accepts requests on any IP address.
    3. Disable the firewall exceptions for WS-Management communications.
    4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
       members of the Administrators group on the computer.

New-PSSession : [localhost] Connecting to remote server localhost failed with the following error message : Access is
denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ New-PSSession -ComputerName localhost
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
   gTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed

New-PSSession -ComputerName localhost -EnableNetworkAccess

Id Name       Transport ComputerName  ComputerType   State   ConfigurationName   Availability
 -- ----       --------- ------------  ------------   -----   -----------------   ------------
 1  Runspace1  WSMan     localhost     RemoteMachine  Opened  powershell.6           Available

Penggunaan New-PSSession pertama upaya untuk membuat sesi jarak jauh ke komputer lokal. Jenis koneksi ini melewati tumpukan jaringan dan bukan loopback. Akibatnya, upaya koneksi ke titik akhir yang dinonaktifkan gagal dengan kesalahan Akses ditolak .

Penggunaan New-PSSession kedua juga mencoba membuat sesi jarak jauh ke komputer lokal. Dalam hal ini, berhasil karena merupakan koneksi loopback yang melewati tumpukan jaringan.

Koneksi loopback dibuat saat kondisi berikut terpenuhi:

  • Nama komputer yang akan disambungkan adalah 'localhost'.
  • Tidak ada kredensial yang diteruskan. Pengguna yang masuk saat ini (kredensial implisit) digunakan untuk koneksi.
  • Parameter switch EnableNetworkAccess digunakan.

Untuk informasi selengkapnya tentang koneksi loopback, lihat dokumen New-PSSession .

Contoh 6: Mencegah akses jarak jauh ke konfigurasi sesi yang memiliki deskriptor keamanan kustom

Contoh ini menunjukkan bahwa Disable-PSRemoting cmdlet menonaktifkan akses jarak jauh ke semua konfigurasi sesi yang menyertakan konfigurasi sesi dengan deskriptor keamanan kustom.

Register-PSSessionConfigurationmembuat konfigurasi sesi Uji. Parameter FilePath menentukan file konfigurasi sesi yang menyesuaikan sesi. Parameter ShowSecurityDescriptorUI menampilkan kotak dialog yang mengatur izin untuk konfigurasi sesi. Dalam kotak dialog Izin, kami membuat izin akses penuh kustom untuk pengguna yang ditunjukkan.

Get-PSSessionConfiguration cmdlet dan Format-Table menampilkan konfigurasi sesi dan propertinya. Output menunjukkan bahwa konfigurasi sesi Uji memungkinkan akses interaktif dan izin khusus untuk pengguna yang ditunjukkan.

Disable-PSRemoting menonaktifkan akses jarak jauh ke semua konfigurasi sesi.

Register-PSSessionConfiguration -Name Test -FilePath .\TestEndpoint.pssc -ShowSecurityDescriptorUI -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Wrap

Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Wrap
New-PSSession -ComputerName localhost -ConfigurationName Test

Name                          Permission
----                          ----------
microsoft.powershell          BUILTIN\Administrators AccessAllowed
Test                          NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed,
DOMAIN01\User01 AccessAllowed

WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
 or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
    1. Stop and disable the WinRM service.
    2. Delete the listener that accepts requests on any IP address.
    3. Disable the firewall exceptions for WS-Management communications.
    4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
       members of the Administrators group on the computer.

Name                          Permission
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
Test                          NT AUTHORITY\NETWORK AccessDenied, NTAUTHORITY\INTERACTIVE AccessAllowed,
BUILTIN\Administrators AccessAllowed, DOMAIN01\User01 AccessAllowed


[Server01] Connecting to remote server failed with the following error message : Access is denied. For more information, see the about_Rem
ote_Troubleshooting Help topic.
+ CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed

Get-PSSessionConfiguration Sekarang cmdlet dan Format-Table menunjukkan bahwa deskriptor keamanan AccessDenied untuk semua pengguna jaringan ditambahkan ke semua konfigurasi sesi, termasuk konfigurasi sesi Uji. Meskipun deskriptor keamanan lainnya tidak diubah, deskriptor keamanan "network_deny_all" lebih diutamakan. Ini diilustrasikan oleh upaya untuk menggunakan New-PSSession untuk menyambungkan ke konfigurasi sesi Uji .

Contoh 7: Mengaktifkan kembali akses jarak jauh ke konfigurasi sesi yang dipilih

Contoh ini menunjukkan cara mengaktifkan kembali akses jarak jauh hanya ke konfigurasi sesi yang dipilih. Setelah menonaktifkan semua konfigurasi sesi, kami mengaktifkan kembali sesi tertentu.

Set-PSSessionConfiguration Cmdlet digunakan untuk mengubah microsoft. Konfigurasi sesi ServerManager. Parameter AccessMode dengan nilai Remote mengaktifkan kembali akses jarak jauh ke konfigurasi.

Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize

Set-PSSessionConfiguration -Name Microsoft.ServerManager -AccessMode Remote -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize

WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
 or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
    1. Stop and disable the WinRM service.
    2. Delete the listener that accepts requests on any IP address.
    3. Disable the firewall exceptions for WS-Management communications.
    4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
       members of the Administrators group on the computer.

Name                          Permission
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell32        NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
WithProfile                   NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed

Name                          Permission
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell32        NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       BUILTIN\Administrators AccessAllowed
WithProfile                   NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed

Parameter

-Confirm

Meminta Anda mengonfirmasi sebelum menjalankan cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

Memaksa perintah untuk dijalankan tanpa meminta konfirmasi pengguna.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Menunjukkan apa yang akan terjadi jika cmdlet berjalan. Cmdlet tidak dijalankan.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Input

None

Anda tidak dapat menyalurkan objek ke cmdlet ini.

Output

None

Cmdlet ini tidak mengembalikan output.

Catatan

  • Menonaktifkan konfigurasi sesi tidak membatalkan semua perubahan yang dibuat oleh Enable-PSRemoting cmdlet atau Enable-PSSessionConfiguration . Anda mungkin harus mengurungkan perubahan berikut secara manual.

    1. Hentikan dan nonaktifkan layanan WinRM.
    2. Hapus pendengar yang menerima permintaan di alamat IP apa pun.
    3. Nonaktifkan pengecualian firewall untuk komunikasi WS-Management.
    4. Pulihkan nilai LocalAccountTokenFilterPolicy ke 0, yang membatasi akses jarak jauh ke anggota grup Administrator di komputer.

    Konfigurasi sesi adalah sekelompok pengaturan yang menentukan lingkungan untuk sesi. Setiap sesi yang tersambung ke komputer harus menggunakan salah satu konfigurasi sesi yang terdaftar di komputer. Dengan menolak akses jarak jauh ke semua konfigurasi sesi, Anda secara efektif mencegah pengguna jarak jauh membuat sesi yang terhubung ke komputer.

    Di Windows PowerShell 2.0, Disable-PSRemoting menambahkan entri Deny_All ke deskriptor keamanan semua konfigurasi sesi. Pengaturan ini mencegah semua pengguna membuat sesi yang dikelola pengguna ke komputer lokal. Di Windows PowerShell 3.0, Disable-PSRemoting tambahkan entri Network_Deny_All ke deskriptor keamanan semua konfigurasi sesi. Pengaturan ini mencegah pengguna di komputer lain membuat sesi yang dikelola pengguna di komputer lokal, tetapi memungkinkan pengguna komputer lokal membuat sesi loopback yang dikelola pengguna.

    Di Windows PowerShell 2.0, Disable-PSRemoting setara dengan Disable-PSSessionConfiguration -Name *. Di Windows PowerShell 3.0 dan rilis yang lebih baru, Disable-PSRemoting setara dengan Set-PSSessionConfiguration -Name \<Configuration name\> -AccessMode Local