powershell – Is there any way to atomate this process?

I’m not sure if there even is a way to automate this, but basically, I would like something that could:

  1. Go to “G:filesclientClient X” and check if there is a .PDF named “received” there;
  2. a] tell me if there is no such .PDF there at step 5.
  3. b] if there is, id like it to check the .PDF for key words like “month, year, client ID, VALID, INVALID”
  4. then move on to the next client in the established order
  5. make a list with what it found

so basically im looking for something that can make a list

So is there any way to automate this process?

powershell – Windows Linux Subsystem Binary Priorities vs Windows Path

Preface: Some of these statements are made based on my current understanding of how things are working. If they are wrong, feel free to correct me.

A number of binaries in PowerShell reference those in the WSL. For example…

PS C:UsersUsername> which which

PS C:UsersUsername> which ls

If we have a windows binary with the same name, even if the binary is at the top of the Windows PATH the WSL version will still take priority. My question is, how can we adjust this priority (much like lowering the binary’s folder in the Windows PATH) or otherwise alter which binary is being called?

Sharepoint Online: Get List Items from Documents List with over 5000 Items using Powershell

My goal is to create a powershell script that will change the created by value in my Sharepoint online documents list. Fyi this list contains 10005 items.

I’m at the very beggining and already stuck because of this error:

Exception calling “ExecuteQuery” with “0” argument(s): “The attempted operation is
prohibited because it exceeds the list view threshold enforced by the administrator.”

Here is my script:

##Variables for Processing
$SiteUrl = "https://xyz.sharepoint.com/sites/xyz"
$UserName ="user@xyz.com"
$Password ="xyz"
$ListName ="Documents"

#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Setup the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $Credentials

#Get the list (documents)
$Web = $context.Web
$documentsList = $Web.Lists.GetByTitle($ListName)

#Get All List items
$ListItems = $documentsList.GetItems((Microsoft.SharePoint.Client.CamlQuery)::CreateAllItemsQuery()) 

Write-host "Total Number of List Items found:"$ListItems.count

I want to loop through the list items and change the created by value.

How do you get around the 5000 item limit in this case?

Thank you.

Powershell GUI – not calling sub batch file

I have one question regarding my powershell script with gui. When compiled as an .exe (with PS2GUI with noConsole) it works properly, but when calling this same .exe from a .bat file it does not work. It does not start the Start-Process batch file below. The Problem is, that I cannot call the .exe file directly from a Eclipse based lauchner, that is why we need a .bat file for it to be launched. I have tried it with the following commands in the batch file: start script.exe

I have tried calling the .ps1 script directly, however the refresh timer does not work and also the checks if the application & sub batchfiles is already running do not work… Any clue on how to make those things work properly?

Here my code:

#Date format for Logfile
$heute = Get-Date -UFormat %d_%m_%Y_%R
$LogFile = "c:tempoutput.txt"
$TempLocation = "c:tempstartscript"

#Kill already started startscript
Get-Process -Name noconsole_exe | where { $_.Id -ne $PID } | Stop-Process
#Kill already started project.bat
$fltr = "name like '%cmd.exe%' and commandline like '%project.bat%'"
(Get-WmiObject Win32_Process -Filter $fltr).Terminate()

# Percentage
Function get-count{
    $Percent.text = (gci $TempLocation).count * 10

        $timer1 = New-Object System.Windows.Forms.Timer
        $timer1.Enabled = $true
        $timer1.Interval = 100



#GUI Form    
Add-Type -AssemblyName System.Windows.Forms

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '600,200'
$Form.text                       = "Start"
$Form.BackColor                  = "#ffffff"
$Form.TopMost                    = $false
$Form.startposition = "centerscreen"        
$Form.icon                       = "c:startscriptsstartscript.ico"                            

$Label1                          = New-Object system.Windows.Forms.Label
$Label1.text                     = "Program is starting, please wait."
$Label1.AutoSize                 = $true
$Label1.width                    = 25
$Label1.height                   = 10
$Label1.location                 = New-Object System.Drawing.Point(131,28)
$Label1.Font                     = 'Microsoft Sans Serif,16'

$Label2                          = New-Object system.Windows.Forms.Label
$Label2.text                     = "Please include the log below"
$Label2.AutoSize                 = $true
$Label2.width                    = 25
$Label2.height                   = 10
$Label2.location                 = New-Object System.Drawing.Point(50,109)
$Label2.Font                     = 'Microsoft Sans Serif,10'

$ToolTip1                        = New-Object system.Windows.Forms.ToolTip
$ToolTip1.ToolTipTitle           = "Log File Location: c:tempoutput.txt"

$Button2                         = New-Object system.Windows.Forms.Button
$Button2.text                    = "Send Log via E-Mail"
$Button2.width                   = 173
$Button2.height                  = 30
$Button2.location                = New-Object System.Drawing.Point(210,142)
$Button2.Font                    = 'Microsoft Sans Serif,10'

$ToolTip2                        = New-Object system.Windows.Forms.ToolTip
$ToolTip2.ToolTipTitle           = "Send Log via E-Mail"

$Label3                          = New-Object system.Windows.Forms.Label
$Label3.text                     = "%"
$Label3.AutoSize                 = $true
$Label3.width                    = 25
$Label3.height                   = 10
$Label3.location                 = New-Object System.Drawing.Point(317,61)
$Label3.Font                     = 'Microsoft Sans Serif,16'

$Percent                         = New-Object system.Windows.Forms.Label
$Percent.Text                    = (gci $TempLocation).count * 10
$Percent.AutoSize                = $true
$Percent.width                   = 30
$Percent.height                  = 12
$Percent.location                = New-Object System.Drawing.Point(276,61)
$Percent.Font                    = 'Microsoft Sans Serif,16'

$ToolTip2.SetToolTip($Button2,'Opens Outlook with the log file. Please include also a screenshot of an error message and send the e-mail.')

$Button2.Add_Click({ OpenMailLog })

function OpenLog {
    Start-Process notepad $LogFile }

function append-text { 
   foreach-object {$_ + "%0d%0a"}

function OpenMailLog { 
Copy-Item "c:tempoutput.txt" -Destination "c:tempoutput_4_mail.txt"

$MailText = Get-Content -path c:tempoutput.txt
$MailText | append-text | out-file "c:tempoutput_4_mail.txt"
$AntiText = Get-Content -path c:tempoutput_4_mail.txt

$Output = @()
#Add new text
$Output += "Dear Mr.X,%0d%0ahere is the log file output.%0d%0a%0d%0a"
#Append old text from content
$Output += $AntiText
$Output | Out-file "c:tempoutput_4_mail.txt"
$BodyText = Get-Content -path c:tempoutput_4_mail.txt
Start-Process "mailto:example@acme.com?Subject=Log file&Body=$BodyText"
Start-Process -FilePath "c:startscriptsproject.bat" -RedirectStandardOutput "$LogFile" -WindowStyle Hidden

Thanks for the help!

sharepoint online – Convert the Powershell script to Python 3

I’m trying to perform an upload files from Linux to share point using Python. However I tried a lot by googling but nothing help. At last I got a power shell script that is working. So requesting for help to convert the below script to Python 3

Specify tenant admin and site URL
$User = "justin.jacob@spidersoft.in"
$SiteURL = "https://test-my.sharepoint.com/personal/justin_jacob_spidersoftin";

$Folder = "C:Usersjustin.jacobDesktopNew folder"
$DocLibName = "Documents"

#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"

$Password  = ConvertTo-SecureString ‘123@123’ -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")



#Upload file
Foreach ($File in (dir $Folder -File))
$FileStream = New-Object IO.FileStream($File.FullName,(System.IO.FileMode)::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $File
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)

regex – Set string from another file as variable in Powershell

I have this text file contains the following line


How do I iterate the value of those string in a powershell script to print match string? If manually assign variable I will do it something like this

get-content data.csv -ReadCount 1000 | foreach { $_ -match "group1" } | Out-File name1.txt -encoding Utf8

powershell – Set-SPOSite not working for Group enabled SharePoint Online sites

I’m executing the below script to disable one of the document sharing options:

set-sposite -Identity “https://tenant.sharepoint.com/sites/useraccessmanagement” -DisableCompanyWideSharingLinks Disabled

This script is displaying the below error for all Group enabled SharePoint Online sites but for other sites, it is working as expected.

Error Screenshot and Error Text:

enter image description here

set-sposite :
https://tenant.sharepoint.com/sites/UserAccessManagement is a
Groups site collection. The valid parameters for this type of site
collection are ‘-Identity’, ‘-AllowSelfServiceUpgrade’,
‘-DefaultLinkPermission’, ‘-DefaultSharingLinkType’,
‘-DenyAddAndCustomizePages’, ‘-DisableCompanyWideSharingLinks’,
‘-DisableSharingForNonOwners’, ‘-LockState’, ‘-Owner’,
‘-ResourceQuota’, ‘-ResourceQuotaWarningLevel’,
‘-SandboxedCodeActivationCapability’, ‘-SharingCapability’,
‘-SocialBarOnSitePagesDisabled’, ‘-StorageQuota’,
‘-StorageQuotaReset’, and ‘-StorageQuotaWarningLevel’. At line:1
+ set-sposite -Identity “https://tenant.sharepoint.com/sites/useraccessmanageme …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) (Set-SPOSite), ServerException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.SetSite

pnp powershell – Trigger re-index of part of a document library or files of a certain extension in Sharepoint Online

I have a gargantuan set of document libraries that each contain a folder with msg files. I set a few managed properties specifically for the folders with msg files in order to make a custom filter for these properties in a search center. The search and filters work, but only newly entered msg files are being picked up. The formerly entered msg file properties are not present in the new managed property indexes which were only recently mapped. I want to trigger a crawl of just these subfolders, which all have the same name and are nested inside larger document libraries. Is there a way to do this using PnP? I already tried using Request-PnPReindexList -Identity “list/sublist”. There was not an error, but it has been over 24 hours and the list has not been indexed.

I also tried reindexing one of the entire document libraries using the SP front end Library advanced settings > reindex library. It has been about three days and it has not been reindexed yet. My preference would be to set reindex for only the msg file subfolders so as not to overwhelm the system, which has many terabytes of documents divided into dozens of libraries. Thanks in advance for any advice you can provide.

access – Remove anonymous link from SharePoint thanks to PowerShell

I am currently working on a script that should remove an anonymous link from SharePoint using Powershell.
I don’t know where to start and i would like to know if somebody has an idea on how to do it.

The goal of the script is that we should remove entirely a link, i know microsoft can remvove the access after a few day but the link still exists it is just expired. I would like to destroy this link in order to be able to create another one

thanks in advance 🙂