Powershell script Pssesion

deepak 0 Reputation points
2023-02-13T07:27:50.4966667+00:00
My question is if I m running this script on multiple remote computers, the session will automatically close or I need to close??

and if a New-PSSesion is not closed is there any impact on remote computer?


$computers = Get-Content -Path E:\Newfolder\Input\List_computers.txt

$password = convertTo-SecureString "123456" -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential ("user", $password)

$session = New-PSSession -ComputerName $computers -Credential $cred

$command = {Get-LocalUser| where-Object -Property Enabled -EQ True | Select-Object -Property  Name, Enabled, Description }

$res = Invoke-Command -Session $session -ScriptBlock $command | Export-Csv 






PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,883 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.