Get-ChildItem BaseName returing @{} in value

A folder contains a number of encrypted files named like...SB_SeminoleCounty_Dispatch_1.bak.gpg.  I need the base file name without the.gpg extension.
If I execute the this command in powershell I get the expected value
PS L:\SQLServerBackupFile> gci .\SB_SeminoleCounty_Dispatch_1.bak.gpg  | select basename
BaseName
SB_SeminoleCounty_Dispatch_1.bak
I am trying to retrieve the same information in my script
..some code..
$fileDirectory  = 'L:\SQLServerBackupFile'
foreach($file in Get-ChildItem $fileDirectory | where {! $_.PSIsContainer} | Sort-Object name -unique )
$DecryptedFileName = Get-ChildItem $fileDirectory\$file | select {$_.BaseName}
Write-Host "Base file name: " $DecryptedFileName
The output is:
Base file name:  @{$_.basename=SB_SeminoleCounty_Dispatch_1.bak}
How can I get just the value of the file name ..SB_SeminoleCounty_Dispatch_1.bak without @{$_.basename=..}?
Of course, I am sure there is a better alternative so any suggestions are appreciated.
Thanks

This works.  I was not sure if you intended for me to modify my original statement  foreach($file in Get-ChildItem $fileDirectory..
I was trying to retrieve information with my original code and might be able to replace my foreach with your logic.  I did not want to try too many things until I fixed my original question.  But your construct is very helpful.
I added your suggestion into the current foreach and it works. 
I will comment on the other two posts.  Their suggestion worked with a slight modification
$DecryptedFileName = $file.BaseName
I like this command because it is one line.  I actually tried calling $file.FullName oreviously, but it did not work.  I must have had something else wrong.  I am just learning powershell.
Thanks for your feedback.

Similar Messages

  • Get-ChildItem Issue With Variable

    I hope some very clever person out there can resolve this without even thinking, however my brain seems to be blocked.
    $FileVersion
    = (Get-ChildItem
    C:\Windows\System32\drivers\somedriver.SYS).VersionInfo
    |
    Select-Object
    FileVersion
    If ($FileVersion
    -eq
    "2, 0, 0, 1") {Copy-Item
    -Force
    "C:\local\somedriver.SYS","C:\Windows\System32\drivers\somedriver.SYS"} 
    I have verified this and $FileVersion does in fact equal 2, 0, 0, 1 however starts as a formatted table.
    FileVersion
    2, 0, 0, 1
    I think it must be passing the variable as the whole table, I also tried adding in my if statement the value @{FileVersion=2, 0, 0, 1 however that also failed.
    Any ideas what I'm missing here?
    Many Thanks

    If the strings are not in the same format then the files are not the same.  Simple logic.  IF they are in the same format and compare exactly then the strings are identical.  Who cares what is in them?
    Comparing to equal will always work.  If they do not compare as equal you know the files are different.
    That is all. That is all I said.  No need to make more of it.
    ¯\_(ツ)_/¯
    You never answered how you're getting this string. Again, as I've said in more than one post now, if you're using .VersionInfo.FileVersion, that string is not accurate for a significant number of files (especially Microsoft files).
    You are correct when you say that if the strings don't match they're not the same. But you're forgetting that the strings may be the same and yet the file isn't the same. To me, that's a big deal. If you're cataloging file versions, your information could
    be incorrect.
    Here's a scenario:
    1. I check the 'mshtml.dll' VersionInfo.FileVersion today. It reports back that it is '11.00.9600.16410 (winblue_gdr.130923-1706)'.
    It is actually at version '11.0.9600.16476' (which can be confirmed by using Explorer or by combining the File*Part
    properties as in previous posts).
    2. An Internet Explorer patch comes along that updates the file to '11.0.9600.16482' (something higher than 16476)
    3. I check the version of the file again using the VersionInfo.FileVersion property. It reports back '11.00.9600.16410
    (winblue_gdr.130923-1706)', which is the same thing it showed before the patch. The file is obviously different, but the FileVersion property is reporting that it hasn't changed.
    So, if you're using that property, you will miss file changes on a significant number of files. 'mshtml.dll' is just one example. Go back and read my example to get a list of DLLs
    from system32 that are affected by this (remember, you will get some false positives).
    If you're combining the File*Part properties (which is what both Bill and I do), then the version will always be in a known format, and then all of the stuff you said about not being
    able to compare them is simply not correct.
    So, how are you proposing that someone gets a file's version from PowerShell?

  • Get-Childitem with Get-FileHash Info

    Hello,
    I have been able run the following script to get File names in a Recurse folders, although I'm looking to use Get-Filehast too, although I'm not sure or unable to tag this on the end of this script File-filehast info.  could you advise.
    my current Get-Childitem script
    get-childitem'\\folder1\folder2\folder3'-recurse|
    Add-Member
    -MemberTypeScriptProperty-NameVersion-Value{
    $this
    .VersionInfo.ProductVersion
    -PassThru|
    select-object
    DirectoryName,Name,Version,LastWriteTime,Length|where{
    $_.DirectoryName
    -ne$NULL}

    Hi I'm outputting to a text file, which I'm then importing into a database, although I have the following objects
    of which I looking to get also hash (Algorithm SHA256) file values as well.  Thanks
    ( DirectoryName,Name,Version,LastWriteTime,Length
    my code is this & screen print from PowerShell
    get-childitem'\\ServerShare\Folder1\Folder2\FolderData'-recurse|
    Add-Member
    -MemberTypeScriptProperty-NameVersion-Value{
    $this
    .VersionInfo.ProductVersion
    -PassThru|
    select-object
    DirectoryName,Name,Version,LastWriteTime,Length|where{
    $_.DirectoryName
    -ne$NULL}
    |Export-Csv-PathC:\folder0\data1.txt
     

  • Get-ChildItem on version 2.0 vs 3.0

    Not sure if this has been discussed or is known, but I found an interesting issue when running Get-ChildItem on version 2.0 vs 3.0
    So I have the simple command of
    $files = Get-ChildItem -Path $Source -Recurse -ErrorAction SilentlyContinue -ErrorVariable myError
    If $Source only contains 1 file, then $files is of type System.IO.FileInfo, whereas, if there are more than one, it would be of type Syste.Array. I actually thought $files would always be a collection, no mater if there was one or multiple files, but obviously
    I was wrong.
    So with thinking it will always be a collection, I used $files.Count for my Write-Progress
    Write-Progress -Activity "Backing up Files" -Status "File: $src-->$dest" -PercentComplete ($counter / $files.Count*100)
    Everything on my machine worked and I am running version 3.0, so I put the script on a machine that was running 2.0 and the Write-Progress failed with cannot divide by zero..hmmmmm
    So doing a little testing, I ran the Get-ChildItem command on version 2.0 and then did $files.Count which returned nothing due to $files being System.IO.FileInfo, and it doesn't have a property of Count, but if you run it on version 3.0 and then do $files.Count,
    even though $files doesn't have a Count property when it is of type Syste.IO.FileInfo or System.IO.DirectoryInfo, it will return 1
    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
    Don't Retire Technet

    In PowerShell 3.0 or later, you can check a .Count property on any value (even $null.Count); it was added along with the Member Enumeration feature.  This works for .Length as well.  If no property / field named Count or Length exists on the object,
    PowerShell will enumerate it for you and return the number of objects
    When you're needing to support PowerShell 2.0, you need to be more careful.
    On a side note, use the syntax in Boe's last post, with the @() operator around the command that you ran.  There's a subtle difference between these two:
    $files = @(dir DoesNotExist.txt -ErrorAction SilentlyContinue)
    $temp = dir DoesNotExist.txt -ErrorAction SilentlyContinue
    $files2 = @($temp)
    $files.Count # 0
    $files2.Count # In PowerShell 2.0, this will be 1. In 3.0 or later, it's 0.
    This is because there are technically two different kinds of Null values that the PowerShell engine recognizes:  actual null references, and a value called AutomationNull, which is used to represent a command which didn't output anything.  In PowerShell
    2.0, when you assign the result of a command to a variable, it didn't keep track of whether the result was AutomationNull or not, resulting in this weird behavior.  3.0 and later correct this.
    Here are a couple of other demonstrations of this in action:
    $array1 = @($null)
    $array2 = @([System.Management.Automation.Internal.AutomationNull]::Value)
    $array1.Count # 1
    $array2.Count # 0
    function ReturnsNull { return $null }
    function ReturnsNothing { }
    $array1 = @(ReturnsNull)
    $array2 = @(ReturnsNothing)
    $array1.Count # 1
    $array2.Count # 0

  • Inconsistency between get-childitem -include and -exclude parameters

    Hi,
    Powershell 2.0
    Does anyone else consider this a minor design bug in the Get-ChildItem command?  
    # create dummy files
    "a","b","c" | % {$null | out-file "c:\temp\$_.txt"}
    # this "fails", returns nothing
    get-childitem c:\temp -include a*,b*
    # this "works", returns desired files
    get-childitem c:\temp\* -include a*,b*
    # this "works", excludes undesired files
    get-childitem c:\temp -exclude a*,b*
    # this "fails", excludes undesired files BUT RECURSES sub-directories
    get-childitem c:\temp\* -exclude a*,b*
    I'm writing a wrapper script around the GCI cmdlet, but the inconsistency between the two parameters is problematic.  My end user will surely just type a path for the path parameter, then wonder why -include returned nothing.  I can't unconditionally
    add an asterisk to the path parameter, since that messes up the exclude output.
    I'm just wondering why Microsoft didn't make the parameter interaction consistent???  
    # includes desired files in the specified path
    get-childitem -path c:\temp -include a*,b*
    # excludes undesired files in the specified path
    get-childitem -path c:\temp -exclude a*,b*
    # combine both options
    get-childitem -path c:\temp -include a*,b* -exclude *.log,*.tmp
    # same as above, the asterisk doesn't matter
    get-childitem -path c:\temp\* -include a*,b*
    get-childitem -path c:\temp\* -exclude a*,b*
    get-childitem -path c:\temp\* -include a*,b* -exclude *.log,*.tmp
    # same as above, but explicitly recurse if that's what you want
    get-childitem -path c:\temp\* -include a*,b* -recurse
    get-childitem -path c:\temp\* -exclude a*,b* -recurse
    get-childitem -path c:\temp\* -include a*,b* -exclude *.log,*tmp -recurse
    If I execute the "naked" get-childitem command, the asterisk doesn't matter...
    # same results
    get-childitem c:\temp
    get-chileitem c:\temp\*
    If this isn't considered a bug, can you explain why the inconsistency between the two parameters when combined with the -path parameter?
    Thanks,
    Scott

    The Get-ChildItem cmdlet syntax is horrific for advanced use. It's not a bug in the classic sense, so you shouldn't call it that. However, feel free to call it awful, ugly, disastrous, or any other deprecatory adjective you like - it really is
    nasty.
    Get-ChildItem's unusual behavior is rooted in one of the more 'intense' dialogues between developers and users in the beta period. Here's how I recall it working out; some details are a bit fuzzy for me at this point.
    Get-ChildItem's original design was as a tool for enumerating items in a namespace -
    similar to but not equivalent to dir and
    ls. The syntax and usage was going to conform to standard PowerShell (Monad at the time) guidelines.
    In a nutshell, what this means is that the Path parameter would have truly just meant Path - it would not have been usable as a combination path specification and result filter, which it is now. In other words
    (1) dir c:\temp
    means you wanted to return children of the container c:\temp
    (2) dir c:\temp\*
    means you wanted to return children of all containers inside
    c:\temp. With (2), you would never get c:\tmp\a.txt returned, since a.txt is not a container.
    There are reasons that this was a good idea. The parameter names and filtering behavior was consistent with the evolving PowerShell design standards, and best of all the tool would be straightforward to stub in for use by namespace
    providers consistently.
    However, this produced a lot of heated discussion. A rational, orthogonal tool would not allow the convenience we get with the dir command for doing things like this:
    (3) dir c:\tmp\a*.txt
    Possibly more important was the "crash" factor.  It's so instinctive for admins to do things like (3) that our fingers do the typing when we list directories, and the instant failure or worse, weird, dissonant output we would get with a more pure Path
    parameter is exactly like slamming into a brick wall.
    At this point, I get a little fuzzy about the details, but I believe the Get-ChildItem syntax was settled on as a compromise that wouldn't derail people expecting files when they do (3), but would still allow more complex use.  I think that this
    is done essentially by treating all files as though they are containers for themselves. This saves a lot of pain in basic use, but introduces other pain for advanced use.
    This may shed some light on why the tool is a bit twisted, but it doesn't do a lot to help with your particular wrapping problem. You'll almost certainly need to do some more complicated things in attempting to wrap up Get-ChildItem. Can you describe some
    details of what your intent is with the wrapper? What kind of searches by what kind of users, maybe? With those details, it's likely people can point out some specific approaches that can give more consistent results.

  • How to get all property names and values of an bean instance at runtime?

    How can I get all property names and values of an bean instance at runtime?
    (The class of the bean instance is dynamic and I can not know before I write the code .)

    Look at Class. It has a way to get at all public methods and attributes.
    If you need to get to private attributes you can do what the Introspector does and expect the methods to follow the Bean pattern and pull the attributes out based upon that. Privates are all hidden from direct access but through the Bean Pattern they can be figured out.

  • I am trying to get a hold of the value of a seeded field

    I added a custom region to a seeded page, part of my validation, I should check a value from the seeded page against a value in my region.
    I am trying to get a hold of the value of a seeded field, this is an Oracle selfservice benefits update page.
    The page name is /oracle/apps/ben/selfservice/enrollment/webui/EnrtSelctPG.
    The fields I am looking at are healthplan option name and the selection field-that has the check flag.
    I am unable to find out the name of the fields and unable to figure out how I can get to the two fields to check their values.
    Can someone please assist?
    Thank you,

    I am trying to validate when the user click next.
    Compare values from my custom region and a value in a nested seeded region. This is the first tme I am trying to get a hold of a seeded field on the seeded page.
    I created stand alone region before, but never compared values and validated Oracle seeded fields.So I am not sure how to go about it.
    Thanks,

  • How to get rid of the residual value in my account

    hi
    i have 1 kr in my itunes accout and i need to change my country but i cant , what i do to get rid of the remaining value .
    thank you

    If you can, enter in a credit card from your original country temporarily so you can buy something that costs more than the balance remaining on your account and thereby use up all the remaining credit. If you cannot or do not wish to put in a credit card, go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store. They can probably clear your remaining balance for you.
    Regards.

  • We are trying to do a Quick payment from payment workbench and getting 'FRM-41830: List of values contains no entries' error for payment document column/field. Payment document setup looks good. Not sure what the issue is.

    We are trying to do a Quick payment from payment workbench and getting 'FRM-41830: List of values contains no entries' error for payment document column/field. Payment document setup looks good. Not sure what the issue is.

    Already gone through following three notes but didn't found resolution.
    APXPAWKB: FRM-41830 When Clicking on Payment Document LOV (Doc ID 1081305.1)
    R12: APXPAWKB: Payment Document Lov Is Empty When Entering A Payment (Doc ID 857587.1)
    R12: Payment Workbench Error: FRM-41830 List Of Values Contains No Entries (APXPAWKB.FMB) (Doc ID 1323875.1)

  • I am trying to export the combained PDF based on BOOK opetion using below scripts. but i am getting following error message "Invalid value for parameter 'to' of method 'exportFile'. Expected File, but received 1952403524". anyone knows, please suggest me

    Dear ALL,
    i am trying to export the combained PDF based on BOOK opetion using below scripts. but i am getting following error message "Invalid value for parameter 'to' of method 'exportFile'. Expected File, but received 1952403524". anyone knows, please suggest me solutions.
    var myBookFileName ,myBookFileName_temp;
                    if ( myFolder != null )
                            var myFiles = [];
                            var myAllFilesList = myFolder.getFiles("*.indd");    
                            for (var f = 0; f < myAllFilesList.length; f++)
                                        var myFile = myAllFilesList[f]; 
                                        myFiles.push(myFile);
                            if ( myFiles.length > 0 )
                                        myBookFileName = myFolder + "/"+ myFolder.name + ".indb";
                                        myBookFileName_temp=myFolder.name ;
                                        myBookFile = new File( myBookFileName );
                                        myBook = app.books.add( myBookFile );  
                                       myBook.automaticPagination = false;
                                        for ( i=0; i < myFiles.length; i++ )
                                                   myBook.bookContents.add( myFiles[i] );             
                                        var pdfFile =File(File(myFolder).fsName + "\\"+myBookFileName_temp+"_WEB.pdf");
                                        var bookComps = myBook.bookContents;
                                        if (bookComps.length === 1)
                                                       bookComps = [bookComps];
                                         var myPDFExportPreset = app.pdfExportPresets.item("AER6");
                                        app.activeBook.exportFile(ExportFormat.PDF_TYPE,File("D:\\AER\\WEBPDF.pdf"),false,myPDFEx portPreset,bookComps);
                                      //myBook.exportFile (ExportFormat.pdfType, pdfFile, false);
                                      //myBook.exportFile(pdfFile, false, pdfPref, bookComps);
                                        myBook.close(SaveOptions.yes);      

    Change the below line:
    app.activeBook.exportFile(ExportFormat.PDF_TYPE,File("D:\\AER\\WEBPDF.pdf"),false,myPDFExp ortPreset,bookComps);
    to
    app.activeBook.exportFile(ExportFormat.PDF_TYPE,File("D:\\AER\\WEBPDF.pdf"),false,myPDFExp ortPreset);
    Vandy

  • How to get the object class field value in CDHDR table for vendor

    hi
    how to get the object class field value in CDHDR table for vendor

    Try KRED/KRED_N as object class in CDHDR for Vendor.

  • How to get the latest credit limit values per each customer in the report.

    Hi All,
    Can anybody give me an idea on how to get the latest credit limit values per each customer in the report.
    I have below requiremnt.
    I have cube which is having transactional data on document and customer level .and it also having master data info object in the cube which is credit management view having all the customer numbers .
    This credit management view is master data info object having credit limit key figure as attribute.These credit limit are per each customer.
    So we need these credit limits in the report as dynamic values .(I mean whatever be the current credit limit in the master data table for that paricular customer that should show up in the reporting).
    one more thing these credit limits should roll up correctly at the HTR level.
    One HTR having number of customers .
    for example HTR 100 can have customer number 200,300,400.
    Those 200,300,400 customer credit limits should roolup correctly at the HTR 100 level.
    Example below :
    Cube DATA :
    HTR Customer Doct number Credit managment view
    100 200 10001 200
    100 200 10002 200
    100 300 10004 300
    100 300 10005 300
    100 400 10006 400
    100 400 10007 400
    100 400 10008 400
    Master data tabel (P Table)(Credit managment view)
    Credit managment view Credit limits
    200 1000.00
    300 50000.00
    400 90000.00
    Please remeber :
    We can not make these credit limits as navigational becasue these are keyfigure attributes not characteristics.
    one more thing we can not make them as charatistics because we need use these credit limits to derive other calkculation. so it is not possibel to derive calculations on charactristics .

    Create a formula variable of type replacement path with reference as attibutes of Credit management view and choose your key figure credit limit,say zcredit.
    Now create a formula or CKF and use zcredit.
    This should display the credit limit in your report as normal key figure.
    I didnot get this part "one more thing these credit limits should roll up correctly at the HTR level.", may be the above will solve this too.Try it.
    Hope this helps.

  • How can I get the variable with the value from Thread Run method?

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    // I should get Inside the run method::: But I get only Inside
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    We want to access a variable from the run method of a
    Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
    Even
    though I make the variable as public /public static, I
    could get the value till the end of the run method
    only. After that scope of the variable gets lost
    resulting to null value in the called method/class..
    I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
    public class SampleSynchronisation
      public static void main(String[] args)
        SampleSynchronisation app = new SampleSynchronisation();
      public SampleSynchronisation()
        MyRunnable runner = new MyRunnable();
        new Thread(runner).start();
        // yield this thread so other thread gets a chance to start
        Thread.yield();
        System.out.println("runner's X = " + runner.getX());
      class MyRunnable implements Runnable
        String X = null;
        // this method called from the controlling thread
        public synchronized String getX()
          return X;
        public void run()
          System.out.println("Inside MyRunnable");
          X = "MyRunnable's data";
      } // end class MyRunnable
    } // end class SampleSynchronisation>
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run
    method "+sathr.x);
    // I should get Inside the run method::: But I get
    only Inside
    class sampleThread extends Thread
    public String x="Inside";
    public void run()
    x+="the run method";
    NB: if i write the variable in to a file I am able to
    read it from external method. This I dont want to do

  • How can I get the variable with the value from Thread's run method

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get:
    Inside the run method
    But I get only:
    Inside*/
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

  • Which table i can get BED and ECS+SHEC values

    Hi all
    which table i can get BED and ECS+SHEC values and how i link to PO number..
    plz help me
    thanks
    ramesh

    Hi
    please search before you post the question ,
    this query is discusssed many times in the forum
    [Searching|http://lmgtfy.co/?q=sapexcise%20table]
    for excise check table J_1IEXCHDR for header
    J_1IEXCDTL for item excise

Maybe you are looking for

  • Open Po quantity in subcontracting Purchase Order

    Hi,   In case subcontracting purchase order,If order quantity 10 and recept quantity is 05 then in delivery shedule tab I didn't got any open purchase order quantity means  05 quantity why? Thanks and Regards Anil Patil

  • What's the quickest way to reset my security questions because I don't remember my answers

    What's the quickest way to reset my security questions because I don't remember my answers

  • Clearing a G/L account

    Hi, I have an issue about a G/L account. There is a difference between amounts which were posted on the G/L account and the amounts which appear when trying to clear the account via transaction F-03. What can cause these variances? Thank you. Kind re

  • BugCheck Dump

    please review if this stack dump is a concern or if it's a one time non-critical event.  If it's a concern, please provide any recommendations. =====================================================================                                    

  • What in the heck happened???

    I am a late night radio DJ. I had purchases on my playlist that wouldn't play during my show...I PAID FOR THEM...HAD THEM WORK...THEY DIDN'T WORK DURING MY SHOW, MAKING ME LOOK BAD.  WHAT THE HECK HAPPENED????