?
Solved

specify a PS script in group policy.

Posted on 2016-08-30
4
Medium Priority
?
47 Views
Last Modified: 2016-09-10
I am working on a powershell script to copy an ini file from a network share to a directory in the user profile when he logins.  

The destination path is something like \\server2\profiledir\%username%\appdata\roaming\vlc\vlc-qt-interface.ini

can I specify this PS1 file in USER CONFIGURATION /POLICIES/WINDOWS SETTINGS/SCRIPT/LOGON of my GP?

Thanks.
0
Comment
Question by:nav2567
  • 2
4 Comments
 
LVL 84

Expert Comment

by:David Johnson, CD, MVP
ID: 41777051
it will have to be in the user settings not the computer settings
I'd use
%userprofile%\appdata\roaming\vlc\vlc\vlc-qt-interface.ini 

Open in new window

for the destination rather than
 \\server2\profiledir\%username%\appdata\roaming\vlc\vlc-qt-interface.ini

Open in new window


you will have to in the computer settings create and run a batch file that runs the following
powershellpolicy.cmd
C:\windows\system32\windowspowershell\v1.0\powershell.exe -executionpolicy bypass -file .\copyfile.ps1

Open in new window


copyfile.ps1
$source = \\server\share\vlc-qt-interface.ini
$destination = $env:userprofile + '\appdata\roaming\vlc\vlc\vlc-qt-interface.ini'
if (!(test-path $source))
     { 
     "Source Path $source not available" | out-file \\server\share\logs\copyfilefailures.txt -append
     }
else {
    try{
        copy-item -source $source -destination $destination
        }
    catch
        {
        'Destination error:' + $destination | out-file  \\server\share\logs\copyfilefailures.txt -append 
        }
}

Open in new window

0
 
LVL 43

Expert Comment

by:Adam Brown
ID: 41777090
I would use a File preference to place the file to %AppDataDir%\roaming\vlc\vlc-qt-interface.ini

Preferences work significantly better than login scripts and are much more reliable. https://technet.microsoft.com/en-us/library/cc772536(v=ws.11).aspx has info.
0
 
LVL 84

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 total points
ID: 41777148
fixed missing quotes in $source directory
$source = '\\server\share\vlc-qt-interface.ini'
$destination = $env:userprofile + '\appdata\roaming\vlc\vlc\vlc-qt-interface.ini'
if (!(test-path $source))
     { 
     "Source Path $source not available" | out-file \\server\share\logs\copyfilefailures.txt -append
     }
else {
    try{
        copy-item -source $source -destination $destination
        }
    catch
        {
        'Destination error:' + $destination | out-file  \\server\share\logs\copyfilefailures.txt -append 
        }
}

Open in new window

0
 

Author Comment

by:nav2567
ID: 41777400
Thanks a lot David and Adam for always helping me!!!

Adam, I have been trying GPP - FILE update but I am not seeing the file is being copied to the destination.  

I specified \\server2\profiledir\%username%\appdata\roaming\vlc\vlc-qt-interface.ini in the destination of the GPP and the user login has r/w access.

The destination folder VLC is not created in \\server2\profiledir\%username%\appdata\roaming folder until the user launch VLC Player software the first time.  

Even the VLC folder is created in the roaming folder, I still do not see the file being copied after logout and log back in.   This is why I am going back to the legacy way and it works.
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's recap what we learned from yesterday's Skyport Systems webinar.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question