Is it possible to delete files older than x days in a sharepoint folder using powershell?

I am looking to run a script every night to delete zip files older than 7 days. In Documents I have a folder called folder1 and inside that folder there are subfolders that contain zip files. I have seen examples of sites / lists but not folders. The following cold will return:

But I would like to recursively delete all zip files in folder1 that are older than 7 days.

Try {
   #Setup the context
   $securePassword = ConvertTo-SecureString $SPOnlinePassword -AsPlainText -Force
   $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) 
   $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($SPOnlineUserName, $securePassword)

   #Get the List
   $List = $Context.Web.lists.GetByTitle($ListName)

   #Define CAML Query to Filter
   $Query = New-Object Microsoft.SharePoint.Client.CamlQuery
   $Query.ViewXML = "
                        
                            
                                
                                    
                                        .zip
                                    
                                    
                                        
                                        
                                            
                                        
                                    
                                
                            
                        
                    "

   #Get List Items
   $ListItems = $List.GetItems($Query)
   $Context.Load($ListItems)
   $Context.ExecuteQuery()

   Write-host -f Green "Number of List Items Found:"$ListItems.Count
   write-host $ListItems.Name
   #Get Each Item's Created Date
   $ListItems | ForEach-Object { Write-host ("List Item:{0} was created on {1}" -f $_("FileLeafRef"), $_("Created")) }

   foreach ($item in $ListItems) {
      $List.getItemById($item.id).deleteObject()
   }
   $Context.ExecuteQuery()
}
Catch {
   write-host -f Red "Error:" $_.Exception.Message
}

Edit: I have the above code working until I received & # 39; Error: Exception calling "ExecuteQuery" with "0" argument (s): "The operation has timed out".

sharepoint server – Powershell to move files from one library to another – SP2010

In SP2010, I am trying to move all files from one library to another using Powershell.

I am using the following script to first copy the source files to destination and then delete the source file.

But the script shows an error after the first file is moved to the destination and then removed from the source. I understand that the script cannot go back to the foreach loop after processing the first file, I tried different ways but nothing worked.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Custom Function to Copy Files from Source Folder to Target
Function Copy-Files($SourceFolder, $TargetFolder)
 {
write-host "Copying Files from:$($SourceFolder.URL) to $($TargetFolder.URL)"
#Get Each File from the Source
$SourceFilesColl = $SourceFolder.Files

#Iterate through each item from the source
Foreach($SourceFile in $SourceFilesColl)
{
    #Copy File from the Source
    $NewFile = $TargetFolder.Files.Add($SourceFile.Name, $SourceFile.OpenBinary(),$True)

    #Copy Meta-Data from Source
    Foreach($Field in $SourceFile.Item.Fields)
    {
        If(!$Field.ReadOnlyField)
        {
            if($NewFile.Item.Fields.ContainsField($Field.InternalName))
            {
                $NewFile.Item($Field.InternalName) = $SourceFile.Item($Field.InternalName)
            }
        }
    }
    #Update
    $NewFile.Item.UpdateOverwriteVersion()
    Write-host "Copied File:"$SourceFile.Name

   $SourceFile.Delete()
   Write-host "Deleted File from source:"$SourceFile.Name 
   }
   }
   #Variables for Processing
   $WebURL="http://SiteURL"
   $SourceLibrary ="Team Docs"  
   $TargetLibrary = "Sales Documents"

   #Get Objects
   $Web = Get-SPWeb $WebURL
   $SourceFolder = $Web.GetFolder($SourceLibrary)
   $TargetFolder = $Web.GetFolder($TargetLibrary)

   #Call the Function to Copy All Files
   Copy-Files $SourceFolder $TargetFolder

SP2010 Powershell error:

enter the image description here

Power Automatize: pass Powershell JSON parameters to Flow enabled

Background: I have a PowerShell code used to create team sites based on a list column trigger. This works fine

I am also implementing a site design / script that includes a flow trigger.

I have been able to activate my flow but now I want to pass a parameter which is fetched from PowerShell and pass it to the flow. In this case, the parameter is a list item (email) value that I want to use in the flow to send an email to the user when the group site is created and the site layout / script is applied.

The PS json allocation code looks like the following. I added a parameter (testparm) in the json schema presumably to pass it to the Flow JSON code. It didn't work and I thought it didn't, but I tried it anyway. I hope to be near.

$MySiteScript = '
 {
     "$schema": "schema.json",
         "actions": (
             {
          "verb": "triggerFlow",
          "url": "https://prod-103.westus.logic.azure.com:443/workflows/e81c605fcfc64a24a82e6e697cb19750/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=S3Kf8TtbbWzoP6TDuUIKH6CwY5L_TV_HyRtbgdZVMyI",
          "name": "Record and tweet site creation event",
          "parameters": {
            "event": "Microsoft Event",
            "product": "SharePoint",
            "TestParm": "MyTestParm",
          }
        }


         ),
             "bindata": { },
     "version": 1
 }
 '

The Power Automate (FLOW) component looks like this.

enter the image description here

run batch file as administrator in powershell

I have a batch file. how to run it using powershell and in administrator mode. I can encrypt the credentials. I tried

(string) (ValidateNotNullOrEmpty ()) $ txts = "password"
$ usr = "admin user"
$ sec = ConvertTo-SecureString -String $ txts -AsPlainText -Force
$ mycreds = New-Object Management.Automation.PSCredential ($ usr, $ sec)
Start-Process powershell.exe -Credential $ mycreds C: test batfiles mybat.bat

2013 – SharePoint Powershell Search: header / footer search or job search that appears more than once

So I've been trying to investigate this, but still haven't been able to find an answer.

I am required to search all "unofficial" documents on our website. This tag is normally used in the header or footer. Unfortunately, we have not been using Metadata to capture this information, therefore I want to do a search to be able to add metadata (classifications) to documents.

I'm looking for a way to complete a SharePoint 2013 search using Power Shell, but I just want to display the results of the keyword found in the header / footer of a document or if that keyword appears more than 2 times in the document.

IE: I want to find all the documents that contain "unofficial" in the document header or footer. If this cannot be accomplished then I need to show all results where "unofficial" appears at least twice in the document.

I hope what I'm trying to accomplish makes sense.

active directory – Script Powershell: Set-ADUser -clear with multiple variable attributes

I want to delete various attributes by using variables in Powershell script (version 5.1.17763.1007)

It's work :

Set-ADUser -Identity $($user.SID) -Clear Initials,info

It is also work:

$emptyParams='Initials'
Set-ADUser -Identity $($user.SID) -Clear $emptyParams

It is not work:

$emptyParams='Initials,info'
Set-ADUser -Identity $($user.SID) -Clear $emptyParams

and show:

Set-ADUser: The specified directory service attribute or value does not exist
Parameter name: initials, information
In Set-ADUserDesc.ps1: 32 char: 9
+ Set-ADUser -Identity $ ($ user.SID) -Clear $ emptyParams
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
+ CategoryInfo: Invalid argument: (S-1-5-21-414636 … 1575523350-2106: ADUser) (Set-ADUser), ArgumentException
+ FullyQualifiedErrorId: ActiveDirectoryCmdlet: System.ArgumentException, Microsoft.ActiveDirectory.Management.Commands.SetADUser

Can you explain why?

Sincerely,

pnp: Set-PnPTraceLog with Azure PowerShell function

There are many posts on how to use PnP with Azure PowerShell function

below are some links

https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-pnp-provisioning
https://www.youtube.com/watch?v=plS_1BsQAto&t=925s

But when we work with large projects, problem solving is a great aspect.

For troubleshooting, I mainly use the Set-PnPTraceLog command to see what happens, but when I use the same command nothing is displayed on the screen. Is some PnP PowerShell working to support Azure feature? or am I doing something wrong?

Below is the command I am using

Set-PnPTraceLog -On -Level Debug

powershell: assign multiple words as input to CSV file without quotes

I am running the following script to add users to SharePoint group on SPO sites:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$users= "" 
$users = import-csv D:User.csv
foreach ($user in $users)
{
$groupname=$user.group
Add-SPOUser -Site $user.SiteURL -LoginName $user.UserEmailAddress -Group $groupname
Write-host "User added:" $user.SiteURL $groupname $user.UserEmailAddress
}

The entry, namely UserEmailAddress, SiteURL and Group, is obtained from a csv file.

This script works fine if the group name is a single word without any spaces like Approvers, SiteOwners but if the group name has 2 or more words with spaces between them, the script displays the error "Cannot find group"

I understood the problem and tried different approaches to fix it, but nothing works.

How to identify actual PowerShell command in Windows 10 from Task Manager?

I have a well used quad core developer machine with Windows 10 that has seen some software come in and out. Being a Java developer, I am not that familiar with Windows 10, but I have local administrator rights.

Now I have a PowerShell command that Task Manager reports running at 25% on a regular basis, which makes my fans run continuously, and Task Manager is, as far as I can see, it can only tell me about the PowerShell binary, but not the In this context, it is running where I think it would help me identify which product invokes PowerShell and whether it is legitimate or a leftover from a software installation that is not removed entirely.

Is there a way to get better insights from running work that can help me understand what you're doing?

powershell: force Windows to install * all * missing updates

When I miss at least one cumulative update on one of my Windows 10 or Windows Server 2019 installations, I often get the situation that after apparently installing all pending updates and restarting first, the Windows Update GUI says the system is up to date , but as soon as Click the Check for Updates button to find lots of additional updates. I can install them right away with no problems, but that's really annoying and time consuming and also requires a second reboot right after the first …

Is there a way to force Windows to search for all missing updates directly and force it to install them all at once?

Pressing the Check for Updates button manually at the beginning (if available) or wuauclt.exe /detectnow it doesn't cut it but maybe there is a way with PowerShell or something similar?

(I suppose this is already answered somewhere, but searching for it really seems difficult since many other Windows Update topics appear. But I'd also appreciate any link or reference.)