An empty pipe element is not allowed

Glenn Maxwell 10,146 Reputation points
2024-04-01T06:51:47.3433333+00:00

Hi All, can anyone help me correct the syntax. i am unable to export the output to a text file

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
    Write-Host "Installing NuGet provider..."
    Install-PackageProvider -Name NuGet -Force
}
else {
    Write-Host "NuGet provider is already installed."
}
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
    Write-Host "Installing PSWindowsUpdate module..."
    Install-Module PSWindowsUpdate -Force
}
else {
    Write-Host "PSWindowsUpdate module is already installed."
}
Import-Module PSWindowsUpdate
Write-Host "Checking for available Windows Updates..."
Get-WindowsUpdate
Write-Host "Installing available Windows Updates..."
Install-WindowsUpdate -AcceptAll -AutoReboot:$false | Out-File -FilePath "C:\output.txt"
At line:29 char:1
+ | Out-File -FilePath "C:\output.txt"
+ ~
An empty pipe element is not allowed.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : EmptyPipeElement


Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,491 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,395 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,396 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,132 questions
{count} votes

Accepted answer
  1. MotoX80 32,086 Reputation points
    2024-04-02T16:48:14.7866667+00:00

    I didn't have any problem with the brackets on Win10/PS5.1, but -AutoReboot:$false did not work. I get a prompt.

    User's image

    -IgnoreReboot appears to work. I need to verify on another VM.

    User's image

    After a reboot, when I rerun the script I get this.

    User's image

    Here is the script that I used. Updated on 4/3..

    $LogFolder = "C:\Temp"                                # Where to put log files 
    $ts = $LogFolder + "\PatchInstallTranscript.log"
    $op = $LogFolder + "\PatchInstallOutput.log"
    
    Start-Transcript -Path $ts
    
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
        Write-Host "NOT Installing NuGet provider..."
        Install-PackageProvider -Name NuGet -Force -confirm:$false
    }
    else {
        Write-Host "NuGet provider is already installed."
    }
    if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
        Write-Host "Installing PSWindowsUpdate module..."
        Install-Module PSWindowsUpdate -Force -confirm:$false
    }
    else {
        Write-Host "PSWindowsUpdate module is already installed."
    }
    Import-Module PSWindowsUpdate
    Write-Host "Checking for available Windows Updates..."
    Get-WindowsUpdate -verbose -IgnoreReboot
    Write-Host "Installing available Windows Updates..."
    $Update = Install-WindowsUpdate -AcceptAll -IgnoreReboot -verbose
    if (!$Update) {
       $Update = "Install-WindowsUpdate did not return any data."
    }
                                                
    $Update | format-table -wrap | Out-File -FilePath $op 
    get-content $op                     # record in transcript   
    Stop-Transcript
    
    

    I would recommend that you do a reboot in case you have updates installed and waiting to to be implemented and/or other powershell.exe processes waiting for someone to type in y/n.


8 additional answers

Sort by: Most helpful
  1. Glenn Maxwell 10,146 Reputation points
    2024-04-01T11:36:50.27+00:00

    tried that as well but same error.

    • | Out-File -FilePath "C:\output.txt"
    • ~

    An empty pipe element is not allowed.

    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    
    + FullyQualifiedErrorId : EmptyPipeElement
    
    0 comments No comments

  2. Glenn Maxwell 10,146 Reputation points
    2024-04-01T11:39:35.7+00:00

    When i use the below syntax i am getting output as empty i should get the below output.

    NuGet provider is already installed.

    PSWindowsUpdate module is already installed.

    Checking for available Windows Updates...

    Installing available Windows Updates...

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
        Write-Host "Installing NuGet provider..."
        Install-PackageProvider -Name NuGet -Force
    }
    else {
        Write-Host "NuGet provider is already installed."
    }
    if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
        Write-Host "Installing PSWindowsUpdate module..."
        Install-Module PSWindowsUpdate -Force
    }
    else {
        Write-Host "PSWindowsUpdate module is already installed."
    }
    Import-Module PSWindowsUpdate
    Write-Host "Checking for available Windows Updates..."
    Get-WindowsUpdate
    Write-Host "Installing available Windows Updates..."
    Install-WindowsUpdate -AcceptAll -AutoReboot:$false | Out-File -FilePath "C:\output.txt"
    
    
    0 comments No comments

  3. MotoX80 32,086 Reputation points
    2024-04-01T14:24:04.34+00:00

    Don't use a pipe. Assign the output to a variable and then examine the variable.

    I would also suggest writing to some folder other than the root of C:.

    Add the "-verbose" switch to the install cmdlet and see if that produces any additional info.

    $x = Install-WindowsUpdate -AcceptAll -AutoReboot:$false -verbose
    "Here is the type."
    $x.gettype()
    "Here is the x variable."
    $x
    $x | Out-File -FilePath "C:\windows\temp\output.txt"
    

    Add a transcript if the verbose output is not captured.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

    0 comments No comments

  4. Glenn Maxwell 10,146 Reputation points
    2024-04-01T19:29:28.11+00:00

    i am getting this error

    You cannot call a method on a null-valued expression.