Share via


PowerShell script not running when applied through GPO.

Question

Tuesday, August 8, 2017 8:49 PM

Hi, I am applying a script to a workstation through GPO. The thing is that the script is not applying when I am deploying it through GPO, but I can deploy it when I am log in to workstation.

Here is the script:

Set-ExecutionPolicy Unrestricted

# define store number for URL

$wks = $env:computername
$number = $wks.substring(3,3)

# Create shortcut

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Chrome.lnk")
$ShortCut.TargetPath="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
$ShortCut.Arguments= "-kisok https://dom-prod/wsc/login.do?StoreId=SCXX$number"
$ShortCut.WorkingDirectory = "C:\Program Files (x86)\Google\Chrome\Application\";
$ShortCut.Save()

Any ideas?

All replies (6)

Wednesday, August 9, 2017 9:20 AM

Hi,

For your case, you may run CMD as administrator then use command gpresult /h result.html to check GPO applied status.

In addition, I suggest you create shortcut using GPO under Computer Configuration/ User Configuration – Preferences – Windows Settings—Shortcuts.

If you need further help, please feel free to let us know.

Best Regards,

William


Wednesday, August 9, 2017 3:47 PM

I have run gpresult and I can see that policy is being applied. The issue is that the script does not run wehn it is applied through GPO but it runs when it is applied directly on workstation. Here is an image:

Also, I have to use a script because the script does calculation based on workstation name and gives URL that is added to shortcut.


Thursday, August 10, 2017 1:32 PM

You can't set the execution policy within the script. Instead, click Edit and add the following parameter:

-executionpolicy bypass


Friday, August 11, 2017 9:33 AM

Hi,

Just like Jacorbello said.

Or configure GPO.

Path:computer configuration/policies/administrative templates/windows components/windows powershell/Turn on Script Execution

enable "Turn on Script Execution"

It is not recommand push ps1 by GPO. It's easy to fail since the differences of clients'  net.framework version, powershell version and so on.

invoke-command  is a remote command for one-to-many :

/zh-cn/powershell/module/Microsoft.PowerShell.Core/Invoke-Command?view=powershell-6

Best Regards,

Frank

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Monday, August 14, 2017 8:27 AM

Hi,
Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

Best Regards,

Frank

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Tuesday, August 15, 2017 7:58 AM

Hi,

Was your issue resolved? 

If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.

Best Regards,
Frank

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].