Guy recommends :
Free Permissions
Analyzer Tool

Solarwinds Free Download of Permissions Analyzer

 

View the effective permissions for a folder or shared drive. Free download try it now!


PowerShell Logon Scripts

PowerShell Logon Scripts

If you are thinking of using PowerShell for a logon script - think again.  Much as I loved grappling with old DOS batch files and perfecting the superior VBScript logon scripts, I admit there are better ways of achieving a task than a PowerShell logon script.  Whatever your worthy project to control the users desktop environment, start with Group Policy.  Incidentally, even if you end up ignoring my advice, you will still probably need a Group Policy to push out your logon script.

Topics For PowerShell Logon Scripts

 ♣

PowerShell Logon Scripts - If You Must!

Back to PowerShell and logon scripts, PowerShell was designed as a command line method for configuring the operating system and not for tweaking users' environments.  In particular, the security and script execution methods employed by PowerShell are unsuited to running on client machines.

Even if you succeed in getting a PowerShell logon scripts to run, you have to ask was it worth it?  Surely there must be a better way of providing a default printer or access to a network share.

PowerShell Logon Script Technique

The problem is that you cannot simply assign a .ps1 file as a logon script; because, by design, Windows 7 or Vista won't be able to execute it.  Fortunately, there is a work-around and that is to create a VBScript script which calls your PowerShell script.  To my mind this whole procedure is telling me clearly, this is not the best way of configuring logon settings.

However, if this is what you want, then PowerShell can play its part via the -ComObject.  Here is a MapNetworkDrive example:

# PowerShell Logon Script Example
$net = $(New-Object -ComObject WScript.Network)
$net.MapNetworkDrive("F:", "\\BigServer\Stuff")

Note 1: Assume that you save the above code in C:\PowerShell\logon.ps1

Note 2: Now call the logon.ps1 file from VBScript thus:

# PowerShell Logon Script Called From VBScript
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell.exe -noexit C:\PowerShell\logon.ps1")

See more on PowerShell MapNetworkDrive

# PowerShell Logon Script Example
$net = $(New-Object -ComObject WScript.Network)
$net.MapNetworkDrive("F:", "\\BigServer\Stuff")

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v10

SolarWinds' Network Performance Monitor will help you discover what's happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds' Network Performance Monitor

PowerShell v 2.0 and Windows 7

Version 2.0 transforms PowerShell's remoting, Windows 7 and Windows Server 2008 R2 provide the menus to configure PowerShell scripts to run via Group Policy.

Another option for running PowerShell scripts on remote Windows 7 computers is to use logon, logoff, startup, and shutdown scripts defined in GPOs. Earlier versions of Windows supported specifying only command files for these scripts. PowerShell provides far more flexibility and power than is available in command files.  See more on PowerShell in Windows 7

Executing PowerShell Logon Scripts Via Group Policy

When Group Policy was delivered with Windows 2000, it allowed administrators to execute batch file-based scripts at user logon or logoff, as well as at computer startup and shutdown. This enabled administrators to configure parts of the environment or execute additional programs during those times. Windows 7 introduces support for executing PowerShell scripts as well, giving administrators more comprehensive tools for real-time configuration during these system events.  See more on Logon Script Group Policy.

Group Policy, Logon Scripts and PowerShell

Here are the Group Policy paths to set the user and computer logon scripts.

User Configuration\Windows Settings\Scripts (Logon/Logoff).
also:
Computer Configuration\Windows Settings\Scripts (Startup/Shutdown).

PowerShell Logon Scripts

Guy Recommends: SolarWinds Network Topology Mapper (NTM)SolarWinds Network Topology Mapper

NTM will produce a neat diagram of your network topology.  But that's just the start; Network Topology Mapper can create an inventory of the hardware and software of your machines and network devices.  Other neat features include dynamic update for when you add new devices to your network.  I also love the ability to export the diagrams to Microsoft Visio.

Finally, Guy bets that if you test drive the Network Topology Mapper then you will find a device on your network that you had forgotten about, or someone else installed without you realizing!

Download your 14 day free trial of SolarWinds Network Topology Mapper

Note: This page has been updated here: Logon Scripts in PowerShell 3

Summary of PowerShell Logon Scripts

Although I spent many a happy hour experimenting with old DOS batch files and perfecting the superior VBScript logon scripts, I now realize there are better ways of achieving a task than a PowerShell logon script, start with Group Policy.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell tasks:

PowerShell Home   • Shell Application   • New-Object   • PowerShell Add Printer   • PowerShell -com

PowerShell Logon Script  • Map Network Drive  • PowerShell Create Shortcut  • Free CSV Import Tool

Invoke-Expression   • Invoke-Command   • Invoke-Item   • PowerShell Expression v Command Mode

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2013 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: