A distant session might be arrange with the assistance of PSSession. The predefined distant session is utilized by default. Nonetheless, we will additionally create our personal session configurations after which hook up with this new session, e.g. to execute a startup script when the session is established. Let’s dive in.
State of affairs: Each time a consumer logs in by way of PowerShell Remoting, all logged in customers needs to be displayed
First, we create a brand new file that calls quser. Quser reveals all customers which might be at the moment logged in or have established a distant session. This file and its command shall be executed each time a consumer connects to a distant PowerShell session.
# Create file with quser in it
New-Merchandise -ItemType File -Path $homeusers.ps1 -Worth "quser"
Subsequent, we configure a brand new PoweRshell configuration with the title customers and specify the customers.ps1 file that we created earlier than.
# Register New PSSession Configuration
Register-PSSessionConfiguration -Title Customers -StartupScript $homeusers.ps1
Lastly, we have to restart the WinRM service.
Let’s do the ultimate verify.
Enter-PSSession -ComputerName dc01 -ConfigurationName Customers
Hooray!
Revealed by