Tuesday, February 28, 2017

PowerShell and PowerCLI - scripted addition to "getting started"

In my first post on Powershell/PowerCLI I had ventured the guess that many of the tasks to setup PowerShell/PowerCLI could be scripted. Today I present the script:



Set-ExecutionPolicy Bypass -force

mkdir $env:userprofile\Documents\WindowsPowerShell

mkdir "C:\PowerCLI codes"

$fixPS = @"

Set-Location "C:\PowerCLI codes"

if (`$psISE)

{

Clear-Host

Write-Host 'You can do this!'

}

"@

$fixPS | Out-File -FilePath $env:userprofile\Documents\WindowsPowerShell\profile.ps1 -Encoding ASCII



You can change the directory for your codes and the startup message, and add or remove things, but this will at least create the proper file to set your working directory, and write all lines to the profile.ps1 file.

So to use this:
1) Find powershell on your computer
2) right click, run as administrator
3) paste and execute. This should not prompt you for any questions
4) close that window
5) Use ISE or powershell like your normally would from now on

Let me know if you found this useful. I needed it since I have several jumpboxes and create new VMs, and figuring out where stuff needs to be changed takes much more time than copy pasting my setup in a script :)

No comments:

Post a Comment