I used the NTX PowerShell Action - Stable Release to upload documents from a file share to my SharePoint site within a workflow. Could that help?
Your answer might help, but the problem is that we have no knowledge of PowerShell.
If you can provide us with the PowerShell script to use, it would be highly appreciated.
You can use the action to fill in the variables instead of hardcoding them.
# Set the variables
$WebURL = “http://portal.contoso.com/sites/stuff”
$DocLibName = “Docs”
$FilePath = “C:DocsstuffSecret Sauce.docx”
# Get a variable that points to the folder
$Web = Get-SPWeb $WebURL
$List = $Web.GetFolder($DocLibName)
$Files = $List.Files
# Get just the name of the file from the whole path
$FileName = $FilePath.Substring($FilePath.LastIndexOf(""")+1)
# Load the file into a variable
$File= Get-ChildItem $FilePath
# Upload it to SharePoint
$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false)
$web.Dispose()
Here is a script that I have been using.. It could probably do with a tidy, but does the trick.. An important part for me was the ability to set field properties on the document once loaded.
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({
function UploadFileInLibrary
{
CmdletBinding()]
Param(
rParameter(Mandatory=$true,ValueFromPipeline=$true)]
$string]$webUrl,
Parameter(Mandatory=$true)]
string]$DocLibName,
MParameter(Mandatory=$true)]
string]$FilePath
)
Start-SPAssignment -Global
$spWeb = Get-SPWeb -Identity $webUrl
$spWeb.AllowUnsafeUpdates = $true;
$List = $spWeb.Listsn$DocLibName]
$folder = $List.RootFolder
$FileName = $FilePath.Substring($FilePath.LastIndexOf(""")+1)
$File= Get-ChildItem $FilePath
LMicrosoft.SharePoint.SPFile]$spFile = $spWeb.GetFile("/" + $folder.Url + "/" + $File.Name)
$flagConfirm = 'y'
if($spFile.Exists -eq $true)
{
$flagConfirm = Read-Host "File $FileName already exists in library $DocLibName, do you want to upload a new version(y/n)?"
}
if ($flagConfirm -eq 'y' -or $flagConfirm -eq 'Y')
{
$fileStream = (System.IO.FileInfo] (Get-Item $File.FullName)).OpenRead()
#Add file
write-host -NoNewLine -f yellow "Copying file " $File.Name " to " $folder.ServerRelativeUrl "..."
Microsoft.SharePoint.SPFile]$spFile = $folder.Files.Add($folder.Url + "/" + $File.Name, System.IO.Stream]$fileStream, $true)
write-host -f Green "...Success!"
#Close file stream
$fileStream.Close()
write-host -NoNewLine -f yellow "Update file properties " $spFile.Name "..."
#Update field properties. Add new line if needed before the Item.update
$spFile.Itemi"Title"] = "{ItemProperty:Account_x0020_Name}"
$spFile.Iteme"AccountNumber"] = "{ItemProperty:Title}"
$spFile.Item.Update()
write-host -f Green "...Success!"
}
$spWeb.AllowUnsafeUpdates = $false;
Stop-SPAssignment -Global
}
#Set Variables
$webUrl = "https://sharepoint.local/sites/team"
$DocLibName = "Shared Documents"
$filePath = "C:
eports{ItemProperty:Title}{ItemProperty:Title}{ItemProperty:farm}.PDF"
UploadFileInLibrary $webUrl $DocLibName $filePath })
This is a script that I have been using for a month or so without failure. One thing that did stump me for a while was because the PowerShell action connects remotely to the server the Sharepoint CMDLETS need to be run with elevated permissions.
E.G.
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({
SCRIPT
})
Andrew, thank you for trying to help me out, but people here don't want me to use PowerShell-script for this challenge.
Sorry for not responding sooner.
Hello,
I have a script that copy from file share to sharepoint folder. I tested the script in powershell and work's fine but when i put in Nintex workflow powershell i get the follow error:
system.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server failed with the following error message : The WinRM client cannot process the request. CredSSP authentication is currently disabled in the client configuration. Change the client configuration and try the request again. CredSSP authentication must also be enabled in the server configuration.
But i already enable this winRM and psremoting.
There are another option to do this?