Azure Cloud Shell Trouble running ps1 Scripts - azure-cloud-shell

In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc.
Any Suggestions, what am I doing wrong.
PS Azure:\> dir
Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
Mode Name
---- ----
. Build_goal.ps1
. Test goal_Files.ps1
. test.ps1
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\> ./test.ps1
./test.ps1 : The term './test.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ./test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./test.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\>

The example below is from Microsoft Docs.
The trick is for the shell to be open in the location that the script is saved.
This will only work if your script doesn't use libraries that are stored on your local device. You may also need to import any modules needed, e.g. AzureAD
# change to your cloud drive fileshare
cd $HOME\clouddrive
# run the script
.\helloworld.ps1
Hello World!

The default directory for Cloud Shell does not seem to allow script running. Copy the script to "$HOME\clouddrive", change to that dir, then run it from there.

Related

How to create Dockerfile in command prompt

Tried to create Dockerfile but not working.I am getting below the error.
Error:
If i tried in command prompt:
C:\Users\admin\D1>touch Dockerfile
'touch' is not recognized as an internal or external command,
operable program or batch file.
If i tried in VS Code terminal:
PS C:\Users\admin\D1> touch Dockerfile
touch : The term 'touch' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:1
+ touch Dockerfile
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (touch:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
How to resolve this issue?
Try vi Dockerfile or vim Dockerfile, if it is installed, it may work
It is not something specific to Dockerfile it will be the same if you will create any file. The reason for that is that you are trying a Linux command in the windows command prompt. If you want to use these commands, you need to have a *nix based tool on your windows machine first. In Powershell, I think the equivalent of touch is New-Item.

Cannot find path because it does not exist

PS D:\> cd gs:\
cd : Cannot find drive. A drive with the name 'gs' does not exist.
PS D:\> Get-GcsBucket
PS D:\> cd gs:\mybucket
Why I can not change drive to gs:\ before Get-GcsBucket?
PS gs:\mybucket> mkdir NewFolder
PS gs:\mybucket> cd .\NewFolder
cd : Cannot find path 'gs:\mybucket\NewFolder' because it does not exist.
PS gs:\mybucket> ls
Name Size ContentType TimeCreated Updated
---- ---- ----------- ----------- -------
NewFolder
Why I can not change directory?
Why I can not change drive to gs:\ before Get-GcsBucket?
Unlike Cmdlets and Functions, Providers and the drives they add can not be discovered until the module they are part of is imported into the current PowerShell session. This can be done explicitly with Import-Module, or implicitly by calling a Cmdlet or Function that is discoverable, such as Get-GcsBucket.
Why are Cmdlets discoverable but drives aren't? Because the module manifest lists the Cmdlets, but does not have an entry for drives, and also because the Cmdlet names are stored in assembly metadata (as attributes) that can be read without loading the assembly, while the drive comes directly from code that can only be run after loading the assembly.
Why I can not change directory?
It looks like a bug, but I have not been able to reproduce it. If you can provide more information, I encourage you to submit an issue on the Google Cloud Powershell issues page.
I'm going to guess this is a bug in the Cloud Tools for PowerShell module.
When you launch PowerShell it loads a manifest file (GoogleCloud.psd1) which provides a declaration for every cmdlet that the module contains. This allows PowerShell to delay loading the actual cmdlets assembly until it is actually needed. And thereby speeding up startup time considerably.
The actual list of which cmdlets are found in the module is determined as part of the build and release process. Some info here.
Anyways, that manifest is not declaring the existence of the Cloud Storage PowerShell provider (the cd gs:\ bits.) So PowerShell doesn't know that it exists until after it loads the GoogleCloud PowerShell module, which is done after you invoke Get-GcsBucket (or I assume any cmdlet in the module) at least once.

Erlang not working with internal Terminal in Visual Studio Code

I am currently having an issue with visual studio code and erlang, I have erlang/OTP installed on my PC, and I have installed the erlang plugin for visual studio code, however I cannot run erlang from the internal terminal window. When I try to I receive this error:
erl : The term 'erl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ erl
+ ~~~
+ CategoryInfo : ObjectNotFound: (erl:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
any help would be appreciated.
From the VS docs
The shell [that is] used [by VS] defaults to $SHELL on Linux and OS X, and %COMSPEC% on
Windows. These can be overridden manually by setting
terminal.integrated.shell.* in settings.
So I would check what the value is of your %COMSPEC% environment variable. Or, you can override %COMSPEC% in the VS settings:
From the VS docs:
Correctly configuring your shell on Windows is a matter of locating
the right executable. VS Code defaults to the %COMSPEC% environment
variable on Windows which typically points to the 32-bit version of
cmd.exe.
Below are a list of common shell executables and their default
locations:
// 64-bit cmd if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe"
// 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
// Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
// Bash on Ubuntu (on Windows)
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
You may also want to check if the path to erlang is in your %PATH% environment variable, and if not add it. Have you ever successfully started up the erlang shell before, e.g. after you installed erlang to test that it was working?
Try the following guide and install erlang
https://www.rose-hulman.edu/Users/faculty/young/CS-Classes/resources/Erlang/index.html

BitBucket and PowerShell

I am very new to BitBucket.Problem is that PowerShell does not recognize git command.What I am trying to do is to Clone.When i copy address to PowerShell and press Return this message shows:
The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spellin
g of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:4
+ git <<<< clone https://B#bitbucket.org/B/firstrepository.git
+ CategoryInfo : ObjectNotFound: (git:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Does anyone know how to solve this?
Thanks in advance!
For posterity purposes I'm going to break out the hidden comment above by #bigyanshr into an answer:
Be sure to install the Git application as described on either this StackOverflow post or the Git 'Getting Started Installing Git' guide. This includes updating your PATH variable to include to your new Git installs 'Git/cmd' folder.

Microsoft.SystemCenter.VirtualMachineManager is not installed on this machine

I want to use get-vm command from powershell.
$my_vm = get-vm -Name MY_VM_NAME
Have error message that
The term 'get-vm' is not recognized as the name of a cmdlet, function,
script f ile, or operable program. Check the spelling of the name, or
if a path was incl uded, verify that the path is correct and try
again.
I found that I need to install Microsoft.SystemCenter.VirtualMachineManager
(how to run get-vm command on windows powershell)
Execute that:
PS C:\Windows\system32> Add-PSSnapin -Name
Microsoft.SystemCenter.VirtualMachineManager
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SystemCenter.VirtualMa
chineManager' is not installed on this machine.
At line:1 char:13
Do I really need to install that huge tool? I don't have enough space on my VM.
http://www.microsoft.com/en-us/download/details.aspx?id=10712
Is it another way to solve issue with get-vm?
Thanks!
You can look in to connecting to the machine that has VMM on it. You can use remoting to do this. You can find some more info about it here: http://windowsitpro.com/scripting/creating-remote-sessions-powershell-20?page=3

Resources