Starting your programs with different credentials using a Powershell script

I always start the same programs at work. Because I login with a normal user account, I start most of them with my admin credentials. This took me too much time to do at each startup, also because of the hard to type password. So I wrote a Powershell script 🙂 Maybe it can be of some use to you.

I got some trouble starting MMC modules, but got it to work eventually. Using 8dot3 paths to bypass space-in-path problems.

# —————————————————————————–
# Script: Start-Processes.ps1
# Author: Yuri de Jager,
# Date: 2013-11-27
# Keywords: Scripting Techniques, Processes, MMC modules
# comments: Start tools with admin account.
# Start-Process, Get-Content
# YdJ – 2013-11-27
# —————————————————————————–
# First save password in password file. Run only when password changes
# $credentials = Get-Credential
# $credentials.Password | ConvertFrom-SecureString | Set-Content [path to]passwd.txt

$password = Get-Content [path to]passwd.txt | ConvertTo-SecureString
$user = [admin user]
$creds = New-Object System.Management.Automation.PSCredential $user,$password

$systemroot = $env:SystemRoot
$progs = $env:ProgramFiles
$progsx86 = “${Env:ProgramFiles(x86)}”

Start-Process $systemroot\system32\mmc.exe -ArgumentList $systemroot\system32\dsa.msc -Credential $creds -windowstyle Maximized
Start-Process $systemroot\system32\mmc.exe -ArgumentList $systemroot\system32\dfsmgmt.msc -Credential $creds -windowstyle Maximized
Start-Process $systemroot\system32\mmc.exe -ArgumentList $systemroot\system32\dhcpmgmt.msc -Credential $creds -windowstyle Maximized
Start-Process $systemroot\system32\mmc.exe -ArgumentList $systemroot\system32\dnsmgmt.msc -Credential $creds -windowstyle Maximized
Start-Process $systemroot\system32\mmc.exe -ArgumentList $systemroot\system32\Cluadmin.msc -Credential $creds -windowstyle Maximized
Start-Process $systemroot\system32\mmc.exe -ArgumentList C:\Progra~1\UPDATE~1\ADMINI~1\wsus.msc -Credential $creds -windowstyle Maximized
Start-Process $systemroot\system32\mmc.exe -ArgumentList C:\Progra~1\MICROS~3\EXCHAN~1\V14\Bin\EXCHAN~1.MSC -Credential $creds -windowstyle Maximized
Start-Process -FilePath “$progs\ConEmu\ConEmu64.exe” -Credential $creds
Start-Process -FilePath “$progsx86\RobWare\RVTools\RVTools.exe” -Credential $creds
Start-Process -FilePath “$progsx86\Remote Desktop Connection Manager\RDCman.exe” -windowstyle Maximized
Start-Process -FilePath “$progsx86\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe”
Start-Process -FilePath “$progsx86\MICROS~2\Office14\OUTLOOK.EXE” -windowstyle Maximized
Start-Process $systemroot\system32\cmd.exe


Create a VM and do some configuration with PowerCLI

Like so many others, I’ve been trying to up my PowerCLI skills lately. I do this to make my life and that of my colleagues a bit easier and to get the skills needed to up my certification to the VCAP level 🙂

Here’s some code to create a 64-bit Oracle Enterprise Linux VM with virtual hardware version 9 and without floppy. I’ll try to update this post as more settings must or can be made.

Create the VM with 7 disks.

$name = “MyVMName”
New-VM -VMHost MyESXiHost -CD -Name $name -MemoryMB 16384 -NumCPU 1 -Version v9 -GuestId oracleLinux64Guest -Datastore VMFS3 -DiskGB 10,20,30,200,200,200,10 -DiskStorageFormat Thin

Some settings which  are annoying to do with a mouse and also easily forgotten

$vm = Get-VM $name
New-AdvancedSetting -Entity $vm -Name ‘vcpu.hotadd’ -Value ‘true’ -Confirm:$false
New-AdvancedSetting -Entity $vm -Name ‘mem.hotadd’ -Value ‘true’ -Confirm:$false
New-AdvancedSetting -Entity $vm -Name ‘svga.autodetect’ -Value ‘true’ -Confirm:$false

This is some code to do the same if the settings have already been configured

$vm | Get-AdvancedSetting -Name ‘vcpu.hotadd’ | Set-AdvancedSetting -Value ‘true’ -Confirm:$false
$vm | Get-AdvancedSetting -Name ‘mem.hotadd’ | Set-AdvancedSetting -Value ‘true’ -Confirm:$false
$vm | Get-AdvancedSetting -Name ‘svga.autodetect’ | Set-AdvancedSetting -Value ‘true’ -Confirm:$false

Change NIC and SCSI controller type

Get-VM $vm | Get-CDDrive | Set-CDDrive -ISOPath “[VMFS1] ISO\oel_6.4_boot.iso” -StartConnected $true -Confirm:$false
Get-VM $vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName Vlan126 -Confirm:$False
Get-VM $vm | Get-NetworkAdapter | Set-NetworkAdapter -Type VMXNet3 -Confirm:$False
Get-VM $vm | Get-ScsiController | Set-ScsiController -Type ParaVirtual

Add the last 4 disks to a seperate SCSCI controller

$disks = Get-Harddisk -VM $vm | Select -Last 4
New-ScsiController -Type ParaVirtual -Harddisk $disks

Start the VM

Start-VM $vm

That’s it for now. Comments are welcome.

%d bloggers like this: