PowerShell startup script applied via GPO failing ambiguously

group-policypowershellwindows-8.1

Script:

$folder = "$env:HOMEDRIVE\TestFolder"
New-Item -ItemType directory -Path $folder
  • note that the same group policy error occurs when $folder is set to "C:\..."

Execution policy is unrestricted, and the script runs fine when ran manually in Windows 8.1 (folder is created). I created a group policy (Computer Configuration > Windows Settings > Scripts > Startup) Added TestFolder.ps1 to \domain.com\SysVol\domain.com\Policies…\Machine\Scripts\Startup. Security Filtering configured to apply to the Domain Computers group. Policy applies fine to computer.

I get the following error when the policy attempts to apply script:

Group Policy event 1130

Startup script failed. 
    GPO Name : TestFolder Script
    GPO File System Path : \\domain.com\SysVol\domain.com\Policies\...\Machine
    Script Name: TestFolder.ps1

SupportInfo1 178254400 
  SupportInfo2 71 
  ErrorCode 267 
  ErrorDescription The directory name is invalid.  
  ScriptType 0 
  GPODisplayName TestFolder Script
  GPOFileSystemPath \\domain.com\SysVol\domain.com\Policies\...\Machine 
  GPOScriptCommandString TestFolder.ps1

I can't help but notice that \Scripts\Startup is omitted from the File System Path in the error information… Ideas?

EDIT: The group policy applies to a Windows 7 VM fine. Seems to me a problem with Windows 8.1.

Best Answer

I don't have any authoritative references, but the $HOME, $env:HOMEDRIVE and $env:HOMEPATH variables are user-specific environment variables.

It's unlikely that they would get assigned when you start a PowerShell host in the security context of the machine and not the user