header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
Out-File Error
Last Post 06 Mar 2012 02:22 PM by EBGreen. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Kevin BrownUser is Offline
New Member
New Member
Posts:7
Avatar

--
06 Mar 2012 05:03 AM
    Code format of the out-file cmdlet is the same in both instances but fails with an error in one instance and works flawlessly in the other.

    This code checks the version of IE and based on that info, the tool is either installed or not. In this case, the tool is not being installed but the out-file cmdlet fails with what appears to be an Encoding error.

    $reg = Get-Item ('HKLM:\Software\Microsoft\Internet Explorer\Version Vector'); $reg.GetValue("IE") | Out-Null

    if ([string]$reg -lt 8.000) {
        IEDevToolBar
    } else {
        Write-Host -ForegroundColor Red 'IE Version is 8.0 or greater, IEDevToolBar Is No Longer Compatible!'
        $Date = Get-Date
        maruja$1
     Out-File -FilePath $LOGS'\DSKTOPTOOL.LOG' -InputObject 'IEDevToolBar Not Compatible--'$Date -Append -NoClobber
    }   


    Out-File : Cannot validate argument on parameter 'Encoding'. The argument "03/06/2012 08:
    47:14" does not belong to the set "unicode,utf7,utf8,utf32,ascii,bigendianunicode,default
    ,oem" specified by the ValidateSet attribute. Supply an argument that is in the set and t
    hen try the command again.
    At S:\DEVCNTR\PSOLibrary\IBM_DESKTOP\DevDskTop_pkgs\PowerShell_Scripts\DevDskTopTools_Bui
    ld.ps1:106 char:14
    +            Out-File <<<<  -FilePath $LOGS'\DSKTOPTOOL.LOG' -InputObject 'IEDevToolBar N
    ot Compatible--'$Date -Append -NoClobber
        + CategoryInfo          : InvalidData: (:) [Out-File], ParameterBindingValidationExc
       eption
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Comm
       ands.OutFileCommand




    This works in the function it resides in without an Encoding error:

    $Date = Get-Date
    Out-File -FilePath $LOGS'\DSKTOPTOOL.LOG' -InputObject $TL_NM'--'$Date -Append -NoClobber

    EBGreenUser is Offline
    Veteran Member
    Veteran Member
    Posts:1276
    Avatar

    --
    06 Mar 2012 05:44 AM
    Try it this way. I suspect it is getting confused over parameters/values:

    "IEDevToolBar Not Compatible--$Date" | Out-File "$LOGS\DSKTOPTOOL.LOG" -Append -NoClobber
    "Look Ma...no strings!"
    Kevin BrownUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    06 Mar 2012 06:19 AM
    That worked but it's still weird that others worked with the arrangement in the original order.
    EBGreenUser is Offline
    Veteran Member
    Veteran Member
    Posts:1276
    Avatar

    --
    06 Mar 2012 02:22 PM
    So to be honest I would not expect either to work. String concatenation in powershell is most commonly done either implicitly using Double Quotes:

    "IEDevToolBar Not Compatible--$Date"

    Or explicitly with the + operator:

    'IEDevToolBar Not Compatible--' + $Date
    "Look Ma...no strings!"
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer