1

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

1
  • 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! Commented Oct 25, 2012 at 15:40

1 Answer 1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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