Automatically start AWS module when VSCode is started - powershell

Is it possible to have the AWS SDK module loaded once VS Code starts?
Running on OSX, VSCode has the PowerShell extension installed and working.
In a terminal I can type "powershell" and it automatically loads the AWS module because "Microsoft.PowerShell_profile.ps1" has
Import-Module AWSPowerShell.NetCore
Set-DefaultAWSRegion -Region eu-west-1
in there so they are loaded once I start PowerShell.
I was hoping to have the same in VSCode and not having to add these 2 lines inside the PowerShell script(s).

You can add your modules and scripts to launch.json to facilitate this.
More detail can be found at the following link:
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/13/debugging-powershell-script-in-visual-studio-code-part-2/

Related

Powershell started via blueprism does not load installed packages

I am launching PowerShell via blueprism and need to change the expiration date on some users.
I have the packages installed on the machine and can run the code if I open PowerShell outside of the blueprism environment.
Blueprism start location is "C:\Program Files\Blue Prism Limited\Blue Prism Automate"
Local PowerShell starts in network drive "G:" where the packages are installed.
I have tried to change the location, but it does not help.
Elevated permission is not the problem and I have checked that the code works.
This is the error message: Set-ADAccountExpiration : The 'Set-ADAccountExpiration' command was found in the module 'ActiveDirectoryModule', but the module could not be loaded.
EDIT NOTE: I'm launching blueprism via the
application modeler.

VSCode CLI install extension from local file with powershell

I am trying to use PowerShell to install a VSCode extension from a local file (not from the internet).
When I use Start-Process and give the appropriate file path, it opens VSCode, stalls the script, and does not install the extension. When I close VSCode, the script terminates without error, but still the extensions is not installed.
I need the exact syntax to install a VSCode extension from PowerShell silently (no new window).
I've tried just about every syntax variation.
Thanks
Instead of using Start-Process, call the default name for VS Code: code. VS Code has some nice CLI options when you call this, one of which is --install-extension. Heres an example of what you can call in powershell or in a .ps1 script that would do this:
code --install-extension path/to/extension.ts
or if you have made an extension pack to help automate the install of multiple extensions at once:
code --install-extension path/to/extensionPack.vsix

Visual Studio Code import library references for Powershell extension

I have Powershell files in the same folder with a number of helper functions. Unfortunately the Visual Studio Code editor does not recognize those functions when using intellisense. How do I import reference libraries and get VSCode to search those files ?
If you want the code available to intellisense you have to load it into one of two places, either the PowerShell Integrated Terminal or your editor. In your case though, if you need it loaded all the time I would simply dot source those files in the VS Code PS Profile. You can create this simply by going to the PS Integrated Terminal and using New-Item $PROFILE -ItemType File -Force and it will create a Microsoft.VSCode_profile.ps1. Anything you add in that file will get loaded into the editor and PS Integrated Terminal upload startup.
More details on the whole engine and how intellisense works in VS Code...
The reason this works is that the main engine in the PowerShell extension is the PowerShellEditorService. This is the engine that creates the host behind the PS Integrated Terminal, and the PS features you have in the editor itself (e.g intellisense, script analyzer, etc.).
You can see an example of this by adding Import-Module somemodule to a new file in VS Code that has not been loaded into the PS Terminal. It can take a few seconds but after the engine loads the module you will have intellisense for that module. Just like you will your code.
Prior to adding the commands in that editor I verified that the module was not loaded. After adding the import command and then using a command from that module the module gets loaded in the background. You can then see the module was loaded:

How to Connect to Azure from Visual Studio Code Terminal

I have installed the required software and Azure PowerShell cmdlets on local system. I tried to execute a powershell script by connecting to Azure from Visual Studio Code Terminal. Below is the error.
Import-Module Microsoft.Online.SharePoint.PowerShell
function PublishToAzure{
Add-AzureAccount
......
......
}
Error is..
Add-AzureAccount : The handle is invalid
Visual Studio Code Settings:
// Place your settings in this file to overwrite the default settings
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
}
Console of Windows Azure Active Directory Module for Windows PowerShell Properties
Target is:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "Import-Module MSOnline"
System Properties: 64bit Win7 OS
You may connect and manage Azure resources from within VS Code's terminal window by installing Microsoft Azure CLI 2.0. (https://aka.ms/InstallAzureCliWindows).
After CLI 2.0 is successfully installed in your environment, add the CLI 2.0 components to your environment path.
For example, my environment is Windows 10 and VS Code v1.13.0. I successfully ran the CLI 2.0 MSI installer for Windows. In my VS Code terminal session, I add the path to my PowerShell environment via this command:
$Env:Path += ';C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin'
To work within my Azure subscription(s), first I login via the command
az login
Follow the prompts to browse to a URL to complete the login to your Azure account and authorize the CLI session. Additional help on CLI 2.0 commands may be found at this link, https://aka.ms/cli
I know this thread is old and my answer a bit late but I hope this helps someone.
Cheers,
CarnegieJ

How to Import Nuget Module to powershell script [duplicate]

I was trying to use my favorite source control from the Package Manager console in Visual Studio 2010. I had issues described in another topic. For now the best answer is to move all command-line stuff from Visual Studio to bare PowerShell.
But this case the Visual Studio related commandlets are not working. For example, most crucial one — I cannot run Update-Database command from Entity Framework.
Is it possible to register somehow Visual Studio specific commandlets for the current project in PowerShell? Or make PowerShell automatically take current project context from the packages subfolder?
The NuGet PowerShell commands rely on being run from within Visual Studio so will not work outside in the normal PowerShell running from the command line.
You can however use migrate.exe which ships with the EntityFramework NuGet package and use that from the command line to update your database.
As a prototype I put together a way to use NuGet PowerShell commands from the normal PowerShell command line using SharpDevelop. Unfortunately at the moment the EntityFramework NuGet package does not work with SharpDevelop.
Another interesting project is StudioShell which provides a new DTE: drive inside Visual Studio but can also be used outside from the command line. I do not believe it supports NuGet PowerShell commands being run from the normal PowerShell command line.
I can find the NuGet.psd1 file at:
C:\Program Files (x86)\Microsoft Visual Studio
12.0\Common7\IDE\Extensions\5ttpefif.3mk\Modules\NuGet\NuGet.psd1.
However, when you try to load it:
PS> Import-Module $pathToNuGetPsd1 -Force -NoClobber -Scope Global
Import-Module : The name of the current Windows PowerShell host is: 'ConsoleHost'.
The module 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\
Extensions\5ttpefif.3mk\Modules\NuGet\NuGet.psd1' requires the following Windows
PowerShell host: 'Package Manager Host'.
I think we're out of luck. It has to be run from the Package Manager Host and requires things from Visual Studio as stated by Matt.
To solve my problem I used Chocolatey to install NuGet.CommandLine and then used NuGet.bat to do what I needed. It is a little more work and may not work in all cases depending on what you're trying to do.
Chocolatey: https://github.com/chocolatey/chocolatey/wiki/Installation
NuGet.CommandLine:
PS> cinst NuGet.CommandLine
I'm not terribly familiar with the Visual Studio cmdlets, but you can import a module into your PowerShell session by using Import-Module -Name <ModuleName>. You can list the available (aka. "installed") PowerShell modules by using `Get-Module -ListAvailable'.
My guess would be that the Visual Studio cmdlets are contained with its own PowerShell module, but it's quite possible that it's not "installed" to one of the standard locations in $env:PSModulePath. If this is the case, then you might need to locate the module directory and import either the .psd1 or .psm1 file directly, and pass that into: Import-Module -Name <FullPathToModuleFile>.
As an example of the above, take notice of where the Windows Azure PowerShell module is located: http://trevorsullivan.net/2012/06/07/introducing-microsofts-official-windows-azure-powershell-module/
It's under the Program Files directory, and is not immediately available to PowerShell, unless you import the module from its fully qualified path (the .psd1 module manifest file).
Hope this helps.