Forum Discussion

DanielNiccoli's avatar
DanielNiccoli
Steel Contributor
Jul 06, 2022

Server Baseline throws error when invoked from other folder

In Baseline-LocalInstall.ps1 is a line

 

$GpoMap = .\Tools\MapGuidsToGpoNames.ps1 ..\GPOs
 
When you run Baseline-LocalInstall.ps1 from a different working directory, this line causes the script to throw an error.
 
To fix this, please replace the line with
 
$GpoMap = . (Join-Path $PSScriptRoot "Tools\MapGuidsToGpoNames.ps1" -Resolve) (Join-Path $PSScriptRoot "..\GPOs" -Resolve)
 
You can also shorten this
 
$GpoMap = . "$PSScriptRoot\Tools\MapGuidsToGpoNames.ps1" "$PSScriptRoot\..\GPOs"
 
While at it, the script often uses
 
[System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path)
 
Where $PSScriptRoot would be the better alternative.
 
Same with
 
[System.IO.Path]::Combine($rootDir, ...
 
Where Join-Path would be the better alternative.
 
Can I also recommend to maybe just put the entire thing on GitHub so the community is able to submit pull requests and also backport fixes for older server OSes like Server 2019, since you already said Microoft won't do backports?
 
Thanks.

Resources