locked
Powershell startup script on Windows XP RRS feed

  • Question

  • I am trying to get a Powershell startup script to run on windows XP and nothing seem to happen. The Domain is a single Windows 2008 R2 server with one WXP and one Windows 7. The script runs fine manually on both systems.

    I started by using the Powershell tab in the GPO. This worked fine for the Windows 7 workstation. The script ran correctly on reboot. but when I put the Windows XP in the same OU, nothing happend. The first thing the script does it write an message to the event log and I never see it on Windows XP.

    The next thing I tried was to wrapper the powershell script in a .Bat file and move the bat file to the Scripts Tab in the GPO. I put the actual powershell script in the netlogon share and the startup.bat file is a single line showed below.

    powershell -noexit -file \\%userdomain%\netlogon\startup.ps1

    Again, I tested the Bat file manually on both machines (WXP and W7) and it ran successfully. I restarted the Windows 7 box and the Startup script ran successfully. I restarted the WXP and got nothing.

    So my question is, can you run a Powershell script on windows XP? If so how? Thanks in advance.

    Roger


    Roger
    Thursday, August 11, 2011 9:59 PM

Answers

  • I found the problem. As I mentioned the .bat file was simply one line

        powershell -file \\%userdomain%\netlogon\starup.ps1

    Apparently the Environment variable %userdomain% is not available in the startup script in WXP bit is available in W7. Therefore WXP failed to locate the script and nothing happend. I am not sure why but if I simply change it to

       powershell -noexit -file \\MyDom\netlogon\starup.ps1

    and everything works just fine.    


    Roger
    • Proposed as answer by Bigteddy Friday, August 12, 2011 8:17 PM
    • Marked as answer by WaukeshaGeek Saturday, August 13, 2011 1:09 AM
    Friday, August 12, 2011 8:12 PM

All replies

  • Yes you can, but you must install it first.  Powershell is installed by default on Windows 7.  You can download Powershell for XP here:

    http://support.microsoft.com/kb/968929


    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
    Friday, August 12, 2011 3:51 AM
  • Thanks for the Replys. First, I did install Powershell V2 on Windows XP. That's why I said that "The script runs fine on both systems."

    I read through Kazun's post and I did essentially what he suggested. I also tried removing the .bat file and replacing it with a simple command

    powershell -noexit -file \\%userdomain%\netlogon\starup.ps1

    Again the command works fine on both systems if I just type it in. I put the command in the GPO and it works on the Windows 7 system but not on the Windows XP.

     


    Roger
    Friday, August 12, 2011 6:54 PM
  • I found the problem. As I mentioned the .bat file was simply one line

        powershell -file \\%userdomain%\netlogon\starup.ps1

    Apparently the Environment variable %userdomain% is not available in the startup script in WXP bit is available in W7. Therefore WXP failed to locate the script and nothing happend. I am not sure why but if I simply change it to

       powershell -noexit -file \\MyDom\netlogon\starup.ps1

    and everything works just fine.    


    Roger
    • Proposed as answer by Bigteddy Friday, August 12, 2011 8:17 PM
    • Marked as answer by WaukeshaGeek Saturday, August 13, 2011 1:09 AM
    Friday, August 12, 2011 8:12 PM
  • Glad to hear it.
    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
    Friday, August 12, 2011 8:17 PM
  • The variable %userdomain% might not be available att startup, but check out "\\domain.xxxxx" instead, i.e your FQDN is available via UNC paths, and it' ping:able aswell. This is available at startup.

    Its either one of your DC's which will responds - alternating/based upon which domaincontroller that verified the computer account.

    //BBengtsson - Senior Systems Administrator.

    Friday, October 19, 2012 10:26 AM
  • I to ran into your problem.
    %userdomain% command works in a Windows 7 startup script but does not work in a Windows XP startup script
    I needed this to work so did some more research and found this command which works.
    Hope it helps

    REM Set Domain Name
    FOR /F "tokens=2 delims==," %%A in ('WMIC COMPUTERSYSTEM GET DOMAIN /Format:list') DO (set "DOMAIN=%%A")
    echo %DOMAIN%


    Jed Parkes - MCITP - Windows 7, Enterprise Desktop Administrator

    Monday, October 22, 2012 9:19 PM
  • would this work:

        %logonserver%\netlogon\startup.ps1


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Tuesday, October 23, 2012 2:05 AM
  • %logonserver% only works after a user has logged on.

    %logonserver% will not work in a startup script.

    Note that the below article describes how to emulate %LOGONSERVER% with the following code:

    for /f "tokens=1 delims=\" %%i in ('@echo %0') do set DOMCTLR=\\%%i

    %DOMCTLR% can now be used in the same way that
    %LOGONSERVER% is used.

    http://blog.chrisara.com.au/2011/08/emulating-logonserver-for-computer.html

    This emulates the server where the script is running from though, it does not give you the domain name you are joined to like the script in my other post.


    Jed Parkes - MCITP - Windows 7, Enterprise Desktop Administrator


    Tuesday, October 23, 2012 2:27 AM