I am traying to copy files betwen SP Document Librarys, with PnP PowerShell command "Copy-PnPFile",
but I get "Copy-PnPFile : The remote server returned an error: (401) Unauthorized"
In the script before this comand I am reading, items, creating folder and it works, only Copy-PnPFile dont work.
Copy-PnPFile -SourceUrl $Item["FileRef"] -TargetUrl $TargetFileUrl
Make sure $Item["FileRef"] is a relative path. Of course $TargetFileUrl should also be a relative path.
Microsoft Official:
Copy-PnPFile:Copies a file or folder to a different location. This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant. Currently there is a 200MB file size limit for the file or folder to be copied. Notice that if copying between sites or to a subsite you cannot specify a target filename, only a folder name.
Here is a nice article for your referenceļ¼
SharePoint Online: Copy File Between Document Libraries using
PowerShell
My mistake.
In source and target relative path forgot to include "SiteCollectionURL".
Related
The Goal:
How to use .gitignore to exclude all folders & files except PowerShell $Profile?
The answer should help expand the current exception file list to more files in other subfolders. If possible, reduce wildcards to minimum, and use as specific as possible (full/fuller file path). Why? For instance, Book1.xlsx may exist in multiple subfolders but I want to be able to choose only the specific desired subfolders.
Thanks in advance!
Current status:
On Windows 10 (not Linux Distros):
git init initiated on top level directory C:\. [Please don't suggest to start from other subfolders. Just remain with C:\, as I will include more files to the exception list]
C:\.gitignore containing the below:
# Ignore All
/*
# Exception List [eg. PowerShell's $Profile (please use FULL/FULLER FILE PATH, if possible)]
!.gitignore
!Microsoft.PowerShell_profile.ps1
!Users/John/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1
!Users\John\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
!C:/Users/John/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1
!C:\Users\John\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
With the above codes, git status successfully returned only .gitignore as 1 untracked file. Microsoft.PowerShell_profile.ps1 remained missing from untrack listing.
I've tried alternative ways (wildcard, partial subfolder name with pattern, etc) but all failed to return the fuller file path PowerShell $Profile.
When running AZCopy command copy to get 2 pictures from a blob container/ folder, it results in a 404 blog not found. Error does not occur if I specify the filename (it downloads the folder structure with the file in it).
Tested 3 different versions of it the code but can not get a recursive version to work.
Example of not working
azcopy copy "https://bloburl.blob.core.windows.net/Container/Folder/*?SASKey" "C:\Users\MyFolder\Pictures"
azcopy copy "https://bloburl.blob.core.windows.net/Container/Folder?SASKey" "C:\Users\MyFolder\Pictures"
Example of working
azcopy copy "https://bloburl.blob.core.windows.net/Container/Folder/UNSC_Infinity.jpg?SASKey" "C:\Users\MyFolder\Pictures"
My goal is to download all files in the blob container/folder and not the structure itself.
SAS URI: https://s00aops01stg01blkbsa.blob.core.windows.net/5740-christianmimms?st=2019-06-03T17%3A09%3A34Z&se=2020-06-04T17%3A09%3A00Z&sp=rwl&sv=2018-03-28&sr=c&sig=3HyCaMQ1JCkb4Yof%2BOWExx8amHtPTmZHpEZbZPX8Iqs%3D
SAS URI w/Folder: https://s00aops01stg01blkbsa.blob.core.windows.net/5740-christianmimms/images/*?st=2019-06-03T17%3A09%3A34Z&se=2020-06-04T17%3A09%3A00Z&sp=rwl&sv=2018-03-28&sr=c&sig=3HyCaMQ1JCkb4Yof%2BOWExx8amHtPTmZHpEZbZPX8Iqs%3D
May I please get your insight?
I have a user group in AD call Contract Admin. I like would this user group to be able to run a script that clones a template folder (retaining permissions) to a new folder and prompt for a new client name.
The folder structure would be as follows:
Clients
New Folder (template folder) (Permissions: Admins, Contract Admin, Financial Admin)
Statements Folder (Permissions: Financial Admin)
End result after script:
Clients
ABC Company (Permissions: Admins, Contract Admin, Financial Admin)
Statements Folder (Permissions: Financial Admin)
Above is an example of the folder structure where New Folder is the template folder which also has a folder inside of it as well. I'd like to have the folders cloned with permissions retained.
I hope this is clear, I apologize if it is not. Thank you so much for your help.
The code I currently have for copying the permissions are as folows:
robocopy /e /copy:DATS "X:\Template" "X:\New Folder Name"
attrib -h "Template"
This is what I have for cloning the folders but I am lost from here.
Thank you
Solution:
#echo off
set "src=C:\Users\XXX\Desktop\template folder"
set /p "dest=Name of Client?: "
robocopy /e /copy:DATS %src% %dest%
the source can simply be the folder/file name without the full path if both the script and the folder/file to be copied is in the same directory.
/copy: Specifies the file properties to be copied. The following are the valid values for this option:
D Data A Attributes
T Time stamps S NTFS access control list (ACL)
O Owner information
U Auditing information
The default value for
CopyFlags is DAT (data, attributes, and time stamps).
But this is not a script. It's a robocopy command.
There are many switches robocopy, see its help file for them.
Specifically the mirror (/MIR) a folder tree to a new location.
As for prompting users, there are a few ways to do this. The most direct is Read-Host cmdlet provides. You simply capture that in a variable and pass that as the folder.
$FolderPath = Read-Host 'Enter a folder path.'
I'm creating a script to automatically copy and paste bookmarks to x amount of computers.
Robocopy the Mozilla Bookmarks which are stored in a file called places.sqlite on a drive. To the destination
Appdata\Roaming\Mozilla\Firefox\Profiles\\*RANDOM PROFILE NAME\places.sqlite
I can't find a solution to copy this file to the destination due to every windows profile and computer gets a random profile name created. I tried with a star * as you can see in the code because I thought a star choices the newest folder (last changed).
The code is:
$env:homeshare
$env:username
Robocopy "$env:homeshare\ComputerChange\" "C:\Users\$env:username\AppData\Roaming\Mozilla\Firefox\Profiles\*\" "places.sqlite" /COPY:DAT
How do I edit the code so it chooses the random named folder? Is it possible to copy the places.sqlite to ALL folder in the Profiles\ folder?
Appreciate the help
I want to check the existence of file which is present on shared location using powershell command.
I am using below query,which is giving wrong result for shared folder.
Test-Path " \computer\Software\aaa.txt"
Please help me to sort out the issue..