sharepoint online – Fetch an image from a SitePage using PowerShell

As far as I know, there is no PowerShell cmdlet to get images from site pages.

The images on site pages are stored in the picture libraries, Site Assets library, personal OneDrive folder or external website (Stock), depending on how they are inserted on the page. If the employee pictures are all uploaded from local drives, you should be able to find them in the folder SiteAssets/SitePages/<pagename> and download them easily.

Or you can use other methods like REST API to get contents from the site page (or the folder as mentioned).
Sample reference: Download and upload file from share point using Java (Rest API call).

ssl – Powershell self-signed certifcate private key not exportable

Using Powershell, I’m attempting to create a self-signed ssl certificate with a private key that can be exported. I’ve read and followed various tutorials, however the end result is always that no private is exported. I’m using Powershell because the server is running Windows Server 2016 Core edition. I’ve tried using the Certificate MMC console from a remote computer, however it appears not all functionality is available when doing that remotely. In any case, the various tutorials I’ve follow speak about the ability to export the private key, however I have yet to find a concrete example of the code which makes this work. Here is the code I have been trying:

$todaydt = Get-Date
$5years = $todaydt.AddYears(5)
$selfSignedRootCA = New-SelfSignedCertificate -DnsName SelfSignedRootCA -notafter $5years -CertStoreLocation Cert:LocalMachineMy -KeyExportPolicy Exportable -KeyUsage CertSign,CRLSign,DigitalSignature -KeySpec KeyExchange -KeyLength 2048 -KeyUsageProperty All -KeyAlgorithm 'RSA' -HashAlgorithm 'SHA256' -Provider 'Microsoft Enhanced RSA and AES Cryptographic Provider'
New-SelfSignedCertificate -CertStoreLocation cert:LocalMachineMy -DnsName "myserver.test" -notafter $5years -Signer $selfSignedRootCA -KeyUsage KeyEncipherment,DigitalSignature
$CertPassword = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText
Export-PfxCertificate -Cert cert:LocalMachineMyREDACTED-THUMBPRINT -FilePath C:test.pfx -Password $CertPassword

My research suggests that the most common reason for this is that the certificate template used in creating the certificate does not allow the private key to be exported, so following these suggestions I’ve copied an existing Certificate Template and ensured that it is configured to allow exporting the key. But, then I don’t know how/where to specify that newly-created template in any of the above commands. And my review of the documentation for these cmdlets does not show any parameter for doing so. Really stuck on this so any advice is much appreciated.

powershell – Add and delete Sharepoint Groups from site

Thanks for you time reading this.
We are a Technical School that’s using Sharepoint 365 as way to collect files and resources. We have to open a Sharepoint to each class and I’m compiling a Powershell script to be easier…
When added a Site lets say “Class.ABC”, the system also creates a group called “ClassABC@acme.org” (without the dot) and through the script I add the students to the group. I’m using PNP.Powershell. One example:

Add-UnifiedGroupLinks –Identity "ClassABC@acme.org" –LinkType "Members" –Links "Student.19912@acme.org"

The problem is this group “ClassABC@acme.org” is put in the “Members” group of the site by default, and therefore with contribute permissions. I want to change this group to “Visitors” of the site.

I’ve try this:

Add-PnPGroupMember -LoginName "ClassABC@acme.orgt" -Identity "Visitors of Class.ABC"
Remove-PnPGroupMember -LoginName "ClassABC@acme.org" -Identity "Members of Class.ABC"

But it didn’t work as they work only with users not groups!

Is there any way to accomplish this?

Thanks a lot for your kind help. I’m not very good at Powershell, so please be gentle! 😉

syntax – Powershell : Update Registry value for RDPFileContent by making change in server port to XXX from XXX

Requirement: to update registry value i.e. server port for one of the property : RDPFileContent using powershell.

Attempt Taken: Tried fetching entire value first of RDPFileContent using get-childitem method and redirected the content to text file and replaced only server port value using replace parameter. But, while setting it back using set-item property, we are not able to set back in proper format by extracting it from updated text file.

Please help us here .

Thanks in advance,

macos – With PowerShell set iTerm2 tab title

I’m using PowerShell as my shell with iTerm2 on macOS.

I know it’s possible on bash and zsh but running the recommended solution doesn’t work in powershell, because the ANSI escape doesn’t work:

PS ~> echo -ne "33]1;Title07"
-ne
33]1;Title07
PS ~>

It should be possible to shell out to i.e. zsh from powershell to use these ANSI escapes, but I’d like a PowerShell-native solution.

Powershell – Script for making Inventory of fileserver drives before migration to Sharepoint

I’m a powershell beginner and I would like to write a script to create a complete inventory of our fileserver.
I tried it with –> Get-ChildItem -Path X -Force -Recurse | Export-Csv -Path X -Encoding ASCII -NoTypeInformation , but I get all the time errors.
Any tips please ?

Thanks a lot

powershell – Trying to revoke locally-generated certificate : No local CA error

For some automated tests on my project, I need to revoke a certificate which has been generated locally by makecert.exe.

First, I generate a signer certificate and associated CRL using the following commands, and use certutil to install them to my machine

# Generate Signer Cert
makecert.exe -pe -n CN=SignerCert -r -sr LocalMachine -ss Root -a sha256 `
    SignerCert.cer -cy authority
certutil -installcert SignerCert.cer

# Set up a certificate revocation list for the CA cert above
makecert.exe -crl -n CN=SignerCert -r -sr LocalMachine SignerCert.crl
certutil -addstore Root SignerCert.crl

I then generate another cert for authentication, the one I would eventually like to revoke

makecert.exe -pe -n CN=AuthCert `
    -ir LocalMachine -is Root -ic SignerCert.cer `
    -sr LocalMachine -ss My -a sha256 AuthCert.cer

and install it as follows (via some powershell)

    $x509cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
    $certPath = Join-Path $pwd AuthCert.cer
    $x509cert.Import("$($certPath)")
    Set-Location "Cert:LocalMachineMy"
    $cert = Get-ChildItem | Where-Object { $_.Thumbprint -eq $x509cert.Thumbprint}
    $cert = $cert(0)
    $cert.FriendlyName = $FriendlyName

So far so good. If I pull up certlm on my machine, I can see both SignerCert and AuthCert under “Personal > Certificates”, SignerCert under “Trusted Root Certification Authorities > Certificates”, and SignerCert under “Trusted Root Certification Authorities > Certificate Revocation Lists”.

Now for the problematic operation. I would like to revoke AuthCert: certutil has a -revoke operation which I could use, so let’s say I retrieve AuthCert’s serial number and run the following command

> certutil -revoke 12345678
Revoking 12345678 -- Reason: Unspecified
ICertAdmin::RevokeCertificate: The RPC server is unavailable. 0x800706ba (WIN32: 1722 RPC_S_SERVER_UNAVAILABLE)
CertUtil: -revoke command FAILED: 0x800706ba (WIN32: 1722 RPC_S_SERVER_UNAVAILABLE)
CertUtil: The RPC server is unavailable.

The RPC’s probably unavailable because there’s no local CA

> certutil -cainfo
CertUtil: No local Certification Authority; use -config option
CertUtil: No more data is available.

Can someone offer me a rundown on what’s going on here and pointers as to how I can successfully revoke the cert?

csom – powershell query row limits for SharePoint online

I am not a super scripter, but I have a requirement run a search query over a site with multiple libraries. The query is for all documents where a specific string (someone’s name) appears.

I have 2 different scripts that I’ve tested and they work well, but I saw some stuff online about row limitations at 500 items.

Questions:

  • Is this true, is there any clear documentation about this anywhere?
  • If it is true, is there a way around it?
  • When we say 500 row limitation, do we mean it can only retrieve 500 items, or it only looks through 500 items? Must be the former, right?

Thanks for your help. For reference:
Script 1 – slight variation from this: CSOM

Script 2 – same as this script, but checking body not title PnP

ms office – Using aws run command – document type powershell- not able to open a excel sheet, make some change and save it

I am trying to run a powershell script using aws runcommand (aws powershell) on windows machine. The powershell script downloads an excel file from S3 location, runs a vbscript which inturn opens this excel file, make changes and saves it in the system. I have already logged into the windows ec2 machine as administrator, and signed with my valid login and saved.

When I run this powershell script through aws runcommand powershell documentype, the powershell always open new microsoft excel and prompts for sign.

As per my understanding, aws runcommand connects to windows ec2 with system32 console and creates a new session to execute a command. My question is how can I have excel signed with my id and when excel application is opened, it doesn’t prompt for sign?

PowerShell to get/list about 26000 SharePoint Library Folders

Trying to list all main folder names in a SharePoint Online Library with PowerShell, compare it with a file column metadata that gets uploaded in another SharePoint library and if there’s a match, to move the uploaded file to the matched folder in the first library. Talking about around 26000 main folders in the main library. For instance, a file with ID 1234567 gets uploaded in another library, it needs to look for a matching folder in the first library containing that ID(as the folder name will contain also a user name, it’d be something like John-Doe-1234567, but the ID is the unique aspect for this matching) and if it finds a matching folder among these 26000 main folders, to move it there, if not, to move it to a dedicated Archiving Folder again located in the first library. I managed to make that and have it working with Power Automate, but the List Folder action times out while trying to catch all these folders in the library and there’s no workaround there. Can anyone show me a PowerShell script for that, as I’m not really familiar with PowerShell, would be very much appreciated, thank you !