Category Archives: Command

Run a Powershell script (.ps1) from command line

To run a Powershell script from the command line, batch file or task scheduler, use the following:
powershell -command “. ‘%SCRIPT%'”
Note the double quotes (“) followed by single quotes (‘), and the reverse on the end of the line.
powershell –command  “. ‘c:maintenancetuesday.ps1′”
To load a custom powershell console, for example the Exchange Management Shell, use the following:
powershell –PSConsoleFile %PSC1% –command “. ‘%SCRIPT%'”
powershell –PSConsoleFile “c:program filesmicrosoftexchange serverv14binExSchell.psc1” -Command “. ‘c:maintenanceReportMailboxSizeExchange2010.ps1′”

Server 2003 Volume Shadow Copy Command Line (previous versions)

Using Server 2003, with the Server 2003 Resource Kit  (opens new window) installed, you can restore Shadow Copies from the command line with the command volrest.exe

For example, the file in question is:

 \svr2003serverdatasales2013Sales report sep 2013.doc”

Open a command prompt and type:

volrest “\svr2003serverdatasales2013sales report sep 2013.doc”

This gives us a list of the shadow copies available for that document.  Wildcards can also be used. 
EG: we could also have used:

volrest “\svr2003serverdatasales2013*report sep 2013.doc”
volrest “\svr2003serverdatasales2013*report*”
volrest “\svr2003serverdatasales2013*”

The switch /s  searches subfolders as well.  The command below will list all shadow copy files for the share serverdata.

volrest /s “\svr2003serverdata*”

We can see the date time the file was modified, size, and the time the shadow copy was created.

To restore, use the command:

volrest “\svr2003serverdatasales2013sales report sep 2013.doc” /r:\svr2003serverdatasales2013restored”

This will restore all the sales report sep 2013.doc copies available to a subfolder called restored.  If the restored folder doesn’t exist, it will be created.

The files are restored in reverse time order.  Eg: the newest files are created first, and subsequent files are renamed (1), (2), etc.

In the example above, the 287Kb file is called Sales report sep 2013.doc, and the 6Kb file is called Sales report sep 2013(1).doc