Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: PowerShell logon script

24 Aug 2010   #1

Windows 7 Professional 32bit
PowerShell logon script

Ok, so this doesn't necessarily have to do with Windows 7, but I originally wanted to reply to a post on Vista forums and somehow I ended up here. Anyway...

I actually tried all of this on Windows Server 2008 - set policies, scripts and logged on there.
Here's one way that actually works. 1) created a logonScript.ps1 file with whatever in it for the actual logon script. 2) created GPO with a policy for running a logon script and specified a vbScript file: launcher.vbs. 3) put those two files in the same folder related to the policy if you know what I mean.
The launcher.vbs contains:
' set up objects
Set WshShl = WScript.CreateObject("WScript.Shell")
Set fileSys = CreateObject("Scripting.FileSystemObject")
Set scriptFile = fileSys.GetFile("logonScript.ps1")

WshShl.Run("PowerShell.exe -NoLogo -NoProfile -command ""&{set-executionpolicy Unrestricted;&'" & scriptFile & "'}""")
That last line causes something like:
'PowerShell.exe -NoLogo -NoProfile -command "&{set-executionpolicy Unrestricted;&'\\IT270\sysvol\\Policies\{AAD5280F-A3B7-4F65-B15B-27E6F92BA431}\User\Scripts\Logon\logonScript.ps1'}"
to run.
The one remaining problem is that I still get a prompt asking me if I want to run the script or not. If I set the IE intranet zone trusted sites to have file://IT270 then that prompt goes away. Unfortunately, setting it with Group Policy didn't work. I had to do it manually or individually in any case. I have another idea of how to get around this: copy the script down to the local computer (TEMP directory) with the VBscript and then invoke it from there.
Ok, I know this is all pretty ridiculous and probably way more effort than it's worth, but it's an exercise. I wanted to make it happen and it works with PS v.1. I guess if I wanted to get really ridiculous, I could just drag out the entire script into the command line I created above. Though, it probably has a max characters limit or something.

My System SpecsSystem Spec
29 May 2011   #2

Windows 7 Ultimate x64

I've also created a Powershell login script here which I run not using Group Policy but from the user's AD account as part of their actual login script.

Powershell login script to map network drives, printers and applicaton settings

Hope this helps others out.
My System SpecsSystem Spec

 PowerShell logon script

Thread Tools

Similar help and support threads
Thread Forum
Help me integrate a Powershell script into the context menu
Hi all, I want to add a custom entry to the right-click context menu so that I can send a copy of a file to a predetermined folder on a remote computer. This idea is based on a tutorial. I stored a Powershell script in C:\context-menu.ps1. There should only be one argument (which is the file's...
General Discussion
Is there a powershell script for turning off power saving on all devs?
I have lots of USB devices on several hubs but more importantly, shit happens and I need to turn off that horrid Power Management feature that allows devices to be turned off to save power. Does anyone have a script to run through all the PC devices and uncheck that feature where it exists? CHEERS!
Hardware & Devices
Powershell script to count file types
Hi all, forgive me if this is the wrong folder. I am googling scripts to find a PS script to count file types and files in several directory's on our network. I am a noob on powershell, and I'm trying to experiment. I have several directory's on my "Libraries" directory on my pc at work. I'm...
General Discussion
CMD or Powershell Moving - script not working
set LISTFOLDER=D:\List\ set FILESPATH=D:\Igre\COD-MW2\main\images set DESTPATH=D:\Igre\COD-MW2\main\images\thepit REM for /r %LISTFOLDER% %%I in (*.txt) do echo xcopy /qvs "%FILESPATH%\%%~nxI" "%DESTPATH%%%~pnxI" for /r %LISTFOLDER% %%I in (*.txt) do xcopy /qvs "%FILESPATH%\%%~nxI"...
General Discussion
powershell script to create user folders and set permissions
Wondering if anyone in this forum can help me figure out what I am doing wrong with my script. I am grabbing a text file with a list of users in it. I want to then create folders for all those people and then set explicit permissions on those folders to only allow the users and admin access to it....

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 18:41.
Twitter Facebook Google+