PowerShell startup script applied via GPO failing ambiguously

5,829

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

Share:
5,829
Jaxaeon
Author by

Jaxaeon

Updated on September 18, 2022

Comments

  • Jaxaeon
    Jaxaeon almost 2 years

    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.

    • DarkMoon
      DarkMoon almost 10 years
      Does HOMEDRIVE exist at machine startup, before the user logs on? I'm not sure it does, but I don't have a Windows PC handy to check...
    • Get-HomeByFiveOClock
      Get-HomeByFiveOClock almost 10 years
      I have actually noticed that there does seem to be a difference (I'm guessing with permissions) on directories in the C:\ - C:|windows\system with Windows 7 and Windows 8. I have long suspected there is some sort of added "security" in those directories that makes it harder.