• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Powershell script doesnt work when fog client executes it

Scheduled Pinned Locked Moved Solved
FOG Problems
2
4
756
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G
    Greg Plamondon Testers
    last edited by Greg Plamondon Jan 3, 2020, 3:37 PM Jan 3, 2020, 8:54 PM

    I have the lock/logins screen set so that users know not to logon while the setup process is running.

    alt text

    I am using this PowerShell script in a snapin to change the image back to the default, the snapin is set to reboot.

    <#
    .SYNOPSIS
    	Change Lock Screen and Desktop Background in Windows 10 Pro.
    .DESCRIPTION
    	This script allows you to change logon screen and desktop background in Windows 10 Professional using GPO startup script.
    .PARAMETER LockScreenSource (Optional)
    	Path to the Lock Screen image to copy locally in computer.
        Example: "\\SERVER-FS01\LockScreen.jpg"
    .PARAMETER BackgroundSource (Optional)
    	Path to the Desktop Background image to copy locally in computer.
        Example: "\\SERVER-FS01\BackgroundScreen.jpg"
    .PARAMETER LogPath (Optional)
        Path where save log file. If it's not specified no log is recorded.
    .EXAMPLE
        Set Lock Screen and Desktop Wallpaper with logs:
        Set-Screen -LockScreenSource "\\SERVER-FS01\LockScreen.jpg" -BackgroundSource "\\SERVER-FS01\BackgroundScreen.jpg" -LogPath "\\SERVER-FS01\Logs"
    .EXAMPLE
        Set Lock Screen and Desktop Wallpaper without logs:
        Set-Screen -LockScreenSource "\\SERVER-FS01\LockScreen.jpg" -BackgroundSource "\\SERVER-FS01\BackgroundScreen.jpg"
    .EXAMPLE
        Set Lock Screen only:
        Set-Screen -LockScreenSource "\\SERVER-FS01\LockScreen.jpg" -LogPath "\\SERVER-FS01\Logs"
    .EXAMPLE
    	Set Desktop Wallpaper only:
        Set-Screen -BackgroundSource "\\SERVER-FS01\BackgroundScreen.jpg" -LogPath "\\SERVER-FS01\Logs"
    .NOTES 
    	Author: Juan Granados 
    	Date:   September 2018
    #>
    Param(
    		[Parameter(Mandatory=$false,Position=0)] 
    		[ValidateNotNullOrEmpty()]
    		[string]$LockScreenSource,
            [Parameter(Mandatory=$false,Position=1)] 
    		[ValidateNotNullOrEmpty()]
    		[string]$BackgroundSource,
            [Parameter(Mandatory=$false,Position=2)] 
    		[ValidateNotNullOrEmpty()]
    		[string]$LogPath
    	)
    
    #Requires -RunAsAdministrator
    
    if (-not [string]::IsNullOrWhiteSpace($LogPath)) {
        Start-Transcript -Path "$($LogPath)\$($env:COMPUTERNAME).log" | Out-Null
    }
    
    $ErrorActionPreference = "Stop"
    
    $RegKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP"
    
    $DesktopPath = "DesktopImagePath"
    $DesktopStatus = "DesktopImageStatus"
    $DesktopUrl = "DesktopImageUrl"
    $LockScreenPath = "LockScreenImagePath"
    $LockScreenStatus = "LockScreenImageStatus"
    $LockScreenUrl = "LockScreenImageUrl"
    
    $StatusValue = "1"
    $DesktopImageValue = "C:\Windows\System32\Desktop.jpg"
    $LockScreenImageValue = "C:\Windows\System32\LockScreen.jpg"
    
    if (!$LockScreenSource -and !$BackgroundSource) 
    {
        Write-Host "Either LockScreenSource or BackgroundSource must has a value."
    }
    else 
    {
        if(!(Test-Path $RegKeyPath)) {
            Write-Host "Creating registry path $($RegKeyPath)."
            New-Item -Path $RegKeyPath -Force | Out-Null
        }
        if ($LockScreenSource) {
            Write-Host "Copy Lock Screen image from $($LockScreenSource) to $($LockScreenImageValue)."
            Copy-Item $LockScreenSource $LockScreenImageValue -Force
            Write-Host "Creating registry entries for Lock Screen"
            New-ItemProperty -Path $RegKeyPath -Name $LockScreenStatus -Value $StatusValue -PropertyType DWORD -Force | Out-Null
            New-ItemProperty -Path $RegKeyPath -Name $LockScreenPath -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null
            New-ItemProperty -Path $RegKeyPath -Name $LockScreenUrl -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null
        }
        if ($BackgroundSource) {
            Write-Host "Copy Desktop Background image from $($BackgroundSource) to $($DesktopImageValue)."
            Copy-Item $BackgroundSource $DesktopImageValue -Force
            Write-Host "Creating registry entries for Desktop Background"
            New-ItemProperty -Path $RegKeyPath -Name $DesktopStatus -Value $StatusValue -PropertyType DWORD -Force | Out-Null
            New-ItemProperty -Path $RegKeyPath -Name $DesktopPath -Value $DesktopImageValue -PropertyType STRING -Force | Out-Null
            New-ItemProperty -Path $RegKeyPath -Name $DesktopUrl -Value $DesktopImageValue -PropertyType STRING -Force | Out-Null
        }  
    }
    
    if (-not [string]::IsNullOrWhiteSpace($LogPath)){Stop-Transcript}
    

    The problem I am seeing is that the following script works if I run it from a PowerShell window but not as a snapin.

    snapin settings:
    alt text

    Logfile for script:

    **********************
    Windows PowerShell transcript start
    Start time: 20200103154304
    Username: MTSTRANS\SYSTEM
    RunAs User: MTSTRANS\SYSTEM
    Configuration Name: 
    Machine: TV3270 (Microsoft Windows NT 10.0.18363.0)
    Host Application: powershell.exe -ExecutionPolicy Bypass -NoProfile -File C:\Program Files (x86)\FOG\tmp\Set-Screen.ps1 -LockScreenSource C:\Windows\Web\Screen\img100.jpg -LogPath c:\TEMP
    Process ID: 4196
    PSVersion: 5.1.18362.145
    PSEdition: Desktop
    PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.18362.145
    BuildVersion: 10.0.18362.145
    CLRVersion: 4.0.30319.42000
    WSManStackVersion: 3.0
    PSRemotingProtocolVersion: 2.3
    SerializationVersion: 1.1.0.1
    **********************
    Creating registry path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP.
    Copy Lock Screen image from C:\Windows\Web\Screen\img100.jpg to C:\Windows\System32\LockScreen.jpg.
    Creating registry entries for Lock Screen
    **********************
    Windows PowerShell transcript end
    End time: 20200103154305
    **********************
    

    but the image never changes…

    fog.log

    ------------------------------------------------------------------------------
    ---------------------------------SnapinClient---------------------------------
    ------------------------------------------------------------------------------
     1/3/2020 4:29 PM Client-Info Client Version: 0.11.16
     1/3/2020 4:29 PM Client-Info Client OS:      Windows
     1/3/2020 4:29 PM Client-Info Server Version: 1.5.7.56
     1/3/2020 4:29 PM Middleware::Response Success
     1/3/2020 4:29 PM SnapinClient Running snapin SET-LOGON-SCREEN
     1/3/2020 4:29 PM Middleware::Communication Download: http://192.168.10.238//fog/service/snapins.file.php?mac=00:23:24:B3:BB:07|44:85:00:9A:20:2D|46:85:00:9A:20:2C|44:85:00:9A:20:2C|44:85:00:9A:20:30&taskid=10518
     1/3/2020 4:29 PM SnapinClient C:\Program Files (x86)\FOG\tmp\Set-Screen.ps1
     1/3/2020 4:29 PM Bus Emmiting message on channel: Notification
     1/3/2020 4:29 PM SnapinClient Starting snapin
     1/3/2020 4:29 PM SnapinClient Snapin finished
     1/3/2020 4:29 PM SnapinClient Return Code: 0
     1/3/2020 4:29 PM Bus Emmiting message on channel: Notification
     1/3/2020 4:29 PM Middleware::Communication URL: http://10fogserver/fog/service/snapins.checkin.php?taskid=10518&exitcode=0&mac=00:23:24:B3:BB:07|44:85:00:9A:20:2D|46:85:00:9A:20:2C|44:85:00:9A:20:2C|44:85:00:9A:20:30&newService&json
     1/3/2020 4:29 PM Power Creating shutdown request
     1/3/2020 4:29 PM Power Parameters: /r /c "Snapin requested restart" /t 0
     1/3/2020 4:29 PM Bus Emmiting message on channel: Power
     1/3/2020 4:29 PM Power Attempt 1/6 to shutdown computer
     1/3/2020 4:29 PM Power --> API call returned 1, will re-attempt in 5 minutes
    
    1 Reply Last reply Reply Quote 0
    • S
      Sebastian Roth Moderator
      last edited by Jan 3, 2020, 9:18 PM

      @Greg-Plamondon said in Powershell script doesnt work when fog client executes it:

      The problem I am seeing is that the following script works if I run it from a PowerShell window but not as a snapin.

      Do you see it being executed in the fog-client log? Just want to make sure!

      Are you aware of the fact that fog-client runs as SYSTEM account. Maybe this causes your script to behave different to what you expect?

      Not sure if this is playing a role in your case as well? https://forums.fogproject.org/topic/11671/powershell-snapin-and-registry

      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

      G 1 Reply Last reply Jan 3, 2020, 9:32 PM Reply Quote 0
      • G
        Greg Plamondon Testers @Sebastian Roth
        last edited by Jan 3, 2020, 9:32 PM

        @Sebastian-Roth said in Powershell script doesnt work when fog client executes it:

        @Greg-Plamondon said in Powershell script doesnt work when fog client executes it:

        The problem I am seeing is that the following script works if I run it from a PowerShell window but not as a snapin.

        Do you see it being executed in the fog-client log? Just want to make sure!

        Are you aware of the fact that fog-client runs as SYSTEM account. Maybe this causes your script to behave different to what you expect?

        Not sure if this is playing a role in your case as well? https://forums.fogproject.org/topic/11671/powershell-snapin-and-registry

        Sorry just updated my original post with the log.

        1 Reply Last reply Reply Quote 0
        • S
          Sebastian Roth Moderator
          last edited by Jan 4, 2020, 8:00 AM

          @Greg-Plamondon Ok, fog-client log looks fine. What about the other things I mentioned?

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            1/4
            Last post

          177

          Online

          12.0k

          Users

          17.3k

          Topics

          155.2k

          Posts
          Copyright © 2012-2024 FOG Project