Created
July 30, 2018 05:03
-
-
Save owns/7570392c8783e2550116b1f71d8f8c17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLS | |
<# list .net installed versions | |
[System.Environment]::Version() | |
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | | |
Get-ItemProperty -name Version,Release -EA 0 | | |
Where { $_.PSChildName -match '^(?!S)\p{L}'} | | |
Select PSChildName, Version, Release | |
#> | |
function Using-Object | |
{ | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[AllowEmptyString()] | |
[AllowEmptyCollection()] | |
[AllowNull()] | |
[Object] | |
$InputObject, | |
[Parameter(Mandatory = $true)] | |
[scriptblock] | |
$ScriptBlock | |
) | |
try | |
{ | |
. $ScriptBlock | |
} | |
finally | |
{ | |
if ($null -ne $InputObject -and $InputObject -is [System.IDisposable]) | |
{ | |
$InputObject.Dispose() | |
} | |
} | |
} | |
function log([string]$s){ | |
process { | |
Write-Host "$(get-date -format 'yyyy-MM-dd hh:mm:ss.fffffff') $s" | |
} | |
} | |
$dl1 = 'C:\SOME\FOLDER\2013\Microsoft.SharePoint.Client.Runtime.dll' | |
$dl2 = 'C:\SOME\FOLDER\2013\Microsoft.SharePoint.Client.dll' | |
log $dl1 | |
log $dl2 | |
Add-Type -Path $dl1 -ErrorAction Stop | |
Add-Type -Path $dl2 -ErrorAction Stop | |
$siteURL = 'https://my/sharepoint/site/' | |
Using-Object($ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)){ | |
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("USERNAME",(ConvertTo-SecureString 'PASSWORD' -AsPlainText -Force)) | |
$ctx.Credentials = $credentials | |
log 'connectiong ...' | |
try { | |
$ctx.ExecuteQuery() | |
} catch { | |
log $_ | |
return | |
} | |
log 'connected!!!' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment