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

  • 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

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

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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