am trying to get all the fields in the document library in my site collection. here is my code . but after entering my username/password , it throws error:
$SiteURL = "http://vmsrvr1:28516/"
Write-Host "Loading CSOM libraries" -foregroundcolor black -
backgroundcolor
yellow
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web
Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web
Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Write-Host "Lib. successfully loaded !" -foregroundcolor black -
backgroundcolor Green
$scriptPath = "D:\PoCSolutions"
$User = "mydomain\adminuser1" #Read-Host -Prompt "username"
$password = Read-Host -Prompt "Enter password" -AsSecureString
Write-Host "Trying to reach $SiteURL // Handling ClientContext..." -
foregroundcolor black -backgroundcolor yellow
$Context = New-Object
Microsoft.SharePoint.Client.ClientContext($SiteURL)
$credentials = New-Object
Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,
$password)
$Context.Credentials = $credentials
$context.RequestTimeOut = 5000 * 60 * 10;
$web = $context.Web
$site = $context.Site
$context.Load($web)
$context.Load($site)
try
{
$context.ExecuteQuery()
Write-Host "Connected !" -foregroundcolor black -backgroundcolor
Green
}
catch
{
Write-Host "Impossible to reach $SiteURL : bad password ?" -
foregroundcolor black -backgroundcolor Red
return
}
$list = $web.Lists["APT"];
$fields = $list.Fields;
$list.Fields | select InternalName | Export-Csv -path ./blabla.csv;
Write-Host "Done !" -foregroundcolor black -backgroundcolor Green
error is
New-Object : Exception calling ".ctor" with "2" argument(s): "The 'username' argument is invalid." At E:\PoCSolutions\getallfields1.ps1:18 char:16 + $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredential ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
