Sitecore download media folder with powershell - powershell

I have a requirement to remove several PDFs from specific folder our Sitecore media library, possibly over 1000 documents. We need to maintain the file names of these PDFs and would prefer to maintain the "file structure/hierarchy" of these documents.
We have tried using the Sitecore Powershell Extensions "Download" feature, but it does not appear to download the PDFs, only the content items themselves. We can create a package, but the folder that contains the resulting PDFs have had their file names replaced with GUIDs.
Is there a PS script available or any other way to do a bulk download of these media library PDFs?
P.S. I am a Powershell neophyte, so please be gentle.

Sounds like you need to use the Send-File command. When executed on a media library item, it allows you to download the associated blob stored in that item.
Example:
PS master:\>Get-Item "master:\media library\files\pdfs\mypdffile" | Send-File -Message "PDF Download"
You can pass -NoDialog to it so the user is not propmted each time.
So for multiple files you can do:
Get-Item -Path master -Query "/sitecore/#media library#/files//*[##templatename='Pdf']" |
Send-File -NoDialog
I can't see performance being great with 1000's of files for that tho. Also it will not keep the path, all files will be saved directly to your Downloads folder.

Perhaps you may be interested in using the download capability through SPE Remoting. This is an alternative solution that operates outside of Sitecore and connects through the web service.
Sample script for downloading:
https://github.com/SitecorePowerShell/Console/blob/master/Modules/Remoting%20Tests%20-%20Download%20with%20RemoteScriptCall.ps1
Book details on getting setup:
https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/content/remoting.html

Related

Backup a user's OneDrive for Business account using PowerShell

Our company is implementing a process where we automatically backup specific users' Exchange mailbox and OneDrive contents during the offboarding process.
My idea was pretty simple: using the cmdlets for the Compliance center to retrieve both and schedule deletion after an x period of time.
The problem is the e-mail backup is working perfectly, but for some reason OneDrive is not.
I created a test account with some e-mails in its mailbox and a added some files to its OneDrive, but for some reason it's only saving the mailbox contents.
Here's my code:
# For running on Azure runbooks
$Creds = Get-AutomationPSCredential -Name "testcred"
Connect-IPPSSession -Credential $Creds
New-ComplianceSearch -Name "test-name" -ExchangeLocation "test.user#company.com" -AllowNotFoundExchangeLocationsEnabled $true -SharePointLocation "https://company-my.sharepoint.com/personal/test_user_company_com/" | Start-ComplianceSearch
The search then pops up on https://compliance.microsoft.com/contentsearch and can be exported if necessary to access.
Problem is when I export it the contents of the OneDrive just simply don't show up even though in the compliance center it does seem to register the request for the site:
That's great, but then after extracting the contents to my PC no OneDrive contents come with:
The Exchange folder contains the .pst file with mailbox contents, but no OneDrive files to be found.
Am I missing something here?
Edit: I should mention we use a 100% cloud Office 365 environment.
Edit2: Just as an additional proof, here's the content inside the OneDrive in the preview section of the Compliance's Content Search:
I landed here when searching about another glitch on exporting Content Search OneDrive files.
Using Compliance Admin Center/Content Search I am able to export OneDrive files, but I have to explicitly set the user's URL (xxxx-my.sharepoint.com/personal/yyyy in my case).
(BTW, my problem is that the export has files with extensions such pdf_1E98101, msg_61c3b09 and so on... I am creating a question for this)

Looking to delete a folder from explorer via registry

I am looking to delete highlighted value from registry shown in Picture, where 'standard user' is the user id from which system is logged in. I need power shell script so that I can deploy it in every machine of my organization from backend and this highlighted value gets deleted from every user's system profile.
Assuming you are planning on doing this via GPO I would advise two steps:
1- Create the script file and add it to the Files preference on your GPMC
2- Create a one-time Scheduled Task and run the remote script.
This code should do what you want as long as you adapt the Path to your needs. It will get a list of the Values inside the Key you point it to and match it using the where-object.
(Get-Item -Path HKCU:\SOFTWARE\Microsoft\OneDrive\Accounts\Business1\Tenants\Intune Test').Property | Where-Object{$_ -match 'Test Sync - Documents'} | Remove-Item
Deployment is up to you, please assume this code can be improved and or adapted. This is just the core block you need to achieve what you asked.

Moving Document Library to a subsite in SharePoint

Currently, we have Document Libraries created in SharePoint Online and would like to move them using Powershell to its own Subsite. The reason we would like to move them is that we would like to keep the version history. Since we are dealing with 1000s of files, I would like to use Powershell to complete this task.
I am currently connecting to my SharePoint site using:
Connect-PnPOnline -Url "Sitename" -UseWebLogin
Here is where I need assistance. I am trying to use Move-PnPFolder but I am not sure how to write a command that would define the source, destination, and move of all files in the document library to a subsite that I have manually created.
Here you need to mix of PnP and CSOM PS script... the normal way how we get the SharePoint list items... we need read the the list items then inside the foreach loop you need to call the below command : Move-PnPFolder -Folder 'Shared Documents/Reports/2016/Templates' -TargetFolder 'Shared Documents/Reports' Something like below :
foreach ($oneFolder in List. Folders) { Move-PnPFolder -Folder 'Shared Documents/Reports/2016/Templates' -TargetFolder 'Shared Documents/Reports' }
Note :
In the above command from the $oneFolder property you will get the source folder URL and you already know the target folder location.
This is just sample code to present the concept.

Powershell script to "monitor" directory(s) for new files and move to new location(s)

I'm setting up a directory process for file signing by operators. These files need processing once signed so the next operator is aware of the previous process being complete.
Step 1. Initial file is created in X:\'operator name'\'Customer Name'
Step 2. Operator signed the file and places signed version in x:\'Operator name'\'Customer Name'\Signed
Step 3. An administrator will launch a batch file or script from their desktop that will move all files created in any X:\'Operator Name'\'Customer Name'\Signed folder into it's corresponding X:\'Customer Name' folder.
A list of operators will be maintained - probably in the batch file. This already exists in a central excel file.
All files will be .pdf
Each operator will have there own folder on X:\
Each operator has an infinite potential number of customer folders.
All operator and customer folders are created automatically in vb so naming will be identical.
Any help appreciated!
Thanks,
# Defines a list of operators. Must be identical to those in the main PDF operators table
$operatorlist = (
"Operator One",
"Operator Two",
"Operator three",
"Operator Four",
"Operator Five",
"Operator Six"
)
# Defining the variables
$nametoFind = "\Signed"
foreach ( $FTM in $operatorlist )
{
$sourceFolder = ( JOIN-PATH "X:\" $operatorlist )
#define the file to move
$FTM = Get-ChildItem $sourceFolder -Recurse | Where-Object {$_.PSIsContainer -and $_.Name.Endswith($nametoFind)}
$customerpath = Split-Path - Path $FTM -Parent -Resolve | Split-Path -Leaf
}
This response to too long to put in a comment. So, putting here:
Why not just use Windows FSRM (File System Resource Manager) service to do this vs scripting. It's a purpose built service to look at data files and take actions defined. You can look at content of a file and make decisions on what to do with them. Much of the info you'll find talks to Windows FCI (File Classification Infrastructure). Yet, nothing prevents you from using FSRM for this generic purpose. See this info:
Windows Server 2012 > Using File Server Resource Manager (FSRM) to Move Files Containing Sensitive Data
If you want to use PowerShell for this, then you'll look to Async FileSystemWatcher implementation. There are prebuilt scripts on the MS PowerShellGallery.com that can get you started. Download and use as is or refactor as needed for your use case.
Example(s):
Powershell FileSystemWatcher
This script uses the .net FileSystemWatcher class to subscribe to 'create', 'change' and 'delete' events on files or folders in the NTFS filesystem. It can be used to monitor a folder or folders, and can be modified to perform any action upon the triggering of these events.
Download : FileSystemWatcher.ps1
Monitor folder for file system events
.Synopsis
Monitors a folder for changes using non-persistent asynchronous events
.Description
A wrapper around IO.FileSystemWatcher and Register-ObjectEvent to monitor a folder for file system events (Created, Deleted, Changed, and/or Renamed)
Download : Monitor-Folder.ps1

Use Powershell to delete file from a folder set by windows registry value

Sorry if this has been answered before, I have tirelessly searched and cannot find the exact answer I am a Mac user and have not ventured into Windows registry before.
I am creating an installer for audio plugins and have a separate demo version of the titles. In the registry for the demo version, I have the entry
Demo=1
and also have paths set for various components of the plugins, which are optionally installed, these are stored in the registry as the user may install these into different directories depending on their host software
VST3=C:\Somepath\VST3
VST32=C\AnotherPath\VSTPlugins
VST64=C\AnotherPathAgain\VSTPlugins
I have found how to search the registry to check if Demo=1
$val = Get-ItemProperty -Path hklm:software\Audio Vitamins\Structure -Name “Demo”
if($val.Demo -eq 1)
{
**** This is where I need help *****
}
How do I set Powershell to remove a particular file 'structure.vst3' from the path set in VST3 or or 'structure.dll' from the paths set in VST32 and VST64. Note these can all be present or only 1 of them depending on the original install.
You have a couple of different paths (pun intended) you can take here.
You can organize your "demo = 1" files into one folder and the others in another and reference the demo folder location in the registry. Then you get the file location and use del to remove them. Much easier and doesn't require you to track which ones are there with unnecessary registry entries.
$demofolder = gp -path HKLM:\path\to\registry\key -Name "demofolder"
dir $demofolder -file|%{del $_ -force}