Need advise on the below powershell script to deploy on intune devices
Hi Champs,
Not sure if below script is correct. Looks like it is working if we run powershell as administrator but otherwise throwing errors. I want to deploy below script to endpoint devices via intune. Please assist.
I want to set the below location path at word, options, save, Default personal templates location
ForEach ($user in (Get-ChildItem “C:Users” -Exclude Public))
{
$location = “C:Users$($user.Name)DocumentsCustom Office Templates”
$IsPresent = Get-ItemProperty ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ | ForEach-Object {If($_ -like ‘*PersonalTemplates*’){ Return ‘True’ }}
if(-Not($IsPresent -eq ‘True’))
{
New-ItemProperty -Path ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ -Name ‘PersonalTemplates’ -Value $location -PropertyType ExpandString -Force
New-Item -ItemType Directory -Force -Path $location
}
$existingValue= Get-ItemPropertyValue -Path ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ -Name ‘PersonalTemplates’
if([string]::IsNullOrWhiteSpace($existingValue)){
Set-ItemProperty -Path ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ -Name ‘PersonalTemplates’ -Value $location
}
else{
$location=$existingValue
if(!(test-path $existingValue))
{
New-Item -ItemType Directory -Force -Path $existingValue
}
}
}
Regards,
Ram
Hi Champs, Not sure if below script is correct. Looks like it is working if we run powershell as administrator but otherwise throwing errors. I want to deploy below script to endpoint devices via intune. Please assist.I want to set the below location path at word, options, save, Default personal templates location ForEach ($user in (Get-ChildItem “C:Users” -Exclude Public)){$location = “C:Users$($user.Name)DocumentsCustom Office Templates”$IsPresent = Get-ItemProperty ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ | ForEach-Object {If($_ -like ‘*PersonalTemplates*’){ Return ‘True’ }}if(-Not($IsPresent -eq ‘True’)){New-ItemProperty -Path ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ -Name ‘PersonalTemplates’ -Value $location -PropertyType ExpandString -ForceNew-Item -ItemType Directory -Force -Path $location}$existingValue= Get-ItemPropertyValue -Path ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ -Name ‘PersonalTemplates’if([string]::IsNullOrWhiteSpace($existingValue)){Set-ItemProperty -Path ‘HKCU:SOFTWAREMicrosoftOffice16.0WordOptions’ -Name ‘PersonalTemplates’ -Value $location}else{$location=$existingValueif(!(test-path $existingValue)){New-Item -ItemType Directory -Force -Path $existingValue}}} Regards,Ram Read More