Skip to content

Instantly share code, notes, and snippets.

@jamiechalmerzlp
jamiechalmerzlp / Get-SPOFolder&ItemCount.ps1
Last active August 10, 2022 14:15
Provides the ability for users to export a count for all Folders, Sub Folders and Files from specified directories using PnP Online
#Parameters - Remove /site/site if this is not applicable to you
$SiteURL = "https://XXXX.sharepoint.com/site/site"
Connect-PnPOnline $SiteURL -Interactive
$FolderSiteRelativeURL = "/Shared Documents/subfolder/subfolder"
$downloadPath = "C:\temp"
Function Get-SPOFolderStats
{
function get-localadmins{
[cmdletbinding()]
Param(
[string]$computerName
)
$group = get-wmiobject win32_group -ComputerName $computerName -Filter "LocalAccount=True AND SID='S-1-5-32-544'"
$query = "GroupComponent = `"Win32_Group.Domain='$($group.domain)'`,Name='$($group.name)'`""
$list = Get-WmiObject win32_groupuser -ComputerName $computerName -Filter $query
$list | %{$_.PartComponent} | % {$_.substring($_.lastindexof("Domain=") + 7).replace("`",Name=`"","\")}
}
if (test-path HKLM:\Software\Microsoft\Office\14.0\Outlook) {$bitness = (get-itemproperty HKLM:\Software\Microsoft\Office\14.0\Outlook).Bitness}
if (test-path HKLM:\Software\Microsoft\Office\15.0\Outlook) {$bitness = (get-itemproperty HKLM:\Software\Microsoft\Office\15.0\Outlook).Bitness}
if (test-path HKLM:\Software\Microsoft\Office\16.0\Outlook) {$bitness = (get-itemproperty HKLM:\Software\Microsoft\Office\16.0\Outlook).Bitness}
if (test-path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\14.0\Outlook) {$bitness = (get-itemproperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\14.0\Outlook).Bitness}
if (test-path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\Outlook) {$bitness = (get-itemproperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\Outlook).Bitness}
if (test-path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Outlook) {$bitness = (get-itemproperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Outlook).Bitness}
write-host $Bitness
New-ItemProperty "HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319" -Name "SystemDefaultTlsVersions" -Value 1 -PropertyType "DWord"
New-ItemProperty "HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319" -Name "SystemDefaultTlsVersions" -Value 1 -PropertyType "DWord"
New-ItemProperty "HKLM\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319" -Name "SystemDefaultTlsVersions" -Value 1 -PropertyType "DWord"
New-ItemProperty "HKLM\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319" -Name "SystemDefaultTlsVersions" -Value 1 -PropertyType "DWord"
$TPMPRESENT = (Get-Tpm).TpmPresent
$TPMENABLED = (Get-Tpm).TpmEnabled
$TPMREADY = (Get-Tpm).TpmReady
$tpmVersion = Get-WmiObject -Class Win32_Tpm -Namespace root\CIMV2\Security\MicrosoftTpm | Select-Object -Property SpecVersion
$tpmVersionOut = $tpmVersion.SpecVersion.Split(",")[0] -as [string]
Write-Host "TPM Present: ${TPMPRESENT}, TPM Enabled: ${TPMENABLED}, TPM Ready ${TPMREADY}, TPM Version: ${tpmVersionOut}"
$Files = Get-ChildItem -Path "your\directory\here" -File -Recurse -Name -Force -ErrorAction SilentlyContinue | Measure-Object | Select-Object @{Name='File(s) Count';Expression={$_.count}}
$Folders = Get-ChildItem -Path "your\directory\here" -Directory -Recurse -Name -Force -ErrorAction SilentlyContinue | Measure-Object | Select-Object @{Name='Folder Count';Expression={$_.count}}
write-host "Files: $Files"
write-host "Folders: $Folders"
#Function to Download All Files from a SharePoint Online Folder - Recursively
$FolderName = "Name the folder you are downloading"
#The transcript will capture the process to ensure you have a log of the download/transfer - ALWAYS KEEP LOGS
Start-Transcript -Path "C:\temp\$FolderName.txt"
Function Download-SPOFolder([Microsoft.SharePoint.Client.Folder]$Folder, $DestinationFolder)
{
#Get the Folder's Site Relative URL
$FolderURL = $Folder.ServerRelativeUrl.Substring($Folder.Context.Web.ServerRelativeUrl.Length)
$LocalFolder = $DestinationFolder + ($FolderURL -replace "/","\")
#Create Local Folder, if it doesn't exist
#Needs ExchangeOnline and MSOLService
$SharedMailboxes = Get-EXOMailbox -Filter {(recipienttypedetails -eq "SharedMailbox") -or (recipienttypedetails -eq "EquipmentMailbox") -or (recipienttypedetails -eq "RoomMailbox")} | get-MsolUser | Select-Object UserPrincipalName,blockcredential,recipienttypedetails
$SignInEnabledSharedMailboxes = $SharedMailboxes | Where-Object {$_.BlockCredential -eq $False}
$SignInEnabledSharedMailboxes | Export-CSV C:\temp\report.csv -NoTypeInformation
If ($SignInEnabledSharedMailboxes) {
Write-Host "[BAD] $($SignInEnabledSharedMailboxes.Count) shared mailboxes were found with signin enabled."
Do {
$Answer = Read-Host -Prompt 'Do you want to disable signin for all shared mailboxes? (y/n)'
If (!($Answer -match 'y' -or $Answer -match 'n')) {Write-Host 'Please answer "y" for Yes or "n" for No.'}
}
$members = net localgroup administrators |
where {$_ -AND $_ -notmatch "command completed successfully"} |
select -skip 4
$members += $(Get-Date -format 'd')
write-host $members
#Only keep this line if you are using Datto RMM for a UDF.
#New-ItemProperty -PropertyType String "HKLM:\SOFTWARE\CentraStage" -Name "Custom5" -Value $members
# Parameters for source and destination for the Image file
# Current script is edited to put the same image on LockScreen and Wallpaper
$WallpaperURL = "bloburl from azure" # Change to your fitting
$LockscreenUrl = "bloburl from azure" # Change to your fitting
$ImageDestinationFolder = "c:\temp" # Change to your fitting - this is the folder for the wallpaper image
$WallpaperDestinationFile = "$ImageDestinationFolder\wallpaper.png" # Change to your fitting - this is the Wallpaper image
$LockScreenDestinationFile = "$ImageDestinationFolder\LockScreen.png" # Change to your fitting - this is the Lockscreen image