I need to automate an installation - PowerShell?

oynaz

Platinum Member
May 14, 2003
2,449
3
81
Hi guys,

I need to do a bunch of installations of a SharePoint based archiving system. There is quite a bit of manual work involved, which is a waste of time. This is a good excuse to further hone my coding (well, scripting) skills (see me Epic Android Journey blog thread).

The most annoying part of the installation is creating shares and assigning user rights to them. How would I best go about scripting my way out of this? The only scripting I have done is some basic .bat file creating. I guess PowerShell is a good bet here?
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
powershell is one of the most powerful things MS ever put in windows but they didn't really promote it well enough so mainly just hard core system admins know about it. I love the things it can do , it is the closest to linux type shell scripting as you can get on windows .
If it can be done in windows by a person at the keyboard then powershell can do it. Powershell is basically windows by keyboard vs using the mouse.
 

Doppel

Lifer
Feb 5, 2011
13,306
3
0
powershell is one of the most powerful things MS ever put in windows but they didn't really promote it well enough so mainly just hard core system admins know about it. I love the things it can do , it is the closest to linux type shell scripting as you can get on windows .
If it can be done in windows by a person at the keyboard then powershell can do it. Powershell is basically windows by keyboard vs using the mouse.
What is the best site to get started with it; e.g. some basic decent examples of what it can do?
 

oynaz

Platinum Member
May 14, 2003
2,449
3
81
I forgot something important. I am mucking around on the customers' servers, so my scripts must be able to run natively in Windows, or at most with a very small runtime installation.
 

mikeymikec

Lifer
May 19, 2011
20,992
16,236
136
I use VBS quite a lot. Part of a stock install of Windows probably as far back as Win98 (XP and later have pretty similar versions of VBS, I haven't come across any "Vista/7-only" issues yet.

With VBS you can do quite a few different file-related operations (google for FileSystemObject), though I'm not aware of any to do with permissions. If what you needed to do isn't that clever I would just call a permissions-altering command line program like XCACLS in the script.
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
What is the best site to get started with it; e.g. some basic decent examples of what it can do?

This one has a lot of tips.
http://powershell.com/cs/blogs/tips/

A few I use :

Get free space of all drives
Code:
Get-WMIObject Win32_LogicalDisk | Foreach-Object { 
  'Disk {0} has {1:0.0} MB space available' -f $_.Caption, ($_.FreeSpace / 1MB) }

Shutdown a remote computer
Code:
$os = Get-WmiObject Win32_OperatingSystem -computerName 10.10.10.10
$os.Win32Shutdown(6,0)


Use BITS to download, bits is the service windows uses for updates, it resumes automatically if the system resets, powers off, until the download completes. Last line Get-BITS will let you know if it finished.
Code:
Import-Module BitsTransfer
Start-BitsTransfer http://downloads.sourceforge.net/project/boost/boost-docs/1.47.0/boost_1_47_pdf.zip `
  $home\boost_1_47_PDF.zip -async

Get-BITSTransfer | Format-List *


List all hotfixes installed
Code:
Get-Hotfix


Clear the recently used list
Code:
Dir ([Environment]::GetFolderPath("Recent"))
Del "$([Environment]::GetFolderPath("Recent"))\*.*"
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
I use VBS quite a lot. Part of a stock install of Windows probably as far back as Win98 (XP and later have pretty similar versions of VBS, I haven't come across any "Vista/7-only" issues yet.

I have VBS blocked on all computers. It is one of the main tools that malware uses and very little legitimate software relies on it.
 

mikeymikec

Lifer
May 19, 2011
20,992
16,236
136
I can't remember the last time I saw malware using VB scripts - why bother when it's so easy to get the average user to download an exe.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I can't remember the last time I saw malware using VB scripts - why bother when it's so easy to get the average user to download an exe.

No longer much of an expert on malware, but back when we used to see a lot of VBS exploits one of the advantages was that the VBscript could obfuscate itself by rewriting the code on the fly.
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
I can't remember the last time I saw malware using VB scripts - why bother when it's so easy to get the average user to download an exe.


I see malware weekly that uses it and a lot of the virus generation toolkits rely on it. The normal routine is to take a valid exe file for something like the setup program for winzip. Extract all the files. Add the vbs to the new installer so it executes silently and package it all back up as the winzip setup program. Everything looks legit to the user, but while they are waiting for the setup program to complete the script is disabling registry keys and adding whatever malware to the system . EXE show up in task manager and can trigger UAC prompts. Get your script in with a setup program that the user has clicked ok to for UAC when they run the setup and the user never knows it is being installed. If a user looks at task manager they only see setup.exe.
 

oynaz

Platinum Member
May 14, 2003
2,449
3
81
PowerShell it is. Any tips for a good editor? Free is best, but if there are major advantages to a paid one, I will get my boss to shell out for it.