Splitting a get-Item LastwriteTime

I am trying to pull a number of variables to be used in various places in a script I have had trouble with the formatting of the strings
I organically came to the following conclusion but I am sure there is a better way!
$Date=Get-Item "C:\BOSS"|Select LastWriteTime|Format-Wide
$Datesimple=Get-Date -format Mdy
$Dates= $date | out-string
$sDates= $dates -split ("/")
$year = $sdates[2] -split (" ")
$mm = $sdates[0] | out-string
$d = $sdates[1] | out-string
$yyyy = $year[0] | out-string
$folderd = $mm+$d+$yyyy
$folderd = $folderd -replace "[^\d]","
This is probrably solvable in a single line of code I just couldn't figure out how!

[datetime]$Date = (Get-Item "C:\BOSS").LastWriteTimeGet the day
$date.day
Try to typecast to datetime object
Hope this helps

Similar Messages

  • Get-Item: Cannot find path ' ' because it does not exist. While running Powershell script.

    I am trying to run a PowerShell script to upload files into a SharePoint site in an Azure environment...the script works fine on my local machine, but every time I run it in Azure (remotely), I get errors. Here is what my simple script looks like...
    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
    Write-Host "Loading Sharepoint Module "
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell) -eq $null )
    Write-Host "Failed to load sharepoint snap-in. Could not proceed further, Aborting ..."
    Exit
    #Script settings
    $webUrl = "http://sampleWebUrl"
    $docLibraryName = "My Documents"
    $docLibraryUrlName = "My%20Documents"
    $localFolderPath = get-childitem "C:\Upload\Test Upload\My Documents\" -recurse
    $contentType = "ContenttType1"
    #Open web and library
    $web = Get-SPWeb $webUrl
    write-host "Web:" $web
    $docLibrary = $web.Lists[$docLibraryName]
    write-host "docLibrary:" $docLibrary
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
    write-host "files:" $files
    If ($contentType = "ContenttType1")
    #Open file
    $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()
    # Gather the file name
    $FileName = $File.Name
    #remove file extension
    $NewName = [IO.Path]::GetFileNameWithoutExtension($FileName)
    #split the file name by the "-" character
    $FileNameArray = $NewName.split("_")
    $check = $FileNameArray.Length
    #Add file
    $folder = $web.getfolder($docLibrary.rootFolder.URL)
    write-host "Copying file " $file.Name " to " $folder.ServerRelativeUrl "..."
    $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
    $spItem = $spFile.Item
    write-host "Success"
    write-host "SP File:" $spFile
    write-host "SP Item" $spItem
    #populate columns
    $spItem["Column1"] = $FileNameArray[0]
    $spItem["Column2"] = $FileNameArray[1]
    $spItem.Update()
    $fileStream.Close();
    Again, I can run this on my local machine and it works just fine, but when I attempt to run it on the Azure environment I get this error...
    Get-Item : Cannot find path 'C:\powershellscripts\12653_B7045.PDF' because it does not exist.
    At C:\PowerShellScripts\Upload-FilesIntoSharePointTester.ps1:32 char:42
    +     $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
    +                                          ~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (C:\powershellscripts\12653_B7045.PDF:String) [Get-Item], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
    What strikes me first is the fact that the file its looking for is in the "C:\Upload\Test Upload\My Documents\" directory, but the error keeps saying "C:\powershellscripts\" which is where my script resides and not the files I want to
    upload into SharePoint. When I step through the code, all the variables are holding the correct values. The $localFolderPath shows the name of files that I am attempting to upload, so it recognizes them. But once I step through this particular line of code,
    the error occurs...
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()
    Is this an error caused because I am remoting into the Azure environment? Has anyone dealt with this issue before? I would really appreciate the help. Thanks
    Update: quick thing I noticed is that these two lines of code are returning null values. Again, is this handled differently in Azure or remotely? I ask cause this is the way I know how to do this, locally.
    $docLibrary = $web.Lists[$docLibraryName]
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()

    "...square brackets are wildcard characters in Windows PowerShell..."
    When you use cd without a parameter it uses the -Path parameter. In this case you'll have to escape the square brackets so they are not considered wildcards. Each of the commands in the first example does the exact same thing.
    cd 'Learn PowerShell `[Do Whatever`]'
    cd -Path 'Learn PowerShell `[Do Whatever`]'
    cd (or Set-Location) also has a literal path parameter (-LiteralPath) that does not require using an escape character (`) before each of the brackets. Hope this helps.
    cd -LiteralPath 'Learn PowerShell [Do Whatever]'

  • Splitting the Line items in Transaction LB02........

    Hi Frnds,
                I would like to know how to proceed further....afetr entering into standard transaction LB02, the user wants to split the line items depending on the quantity what he has enterd in the custom screen which i developed.
               Here am able to get the data in background necessary to goto standard transaction. After entering into the standard transaction how to split the line items.
    Functional Requirement
    In the screen, which i developed...
    The user enters material no...
    -->Matl qty  & matl desc will be displayed....
    -->Then user enters the bin no.   and the qty he wants to keep in that particular bin.
    -->Here depending on the qty the user has entered it has to reflect in the Tcode LB02.
    -->For example, total qty displayed in the custom screen after entering the matl no. is 20  From this qunatity, the user enters the quantity as 10 which is not GE to that qty (20)  which we got from database.
    -->Now this has to be replicated in the standard transaction in such a way that..the line items should also split according to the qty the user enters.......it may be upto n no. of  line items.....and the bin no. should also be entered into the stnd Tcode LB02 at the unloading point field......
    Thanks & Regards
    Message was edited by:
            Badri Thiriveedhi

    Managed to find an Enhancement Point in the Standard SAP Code and hence the Issue is resolved.
    Thanks and Regards,
    Venkat Phani Prasad Konduri

  • How to split a line item to 2 line item.

    Hi all !
    I have a request, help me please !
    In system I have a invoice with 1 line item value 1000 USD.
    Customer payment 600$. a incoming payment with value 600$ will post to system.
    I want incoming payment and invoice will auto clear 600$ but system can't auto clearing because value is not Identical.
    I want line item of invoice will split to 2 line item. Line item 1 value 600$ and line item 2 value 400$.
    Line item 1 of invoice will auto clear with incoming payment and system will exist a invoice with 1 line item value 400$.
    How to split a line item to 2 line item ? Have FM for split a line item to 2 line item in SAP ?
    If you have other solution for this request, help me please !
    Thanks !

    Hi,
    Have a look at Split line item - Sales Order
    Regards

  • Finder got an error: Can't get item 1 of {document file "foo" ...}

    I have a lot of files in Corel Painter 8's RIFF format. I want to write a script that opens a file and somehow forces Corel Painter 8 to save the file as a GIF. GUI scripting may be some help with the latter; now I am concentrating on finding RIFF files and opening them in Corel Painter 8.
    I have a script that does a depth-first search of the folders starting at some root folder, using the Finder application to do the file-system stuff. It creates a list with
    set docs to every document file of pages_folder whose file type = "RIFF"
    as it loops through folders it adds to the list like this:
    set more_documents to every document file of a_folder whose file type = "RIFF"
    set docs to docs & more_documents
    My naîve mental model is that docs is a list of document-file objects. Next I have a loop that attempts to strip out files for which a GIF file already exists (and is no older than the RIFF document). This works by deleting non-matching items like so:
    if not isgifneeded then
    set docs to items 1 thru (i - 1) of docs & items (i + 1) thru (length of docs) of docs
    end if
    Finally it tries to open one of the files in Corel Painter 8 using the Finder:
    open item 1 of docs using "Corel Painter 8"
    This does not work. I get an error message
    Finder got an error: Can't get item 1 of {document file "bar" of folder "foo" of folder "blah" of folder "pdc" of folder "Users" of startup disk, ... }."
    It lists all of the files. (The error message appears in a sheet that extends off the bottom of the screen!) They are identified in the message as document-file objects. The curly braces are, I believe, the AppleScript notation for a list. I expect to be able to obtain the first element of a list with ‘item 1 of xs’. My assumption is that the Finder’s open command would expect a document file object, or at least would be able to cope with being asked to open a document. What am I missing here?
    PowerBook 12" without mini-DVI   Mac OS X (10.4.7)  

    Hi Damian and welcome to Apple Discussions!
    One suggestion: try
    tell application "Finder" to open item 1 of docs
    (without 'using "Corel Painter 8"')
    As far as the Finder is concerned, "Corel Painter 8" is just a string of characters. And telling the Finder to open a file is just the same as double-clicking it: the Finder knows which app to use - as long as these are native Corel Painter 8 docs.
    Hope this helps,
    H

  • How to get items from a list that has more items than the List View Threshold?

    I'm using SharePoints object model and I'm trying to get all or a subset of the items from a SharePoint 2010 list which has many more items than the list view threshold (20,000+) using the SPList.GetItems() method. However no matter what I do the SPQueryThrottledException
    always seems to be thrown and I get no items back.
    I'm sorting based on the ID field, so it is indexed. I've tried setting the RowLimit property on the SPQuery object(had no effect). I tried specifying the RowLimit in the SPQuerys ViewXml property, but that still throws a throttle exception. I tried using the
    ContentIterator as defined here:http://msdn.microsoft.com/en-us/library/microsoft.office.server.utilities.contentiterator.aspx,
    but that still throws the query throttle exception. I tried specifying the RowLimit parameter in the ProcessListItems functions, as suggested by the first comment here:http://tomvangaever.be/blogv2/2011/05/contentiterator-very-large-lists/,
    but it still throws the query throttle exception. I tried using GetDataTable instead, still throws query throttle exception. I can't run this as admin, I can't raise the threshold limit, I can't raise the threshold limit temporarily, I can't override the lists
    throttling(i.e. list.EnableThrottling = false;), and I can't override the SPQuery(query.QueryThrottleMode = SPQueryThrottleOption.Override;). Does anyone know how to get items back in this situation or has anyone succesfully beaten the query throttle exception?
    Thanks.
    My Query:
    <OrderBy>
        <FieldRef Name='ID' Ascending='TRUE' />
    </OrderBy>
    <Where>
        <Geq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Geq>
    </Where>
    My ViewXml:
    <View>
        <Query>
            <OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy>
            <Where>
                <Geq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Geq>
            </Where>
        </Query>
        <RowLimit>2000</RowLimit>
    </View>
    Thanks again.

    I was using code below to work with 700000+ items in the list.
    SPWeb oWebsite = SPContext.Current.Web;
    SPList oList = oWebsite.Lists["MyList"];
    SPQuery oQuery = new SPQuery();
    oQuery.RowLimit = 2000;
    int intIndex = 1;
    do
    SPListItemCollection collListItems = oList.GetItems(oQuery);
    foreach (SPListItem oListItem in collListItems)
    //do something oListItem["Title"].ToString()
    oQuery.ListItemCollectionPosition = collListItems.ListItemCollectionPosition;
    intIndex++;
    } while (oQuery.ListItemCollectionPosition != null);
    Oleg
    Hi Oleg, thanks for replying.
    The problem with the code you have is that your SPQuery object's QueryThrottleMode is set to default. If you run that code as a local admin no throttle limits will be applied, but if you're not admin you will still have the normal throttle limits. In my
    situation it won't be run as a local admin so the code you provided won't work. You can simulate my dilemma by setting the QuerryThrottleMode  property to SPQueryThrottleOption.Strict, and I'm sure you'll start to get SPQueryThrottledException's
    as well on that list of 700000+ items.
    Thanks anyway though

  • User exit for split of PO items

    Hi all.
    In the creation of purchase orders from SRM shopping carts, we have a requirement to split the service purchase order lines in different items when the tax code in SRM is different. I mean, the requirement is to have only services with the same tax code in SRM in the same PO item. If the SRM tax code is different for a concrete service I have to split it in another PO item.
    In short, what I need is to know any user exit, badi, etc... in the creation of PO for the splitting of PO items. Can anyone of you help me?
    Thanks in advance.

    Hello Manosij.
    I have not much experience in SRM. I think that the difference between scenarios is where the subsequent documents of a shopping cart are created, is that right? In my case, the PO is created in the backend, in R/3.
    In the shopping cart (in SRM) the services are created everyone in a different SC item, with the possibility of having different tax codes for each one. However, in the purchase order (in R/3), the services are grouped all together in a unique PO item, all of them under a unique tax code (EKPO-MWSKZ). What I need to do is to have a PO item for each different tax code from the SC. The services have to be under their correspondent tax code in the PO.
    For example, I am creating a SC with two services, one of them with tax code VP and the other one with tax code V5. The PO must have two items, one with tax code VP and the other one with tax code V5. Currently, the PO is being created with a unique item with tax code VP. If both items in the SC would have tax code VP, it would be correct to have the PO with a unique item with tax code VP.
    I hope this clarify my requirement.
    Thanks.

  • Why do I get items at top level in Import Manager?

    Hello all:
    When trying to import from XML file using XML Schema, from IDoc type /AFS/MATMAS04, I get items that should appear as a table, as fiels of structure E1MARAM instead of as a separated table.
    I've already reviewed the XML Schema file XSD, and the maxOccurs parameter is properly set.
    Can anyone please tell me a list of possible reasons for this to happen or provide any other helpful hints?
    Thanks in advance!

    hello bigfootjim159, please try to remove the complitly extension in firefox/tools > addons > extensions - it's adware. also have a look in the windows control panel and uninstall any toolbars or unwanted entries there.
    [[Troubleshoot Firefox issues caused by malware]]

  • How to get item text in smart form

    Hi ABAP Gurus,
                 i want to know how to get the item text in smart forms procedure i know but the logic where to define the variable ect.
    code to get item text in purchase order.

    Hi
    Smartform itself have a functionality to get
    Item Text
    create a text
    change the Text Type to include type
    der in u pass the required entery in the same way how u pass to read text entry
        Text Name         &ZXEKKO-EBELN&
        Text Object       EKKO
        Text ID           F03
        Language          EN
    with Regards
    Rohan Shetty

  • After installing IOS 6.1, how do I get items in "Music" to stop moving?

    After installing IOS 6.1, how do I get items in "Music" to stop moving?

    I was having this same issue.  I went into Settings -> iCloud and turned the Notes sync ON (which when I tried to do previously, i was prompted to create an iCloud email address which I already had).  Once I turned that on, I went to Settings ->Notes and I now see a "Default Account" selection which is set to iCloud.  Now all of my new notes save on the phone and on the cloud.  This doesn't fix the fact that I appear to have forever LOST all the notes I had before iOS6.1.  Apple, we're still waiting for a response???

  • Camel Query : Calender list : Get Items agains given date that must be greater than and eqaul to start date and greater less than or equal to end date ?

    Camel Query : Calender list : Get Items agains given date that must be greater than and eqaul to start date and greater less than or equal to end date ?
    A Snap of Employee holiday list
    Case : Anne juul Sondergaar is on leave from 05-06-2014 to 07-06-2014
    I need a query to check wheither Anne juul is on leave at 06-06-2014 ????
    I am using this query that return nothing
    SPQueryquery =
    newSPQuery();
                                query.Query =
    @"<Where>
    <And>
    <And>
    <Leq>
    <FieldRef Name='Til' />
    <Value Type='DateTime'>"
    + WorkingStartDate.ToString("yyyy-MM-dd")
    + @"</Value>
    </Leq>
    <Geq>
    <FieldRef Name='Fra' />
    <Value Type='DateTime'>"
    + WorkingStartDate.ToString("yyyy-MM-dd")
    + @"</Value>
    </Geq>
    </And>
    <Eq>
    <FieldRef Name='Medarbejdere' />
    <Value Type='Lookup'>"
    + EmployeeName.Trim() +
    @"</Value>
    </Eq>
    </And>
    </Where>"
                                query.ViewFields =
    " <FieldRef Name='ID' />";
    Ahsan Ranjha

    Hello,
    Download CAML query builder from below location and use it to build your query:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/f7b36ebc-6142-404a-8b04-9c87de272871/where-can-i-download-the-u2u-caml-query-builder-for-sharepoint-2010may-i-know-the-exact-link?forum=sharepointgeneralprevious
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • New on POO : get items from purchase order

    Hi,
    i'm new in OO, i must implement the BADI IF_EX_ME_PROCESS_PO_CUST~CHECK. In this method i would like to get items of my current purchase order, how can i do that ?
    Thanks a lot.
    Cheers

    Hello
    Please note that if you have understood this BAdI then you have understood the basics of ALL BAdIs dealing with business objects that have a header and one or more items.
    Example: BAdI ME_PROCESS_REQ_CUST (purchase requisition)
    METHOD if_ex_me_process_REQ_cust~check.
    * define local data
      DATA:
        lt_items      TYPE mmpur_requisition_items,
    *    ls_item       LIKE LINE OF lt_items,  " alternatively
        ls_item       TYPE mmpur_requisition_item,
        ls_header     TYPE mereq_header.
    " Change data types of local variables (compared to if_ex_me_process_PO_cust~check)
    " but use the very same coding to retrieve the items.
    * (1) Get the order items
    *  CALL METHOD im_header->get_items
    *    receiving
    *      re_items = lt_items.
    * Short version:
      lt_items = im_header->get_items( ).
      LOOP AT lt_items INTO ls_item.
        ls_detail = ls_item-item->get_data( ).
    *   do something ...
      ENDLOOP.
    * (2) Get header data
    *  CALL METHOD im_header->get_data
    *    receiving
    *      re_data = ls_header.
    * Short version:
      ls_header = im_header->get_data( ).
    ENDMETHOD.
    Regards
      Uwe

  • Split one salesorder item into two items in delivery

    We want to split one salesorder item into two different items in the same delivery.
    This is because we will pick the material from two different storage locations.
    Any user-exit to use for solving this?
    Best regards,
    Terje

    Hi,
    We are not using batch management.
    I have looked into the foreign trade/customs standard functionality in SAP, but I can not see that them difference in stock in SAP what is duty paid or not.
    We need to have documentation in the system for the custom goverement for what stock is duty paid and not.
    For the same material we can have stock which are duty paid and not duty paid. This is decided when we do the goods receipt.
    For stock coming from Asia, it is profitable to have this on not duty paid stock since we are exporting it back to Europe and Asia later.
    We will send import and export EDI messages to a third party custom application handling all the papers with the custom goverement.
    The only we need to make track on in SAP is the stock for what is duty paid and not.
    In some situations we need to take stock from both duty paid stock and not duty paid stock when we deliver the same material to a customer. Therefor I asked the question of splitting one delivery item into two items.
    Best regards,
    Terje

  • Get Items from limited list by providing username and password - C#

    I'm using the code at the following link in order to get items from SharePoint list,
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.list.getitems.aspx
    I have a SharePoint list that limited to certain users.
    How can I provide by this code (or else) a username and password and log in as a different user who has access to this SharePoint list and get its items?
    Thanks!

    Sorry, previous post didn't see you were using client object model.
    Service.Credentials = (create new credentials passing username and password)
    ICredentials credentials = new NetworkCredential("Joe",SecurelyStoredPassword,"mydomain");
                math.Credentials = credentials
    Thanks!
    Actually, my full question already posted here:
    http:  //sharepoint.stackexchange.com/questions/84917/c-why-impersonation-is-expired-while-clientcontext-executequery-is-performe
    but I was unable to post it here as a new user (images, links, lenght ...) even the link above I was need to insert spaces after "http:" to be able to post it.
    Anyway, I don't know "client object model." am I using it?
    You mentioned "Service.Credentials", What do you mean "Service"?

  • How to get item's cost price?

    I want to get Item's cost price. I get a business boject 'item',g_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems),There are two key to decide one cost price,one is 'itemcode',another is 'whscode',How to get one record by using 'GetByKey' method? Thanks.

    Hi Lu,
    You can get the price in the warehouse as following if you don't want to use a recordset:
            Dim oItem As SAPbobsCOM.Items
            Dim dPrice As Double
            Dim i As Integer
            oItem = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
            oItem.GetByKey("MyItem")
            For i = 0 To oItem.WhsInfo.Count - 1
                oItem.WhsInfo.SetCurrentLine(i)
                If oItem.WhsInfo.WarehouseCode = "TheWarehouseIWant" Then
                    dPrice = oItem.WhsInfo.StandardAveragePrice
                End If
            Next
    Hope it helps,
    Adele

Maybe you are looking for