Powershell上传大文件到子目录下

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Publishing\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Publishing.dll"
Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Search\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Search.dll"
Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.DocumentManagement\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.DocumentManagement.dll"

#Set parameter values
$SiteURL="https://one.sharepoint.com/"
$SourceFilePath="D:\Files\TM1.xlsx"
$TargetFolderRelativeURL ="/Shared Documents"
$User = "jz@one.com"
$Password = "P@ssword"  | ConvertTo-SecureString -AsPlainText -Force

#Bind to site collection
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Ctx.Credentials = $Credentials

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get the Target Folder to upload
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $TargetFolder = $Web.GetFolderByServerRelativeUrl($TargetFolderRelativeURL)
    $Ctx.Load($TargetFolder)
    $Ctx.ExecuteQuery() 

    #Get the source file from disk
    $FileStream = ([System.IO.FileInfo] (Get-Item $SourceFilePath)).OpenRead()
    #Get File Name from source file path
    $SourceFileName = Split-path $SourceFilePath -leaf  
    $TargetFileURL = $TargetFolderRelativeURL+"/"+$SourceFileName

    #Upload the File to SharePoint Library Folder
    $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
    $FileCreationInfo.Overwrite = $true
    $FileCreationInfo.ContentStream = $FileStream
    $FileCreationInfo.URL = $TargetFileURL
    $FileUploaded = $TargetFolder.Files.Add($FileCreationInfo)  
    $Ctx.ExecuteQuery()  

    #Close file stream
    $FileStream.Close()
    Write-host "File '$TargetFileURL' Uploaded Successfully!" -ForegroundColor Green
}
catch {
    write-host "Error Uploading File to Folder: $($_.Exception.Message)" -foregroundcolor Red
}

PowerShell上传文件到SharePoint子目录下

今天客户有一个需求,需要每天定时产生的报表文件上传SharePoint服务器上,网上找了资料,可以上传到相应的根目录下,就是不能上传到子目录下,测试了很多方法都不行,最后在下班的路上通过手机找到了相关资料,进行了一顿修改后,成功将文件放置到客户SharePoint的指定目录下。
原文连接(英文

如果Windows服务器上没有安装过Sharepoint,那就需要安装一个SharePoint Server 2016 Client Components SDK,安装之后需要确定两个DLL文件的对应位置,在执行PowerShell脚本的时需要用到的,具体可以参考我脚本。

#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
#Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
#Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Runtime.dll"

#Specify tenant admin and site URL
$User = "jzh@one.com"
$SiteURL = "https://one.sharepoint.com/sites/Partners/"
$Folder = "D:\username\test\"
$DocLibName = "Documents"
$FolderName = "Analytics"
$Password = "P@ssword"  | ConvertTo-SecureString -AsPlainText -Force

#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds

#Retrieve list
$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List.RootFolder)
$Context.ExecuteQuery()

#Retrieve folder
$FolderToBindTo = $List.RootFolder.Folders
$Context.Load($FolderToBindTo)
$Context.ExecuteQuery()
$FolderToUpload = $FolderToBindTo | Where {$_.Name -eq $FolderName}

#Upload file(s)
Foreach ($File in (dir $Folder -File))
{
    $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
    $FileCreationInfo.Overwrite = $true
    $FileCreationInfo.Content = [System.IO.File]::ReadAllBytes($File.FullName)
    $FileCreationInfo.URL = $List.RootFolder.ServerRelativeUrl + "/" + $FolderName + "/" + $File.Name
    $UploadFile = $List.RootFolder.Files.Add($FileCreationInfo)
    $Context.Load($UploadFile)
    $Context.ExecuteQuery()
}

解决Excel 2016无法直接打开文件的问题

新安装的OFFICE 2016发现从邮件中、微信中都无法直接打开Excel文件,查询了解决方法有2个,大家可以试试看。

1、修改注册表,位置:计算机\HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\Open\command,在最后添加一下“%1”的参数,如果原来有其他参数“DDE”之类的删除,最后的结果为

"C:\Program Files\Microsoft Office\Root\Office16\EXCEL.EXE" "%1"

2、在选项-->高级中取消“忽略使用动态数据交换(DDE)的其他应用程序”前的勾选。

Windows远程桌面连接出现CredSSP的解决方法

今天远程桌面的时候失败了,出现以下提示"CredSSP加密Oracle”错误

于是上网找解决办法,经过测试,该方法是可行的。

首先,在控制台中输入regedit,打开注册表

接着按照以下目录依次展开HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\,接着在System目录下创建两级文件夹,也就是新建项,CredSSP\Parameters,

然后再Parameters下右键-》新建DWORD 32位,修改名称AllowEncryptionOracle。

双击修改值为2.

之后去试一下远程连接桌面,应该就可以了。