Repository navigation
Description
Before submitting a bug report:
- Make sure you are able to repro it on the latest released version
- Perform a quick search for existing issues to check if this bug has already been reported
Steps to reproduce
$scriptContent = Get-Content -Path "C:\temp\myscript_posh_v2.ps1" -Raw
Invoke-Formatter -ScriptDefinition $scriptContent | Set-Content -Path "C:\temp\myscript_posh_v2.ps1"
$error[0] | select *
Expected behavior
Actual behavior
PSMessageDetails :
Exception : System.ArgumentException: Cannot determine line endings as the text probably contain mixed line endings.
Parameter name: text
at Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText.GetNumNewLineCharacters(String text, String[]& lines)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText.GetNewLineCharacters(String text, String[]& lines)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText..ctor(String text)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.Formatter.Format[TCmdlet](String scriptDefinition, Settings settings, Range range, TCmdlet cmdlet)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject :
CategoryInfo : NotSpecified: (:) [Invoke-Formatter], ArgumentException
FullyQualifiedErrorId : System.ArgumentException,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at , : line 2
PipelineIterationInfo : {}
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.26100.1882
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.1882
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.23.0
Activity
andrecrms commentedon Mar 5, 2025
Full script:
$VMs = @("server1", "server2")
$LogFile = "$ (Get-Location)\execution_log.txt"
$Connection = @()
$Jobs = @()
Function to log messages to a file
function Log-Message {
param ([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"$timestamp - $Message" | Out-File -FilePath $LogFile -Append
}
Log script start
Log-Message "Script execution started."
Write-Host "Execution started. Logs will be saved to: $LogFile"
Establish the sessions and execute the SQL command on each server in parallel
foreach ($VM in $VMs) {
Try {
# Attempt to create a session to the remote machine
$Session = New-PSSession -ComputerName $VM -ErrorAction Stop
Write-Host "Successfully connected to $VM"
Log-Message "Successfully connected to $VM"
GO
}
Wait for all jobs to finish
$Jobs | ForEach-Object {
# Wait for the job to complete
Wait-Job -Job $_
}
If there were any connection errors, output them and log
if ($Connection.Count -gt 0) {$($ .ComputerName), Error: $($.ErrorMessage)"$($ .ComputerName), Error: $($.ErrorMessage)"
Write-Host "Connection Issues:"
Log-Message "Connection Issues:"
$Connection | ForEach-Object {
Write-Host "Computer:
Log-Message "Computer:
}
}
Log script completion
Log-Message "Script execution completed."
Write-Host "Execution completed. Log file saved at: $LogFile"