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

Snapin PowerShell Script Can't Run (Execution Policy)

Scheduled Pinned Locked Moved Solved
FOG Problems
5
5
1.8k
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.
  • R
    RobTitian16
    last edited by Oct 20, 2016, 3:02 PM

    Hi all,
    I’m trying to run a PowerShell script that renames the local administrator account after a PC has been imaged through the FOG snapin. However, I run into the issue of it not running because the execution policy isn’t set to remote signed. How would I go about ensuring it can run when the FOG service starts?
    Any help with this would be appreciated.

    1 Reply Last reply Reply Quote 0
    • W
      Wayne Workman
      last edited by Oct 20, 2016, 3:09 PM

      If you use the powershell template when you create a new snapin, it already has execution policy bypass in the arguments for you.

      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
      Daily Clean Installation Results:
      https://fogtesting.fogproject.us/
      FOG Reporting:
      https://fog-external-reporting-results.fogproject.us/

      1 Reply Last reply Reply Quote 2
      • G
        george1421 Moderator
        last edited by george1421 Oct 20, 2016, 9:47 AM Oct 20, 2016, 3:46 PM

        While this doesn’t directly answer your question, the answer may be close to what you need.

        In MDT for Win10 we use this run command line TS to launch a PS to remove the unwanted windows Apps. This script does need the execution bypass set. This will work if the user that is executing the script is running as a local admin.

        powershell.exe -ExecutionPolicy Bypass -Command "Copy-Item '%SCRIPTROOT%\gRemove-Win10-CrapApps.ps1' -destination %temp%; %temp%\gRemove-Win10-CrapApps.ps1; Remove-Item %temp%\*.ps1 -Force"
        

        Now we also rename the local admin account but we do it this way:

        wmic useraccount where name='administrator' rename <notRealAdmin_name>
        net localgroup administrators <notRealAdmin_name> /add
        

        And then for good measure we create a new user account with the name of ‘administrator’ , set a complex password and then disable the account. It’s not clear if it adds any level of security to our design, but we do audit against the use/attempted login of ‘administrator’ on the local workstations.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

        1 Reply Last reply Reply Quote 0
        • J
          Joe Schmitt Senior Developer
          last edited by Oct 20, 2016, 8:02 PM

          @george1421, @Wayne-Workman 's response is the correct answer. We already take into account execution policies with our snapin templates.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          1 Reply Last reply Reply Quote 1
          • Q
            Quazz Moderator
            last edited by Oct 21, 2016, 10:24 AM

            I use a slightly alternative method personally, where I run the powershell command from a batch script, which requires a slightly different approach.

            Example:

            powershell -Command "& {Set-ExecutionPolicy RemoteSigned; Import-Module PSWindowsUpdate; Get-WUInstall}" 
            
            1 Reply Last reply Reply Quote 0
            • 1 / 1
            1 / 1
            • First post
              5/5
              Last post

            193

            Online

            12.0k

            Users

            17.3k

            Topics

            155.2k

            Posts
            Copyright © 2012-2024 FOG Project