Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am new in powershell, i want to save a file which powershell will automatically create new subfolder in sharepoint 2010 and save it ( the subfolder named should be todayname i.e. 25Oct2012) :

here is the script :

$sharepointsave = "SiteURL+DocumentLibrarypath" + "/" + $today + "/"

New-Item $sharepointsave -type directory -Force

$sharepointpath = "SiteURL+DocumentLibrarypath" + "/" + $today + "/"
$sharepointsave = $sharepointpath + $filename + $today + ".xls"

$b.SaveAs($sharepointsave1)

however, it couldn't create the subfolder ... would you please help

Thanks very much

Best Regards Mary

share|improve this question
    
Mary, can you please echo or Write-Host the $today variable, I think it contains some special characters which are invalid for a folder name! –  Arsalan Adam Khatri Oct 25 '12 at 15:40

1 Answer 1

Mary,

I think the $today variable returns some special characters with it, which are invalid for a folder name and that causes it not to create the folder...

Can you please try date formatting like:

$completeFolderName = Get-Date -format dMMMyyyy

Reference to Date Formats in Powershell

UPDATE: Here is how you create folders from PowerShell:

PS > $spFolder = $spDocumentLibrary.AddItem( 
>> "",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,"My New Folder" 
>>) 
PS > $spFolder.Update()

Please refer to: Use PowerShell Cmdlets to Manage SharePoint Document Libraries

share|improve this answer
    
Hi, I have tried this, but it cannot create the subfolder in sharepoint (e.g. subfolder name'25Oct2012') –  Mary Oct 29 '12 at 7:15
    
it said "Path not found" in sharepoint , so ...i guess it cannot create new subfolder... –  Mary Oct 29 '12 at 7:16
    
Mary, I have updated the answer –  Arsalan Adam Khatri Oct 29 '12 at 14:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.