PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,883 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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