How do I add a list column to the list content type through SharePoint Online PowerShell?

I am trying to add a custom property to list the content type on the SharePoint Online site using the following script:

$context=New-Object Microsoft.SharePoint.Client.ClientContext($URL)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)

$web = $context.Web

$lib = $web.Lists.GetByTitle("Document Library")


$cts = $lib.ContentTypes

ForEach ($c in $cts) {
     if($c.Name -eq "Document") {
        $ct = $c

$fields = $lib.Fields

ForEach ($fl in $fields) {
    if($fl.Title -eq "Keyword") {
        $keyword = $fl

$link=new-object Microsoft.SharePoint.Client.FieldLinkCreationInformation


But I have an exception below during execution.

Exception setting "Field": "Cannot convert the
"Microsoft.SharePoint.Client.FieldText" value of type
"Microsoft.SharePoint.Client.FieldTe xt" to type
"Microsoft.SharePoint.Client.Field"." At D:tmpAddContentType.ps1:47
+ (cultureinfo)::CurrentUICulture = 'en-US'; $link.Field=$keyword
+                                            ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) (), SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting   Cannot convert argument "parameters", with value:
"Microsoft.SharePoint.Client.FieldLinkCreationInformation", for "Add"
to type "Microsof t.SharePoint.Client.FieldLinkCreationInformation":
"Cannot convert the
"Microsoft.SharePoint.Client.FieldLinkCreationInformation" value o f
type "Microsoft.SharePoint.Client.FieldLinkCreationInformation" to
type "Microsoft.SharePoint.Client.FieldLinkCreationInformation"." At
D:tmpAddContentType.ps1:51 char:1
+ $ct.FieldLinks.Add($link)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) (), MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

Examples found so far relate to adding website columns to the content type and not the list column.
Is there a way to add a list column to the list content type using PowerShell?

Thank you in advance.

How do I automate the SharePoint document library with a local folder using PowerShell or with another?

I want to create a solution where documents from the document library are automatically synchronized with the local folder. Not only can the synchronization be downloaded at the same time, but all changes made to the synchronized document should be uploaded back to SharePoint. I found only a few articles, but these speak of how to download them.

Is there any way to do this through PowerShell or with an onedrive API if available?

Powershell – Set-OrganizationConfing is not recognized, although I can get-OrganizationConfig

I'm trying to get the & # 39; Focused Inbox & # 39; set to disabled for the entire organization. I found a lot of scripts and tutorials online, most of which point to using the Exchange Online session in PowerShell.

e.g .:

My PS script is as follows:

# Set up Credential
$UserCredential = Get-Credential

# Create the Exchange Online session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

# Import the cmdlets into this session
Import-PSSession $Session -DisableNameChecking

# Get a list of the organisation's current settings

# Now set the 'Focused Inbox' option to 'off' for everyone
Set-OrganizationConfig -FocusedInboxOn $false

# Must remove the session to avoid clogging and clutter
Remove-PSSession $Session

The command & # 39; Get-OrganizationConfig & # 39; returns a complete list of the current configuration:

Enter the image description here

However, when I issue the & # 39; Set-OrganizationConfig & # 39; this fails with the following message:

Set-OrganizationConfig : The term 'Set-OrganizationConfig' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a 

Path has been included, check that the path is correct and try again.

Enter the image description here

I’m assuming it’s a permission issue, but I can see The entire configuration of the organization and the missing cmdlet.

What's the problem?

I am:

  • PS as & # 39; administrator & # 39; To run
  • Use the SharePointAdmin administrator account for credentials

SharePoint permissions via Powershell for Active Directory groups

I have the following folder structure in a SharePoint Document Center library:

 - Site A
  - Site AManagement
 - Site B
  - Site BManagement
 - Site C
  - Site CManagement

With the following Active Directory groups:

 - Access Site A Staff
 - Access Site A Management
 - Access Site B Staff
 - Access Site B Management
 - Access Site C Staff
 - Access Site C Management

Employee groups should have permission to read, create, write, and delete subfolders and files for their site, but not a vision of the management folder.

Management groups should have permission to read, create, write, and delete subfolders and files for their location, including the management folder.

All folders already exist together with the Active Directory groups, but can be deleted / recreated since they are not currently in a production environment.

Repeat this for about 700 locations.

console – Slow start of PowerShell via VPN

I'm having a problem with the PowerShell startup speeds that I've been doing some analysis on.

When I start my laptop, PowerShell starts perfectly (start time <1 second, including loading 1,000 line profiles). When I start my company VPN (Check Point EndPoint), PowerShell takes about 6.5 seconds to start (terrible).

So I pulled all of mine $profile Put functions etc in a separate file and put them on C:Profile_Extras.ps1 to avoid getting into the network in any way (except the $Profile, but that's just one line that points to mine C:Profile_Extras.ps1 File).

PowerShell now takes 3.5 seconds to start. A big improvement, but still very bad, to open a console session (!) On a very fast / modern laptop.

cd $(Split-Path $Profile) brings me to:
Microsoft.PowerShell.CoreFileSystem::\ DocumentsWindowsPowerShell

When I leave the company VPN network, this data is still available (some kind of caching software is used so that I can refer to my network profile at H:). In this state, reloading PowerShell takes <1 second, which is good.

So my question is how can I tell PowerShell to redirect where to look for $ profiles. Is that a registry setting or something?

I also looked at a few other articles, but no help. Why is Powershell slow on my computer?

Powershell – Install optional Windows features in offline mode

How can optional Windows functions be installed on a server without internet access?

Enable-WindowsOptionalFeature -Online -FeatureName "IIS-IPSecurity" -All

This works well with most features as I assume they are packed (but not enabled) with Windows Server 2016 (default). In particular, two functions cannot be installed because the server is not connected to the Internet:

Enable-WindowsOptionalFeature : The source files could not be found. 
Use the "Source" option to specify the location of the files that are 
required to restore the feature. For more information on specifying a source 
location, see
At line:1 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName "IIS-NetFxExtensib ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) (Enable-WindowsOptionalFeature), COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand

The error mentions that the -Source option is used to possibly indicate a local source. In the linked documentation, however, I can find no indication of how these source files are obtained individually for the installation.

Are these files available? Or do I have to create an image to use it with DISM?

Windows – Powershell cannot access packages / "NuGet" package providers after the security configuration has been updated

I upgraded a server with a mof / dsc configuration and essentially changed various permissions / registry keys to ensure security. To a certain extent, this was generated automatically. I have a list of all the items configured, but it is a little difficult to read and not very clear.

After the process, Powershell cannot update new packages or set the default repository.

I don't think this is anything specific to NuGet, and my guess is that it's related to some more basic file permissions. From what I can say, NuGet is installed on my system. I know it was installed before applying this configuration and the form I can say was not removed.

I checked a working server twice and the authorization for the NuGet DLL looks the same.

Here is an example of an error:

PS C:Windowssystem32> Register-PSRepository -Default
PackageManagementImport-PackageProvider : No match was found for the specified search criteria and provider name
'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
At C:Program FilesWindowsPowerShellModulesPowerShellGet1.0.0.1PSModule.psm1:7302 char:25
+ ...     $null = PackageManagementImport-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) (Import-PackageProvider), Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:Program FilesPackageManagementProviderAssemblies' or
'C:UsersopcAppDataLocalPackageManagementProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion -Force'. Do you want PowerShellGet to install and import
 the NuGet provider now?
(Y) Yes  (N) No  (S) Suspend  (?) Help (default is "Y"): Y
PackageManagementInstall-PackageProvider : Unable to find repository with SourceLocation ''. Use Get-PSRepository to
see all available repositories.
At C:Program FilesWindowsPowerShellModulesPowerShellGet1.0.0.1PSModule.psm1:7405 char:21
+ ...     $null = PackageManagementInstall-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) (Install-Pac
   kageProvider), Exception
    + FullyQualifiedErrorId : RegisterPackageSourceRequired,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPack

PackageManagementImport-PackageProvider : No match was found for the specified search criteria and provider name
'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
At C:Program FilesWindowsPowerShellModulesPowerShellGet1.0.0.1PSModule.psm1:7411 char:21
+ ...     $null = PackageManagementImport-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) (Import-PackageProvider), Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv

PackageManagementGet-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try
'Get-PackageProvider -ListAvailable'.
At C:Program FilesWindowsPowerShellModulesPowerShellGet1.0.0.1PSModule.psm1:7415 char:30
+ ... tProvider = PackageManagementGet-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) (Get-PackageProvi
   der), Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka

Register-PSRepository : NuGet provider is required to interact with NuGet-based repositories. Please ensure that
'' or newer version of NuGet provider is installed.
At line:1 char:1
+ Register-PSRepository -Default
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) (Register-PSRepository), InvalidOperationException
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Register-PSRepository

Package provider on a working system:

PS C:Windowssystem32> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
msi                      AdditionalArguments
NuGet                  Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 IncludeWindowsInstaller, IncludeSystemComponent

Parcel provider on a defective system (note, Nuget is no longer capitalized, odd, the directory for "NuGet" is also written in lower case, not sure whether this is relevant:

PS C:Windowssystem32> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------

NuGet package files (indeed, DLL is here, I tried to replace it with the DLL from a working system, to no avail)

PS C:Windowssystem32> gci -Recurse -Filter "nuget" -Directory -ErrorAction SilentlyContinue -Path "C:"

    Directory: C:Program FilesPackageManagementProviderAssemblies

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        2/10/2020   5:03 PM                nuget

Command Line – How do I create and assign persistent global system-wide variables like $ Home in Powershell?

I'm just starting to learn powershell and one thing is getting annoying.

The undesirable and unfair distinction between $env:Home and $HOME, While $ HOME can be completed automatically by entering $ hom> Tab, we have to enter $ env: Ho> Tab for the counterpart.

I have the idea that $HOME This is a kind of global variable that persists in every powershell session even after the system is restarted.

So the question: How do I create such persistent and global variables and assign values ​​either from the command output or the environment variable output or the direct path of the directory / file?