I have an issue. I have a big script, which searches specific WmiObjects, saves them with the name and the folder in an array, which will be exported later. Everything works, except for Baselines. When I try to export Baselines, i get the error in the tilte. It does export some of them, but not everything (f.e the ones in the screenshots).![example](https://learn-attachment.microsoft.com/api/attachments/73e7a345-aa7d-45a7-b7c7-d5a9d5571ebf?platform=QnA)
![reference](https://learn-attachment.microsoft.com/api/attachments/fd71bbfd-b285-4535-b109-885cd92c38a4?platform=QnA)
Is there a way to change the Indexing or is there a different problem? I know that my code is not beautiful, not easy to read and that this is very specific but I am really stuck and could use a lot of help since we want this script for our backup solution.
Thank you :)
#Configuration Baselines - local Path
$DiskPathConfBaselines = "BAS:\ConfigurationBaseline"
#Configuration Baseline - export Path
$RootPathBaselineExport = "C:\Temp\ConfigManager-Dump\Configuration Baselines"
#Configuration Baselines
$Script:ExportArrayConfBaselines = @()
function Get-Baselines {
param (
[string]$rootPath,
[string]$subfolderPath = ""
)
# Get the list of subfolders in the current directory
$currentPath = Join-Path -Path $rootPath -ChildPath $subfolderPath
If($currentPath[$currentPath.Length -1] -eq "\"){
$currentPath = $currentPath.TrimEnd($currentPath[-1])
}
$subfolders = (Get-ChildItem -Path $currentPath).name
# Loop through each subfolder
foreach ($folder in $subfolders) {
$query = ("$subfolderPath\$folder").Replace("\", "/")
$Script:ExportArrayConfBaselines += Get-CMBaseline -Fast |Where-Object {$_.ObjectPath -Like "*$query*"} | Select-Object LocalizedDisplayName, @{Name='subfolder';Expression={("$subfolderPath\$folder")}}
Get-Baselines -rootPath $rootPath -subfolderPath "$subfolderPath\$($folder)"
}
}
#Configuration Baselines
function Export-Baselines {
param (
[string]$RootPath
)
foreach($BaselineName in $ExportArrayConfBaselines){
$BaselineNameClean = $BaselineName.LocalizedDisplayName -Replace '[^\w\s]', ' '
$NewPath = Join-path -Path $RootPath -ChildPath $BaselineName.subfolder
if(Test-Path $NewPath){
if ($BaselineName.subfolder -eq "\"){
Export-CMBaseline -Name $BaselineName.LocalizedDisplayName -Path "$($NewPath)$($BaselineNameClean).cab"
}else{
Export-CMBaseline -Name $BaselineName.LocalizedDisplayName -Path "$($NewPath)\$($BaselineNameClean).cab" }
}else{
New-Item -Path $NewPath -ItemType Directory
if ($BaselineName.subfolder -eq "\"){
Export-CMBaseline -Name $BaselineName.LocalizedDisplayName -Path "$($NewPath)$($BaselineNameClean).cab"
}else{
Export-CMBaseline -Name $BaselineName.LocalizedDisplayName -Path "$($NewPath)\$($BaselineNameClean).cab"
}
}
}
}
Export-Baselines -RootPath $RootPathBaselineExport