Solved

Unable to Run Powershell Command

Posted on 2016-10-11
42
58 Views
Last Modified: 2016-10-13
Hello Experts,

This is my first attempt at running Windows Powershell.

Each I run the powershell script setup-azure.psm I get the error shown in the image.

Can someone let me know what could be wrong?

Cheers

Carlton
0
Comment
Question by:Member_2_7966113
  • 21
  • 9
  • 4
  • +4
42 Comments
 
LVL 14

Expert Comment

by:Todd Nelson
Comment Utility
No image or attachement.
0
 

Author Comment

by:Member_2_7966113
Comment Utility
My apologies

Please see image and file.pshell
Regards
Setup-Azure---Copy.txt
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
For security reasons you always need to provide a path of running a .ps1 file. As you are in the correct folder already, just use
.\Setup-Azure.ps1

Open in new window

The file extension is not required but recommended to name here.
0
 
LVL 19

Expert Comment

by:n2fc
Comment Utility
Note:
There is a known issue with PowerShell $env:PSModulePath that can occur when installing from WebPI. If your computer requires a restart due to system updates or other installations, it may cause updates $env:PSModulePath to not include the path where Azure PowerShell is installed. If this occurs, you may see a 'cmdlet not recognized' message when attempting to use Azure PowerShell cmdlets after the installation or upgrade. If this occurs, restarting the machine should fix the problem.

See: https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Qlemo

Thanks for responding.

I ran the script as you suggested but I get the following error message:

pshell2
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
a .psm1 s a module that will be called from a .ps1 (script) post a link to the page that you got this module from
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Please note the dot backslash in my code line.
0
 
LVL 14

Expert Comment

by:Todd Nelson
Comment Utility
Just type "setup-a" and press the tab button to complete the command.  It has to show exactly like this...

.\setup-azure.ps1

with the leading ".\"
0
 
LVL 6

Expert Comment

by:Niten Kumar
Comment Utility
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
is D:\Modules in your psmodulepath?
Probably a better location is in c:\iusers\<username>\documents\WindowsPowershell\Modules
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Todd,

I have followed your suggestion, see image below:

pshell3
0
 
LVL 14

Expert Comment

by:Todd Nelson
Comment Utility
Will you type "dir" so we can see the name of the files in the directory?
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Hi Nitenkumar,

I have logged into the portal with my Windows Azure account. Can you let me know where to go to get the Windows Azure PowerShell Tools.?

Cheers
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
This cannot be the result of tab completion, as you never get a wrong file or cmdlet that way.
The file name you showed now contains a dot isnstead of a dash!
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Hi Nitenkumar,

I think I have it. Installing it now. Will let you know how I get on
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
get-module -listavailable
import-module modulename
setup-azure
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Hi,

So I have installed Windows Powershell ISE from Azure,

Please see below for dir and command outputs
pshell4.png
0
 
LVL 14

Expert Comment

by:Todd Nelson
Comment Utility
Okay.  I suppose you will need to type ".\setup-azure.psm1" for the command to run properly (or at least start.
0
 

Author Comment

by:Member_2_7966113
Comment Utility
David,

Yes, is D:\Modules in my psmodulepath

See attached
pshell5.png
pshell6.png
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Todd,

That worked. However, after entering the command I should be presented with the following

pshell7
However, I just get the following:

pshell8
Any thoughts why?

Cheers
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Member_2_7966113
Comment Utility
Ok, when I run the script without the quotes it appears to be fine, however the script then opens the Setup-Azure.psm1 file in notepad, see attached.

pshell9Setup-Azure.txt
0
 
LVL 78

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 250 total points
Comment Utility
I will reiterate again a .psm1 is a module a .ps1 is a script
load the module then the command will be available.
import module setup-azure

now you can run the command
setup-azure
0
 

Author Comment

by:Member_2_7966113
Comment Utility
David

Thanks.  

Please remember I'm a novice with this.  Can you please let me know the command to the moody the module ?

Cheers
0
 

Author Comment

by:Member_2_7966113
Comment Utility
I meant to say how to import the module
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
import-module -name modulename
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Can you let me know how to load the module ?

Cheers
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
get-help import-module -examples

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 250 total points
Comment Utility
Assuming setup-Azure.psm1 is located in D:\modules\setup-azure\

Open the PowerShell console using Run as Administrator option, and import the module using following command..
Import-Module D:\modules\setup-azure\setup-Azure.psm1

Open in new window


and then run command
Setup-Azure

Open in new window

0
 

Author Comment

by:Member_2_7966113
Comment Utility
Subsun,

Thank you. I will give that a try when I get to my desk.

Cheers
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Subsun,

I have downloaded the modules to a new pc. This time the files are on the C:.

When I execute the command you suggested I get the error shown in the image:

shell1
Any thoughts
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
get-help about_signing

Open in new window


By default scripts are disabled in the execution policy.
set-executionpolicy -executionpolicy remotesigned

Open in new window


Powershell has a huge help index.  Learn how to use it and you will be amazed at how many questions it will answer.  

if you open powershell as an administrator you should periodically run the
update-help

Open in new window

command
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Hi David

We're nearly,

I get the following error after I run Setup-Azure


Which lab do you want to set up? Type a number from 1 - 11:  
The lab you want to set up is: Lab 1

Is this is correct? Y/N?:   The lab to set up is: Lab 1
Start-Transcript : A parameter cannot be found that matches parameter name 'IncludeInvocationHeader'.
At D:\modules\setup-azure\setup-Azure.psm1:40 char:89
+     Start-Transcript -Path "D:\Logs\Setup-Azure-$labnumber.log" -IncludeInvocationHeader <<<<  -Append -Force
    + CategoryInfo          : InvalidArgument: (:) [Start-Transcript], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartTranscriptCommand
 
Lab 1. Introduction to Azure. Setup will remove any current Azure subscription and account details from the current Azure PowerShell session.

Now setting up Lab 1
Removing cached Azure subscriptions and accounts info...
The term 'Remove-SubsAndAccounts' 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 co
rrect and try again.
At D:\modules\setup-azure\setup-Azure.psm1:70 char:27
+     Remove-SubsAndAccounts <<<<
    + CategoryInfo          : ObjectNotFound: (Remove-SubsAndAccounts:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 

Lab 1 setup is complete
Started at 12/10/2016 18:47:57
Ended at 12/10/2016 18:47:57
 
Total elapsed time is 0 minutes
 
Stop-Transcript : This host does not support transcription.
At D:\modules\setup-azure\setup-Azure.psm1:91 char:20
+     Stop-Transcript <<<<
    + CategoryInfo          : NotImplemented: (:) [Stop-Transcript], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StopTranscriptCommand
 

___________________________________________________________________________________________________________________________________________________________________________________________________________
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
where did you get this module? So the experts can follow along with you
0
 

Author Comment

by:Member_2_7966113
Comment Utility
David,


I got it from Microsoft Azure Training Lab.

Thanks
0
 

Author Comment

by:Member_2_7966113
Comment Utility
The full suite of modules looks like...

mods
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Would you happen to know if there is a script that will enable me to load a bunch of modules in one shot?

Cheers
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Hello Experts

Just so you know, we have got past my original problem with running Setup-Azure.

If you could help me figure out why I can't get past the first base when I run the script:

Which lab do you want to set up? Type a number from 1 - 11:  
The lab you want to set up is: Lab 2

Is this is correct? Y/N?:   The lab to set up is: Lab 2
Start-Transcript : A parameter cannot be found that matches parameter name 'IncludeInvocationHeader'.
At D:\modules\setup-azure\setup-Azure.psm1:40 char:89
+     Start-Transcript -Path "D:\Logs\Setup-Azure-$labnumber.log" -IncludeInvocationHeader <<<<  -Append -Force
    + CategoryInfo          : InvalidArgument: (:) [Start-Transcript], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartTranscriptCommand
 
Lab 2. Creating Virtual Networks and Connecting Virtual Networks. Setup will remove any current Azure subscription and account details from the current Azure PowerShell session.

Now setting up Lab 2
The term 'Add-AzureAccount' 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 D:\modules\setup-azure\setup-Azure.psm1:56 char:29
+         2 { Add-AzureAccount <<<<  | Out-Null; Show-Subscription; Choose-Location; Create-Names $labnumber; Create-Storage $storeName $location; Create-VirtualNetwork $labnumber; Create-VM "ClassicSrv1" $
svcName "Server" $location $labnumber 1 "ADATUM-BRANCH-VNET"}
    + CategoryInfo          : ObjectNotFound: (Add-AzureAccount:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The term 'Get-AzureSubscription' 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 cor
rect and try again.
At D:\Modules\Show-Subscription\Show-Subscription.psm1:6 char:34
+     $subs = Get-AzureSubscription <<<<
    + CategoryInfo          : ObjectNotFound: (Get-AzureSubscription:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Cannot index into a null array.
At D:\Modules\Show-Subscription\Show-Subscription.psm1:47 char:53
+         Write-Host "Using the subscription: " $subs[ <<<< 0].SubscriptionName " Id: " $subs[0].SubscriptionId " (Service Management)"
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray
 
The term 'Select-AzureSubscription' 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 D:\Modules\Show-Subscription\Show-Subscription.psm1:48 char:33
+         Select-AzureSubscription <<<<  -SubscriptionName $subs[0].SubscriptionName -Current
    + CategoryInfo          : ObjectNotFound: (Select-AzureSubscription:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The term 'Choose-Location' 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 a
nd try again.
At D:\modules\setup-azure\setup-Azure.psm1:56 char:76
+         2 { Add-AzureAccount | Out-Null; Show-Subscription; Choose-Location <<<< ; Create-Names $labnumber; Create-Storage $storeName $location; Create-VirtualNetwork $labnumber; Create-VM "ClassicSrv1" $
svcName "Server" $location $labnumber 1 "ADATUM-BRANCH-VNET"}
    + CategoryInfo          : ObjectNotFound: (Choose-Location:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The term 'Create-Names' 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 D:\modules\setup-azure\setup-Azure.psm1:56 char:90
+         2 { Add-AzureAccount | Out-Null; Show-Subscription; Choose-Location; Create-Names <<<<  $labnumber; Create-Storage $storeName $location; Create-VirtualNetwork $labnumber; Create-VM "ClassicSrv1" $
svcName "Server" $location $labnumber 1 "ADATUM-BRANCH-VNET"}
    + CategoryInfo          : ObjectNotFound: (Create-Names:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The term 'Create-Storage' 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 an
d try again.
At D:\modules\setup-azure\setup-Azure.psm1:56 char:117
+         2 { Add-AzureAccount | Out-Null; Show-Subscription; Choose-Location; Create-Names $labnumber; Create-Storage <<<<  $storeName $location; Create-VirtualNetwork $labnumber; Create-VM "ClassicSrv1" $
svcName "Server" $location $labnumber 1 "ADATUM-BRANCH-VNET"}
    + CategoryInfo          : ObjectNotFound: (Create-Storage:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The term 'Create-VirtualNetwork' 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 cor
rect and try again.
At D:\modules\setup-azure\setup-Azure.psm1:56 char:161
+         2 { Add-AzureAccount | Out-Null; Show-Subscription; Choose-Location; Create-Names $labnumber; Create-Storage $storeName $location; Create-VirtualNetwork <<<<  $labnumber; Create-VM "ClassicSrv1" $
svcName "Server" $location $labnumber 1 "ADATUM-BRANCH-VNET"}
    + CategoryInfo          : ObjectNotFound: (Create-VirtualNetwork:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
The term 'Create-VM' 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 D:\modules\setup-azure\setup-Azure.psm1:56 char:183
+         2 { Add-AzureAccount | Out-Null; Show-Subscription; Choose-Location; Create-Names $labnumber; Create-Storage $storeName $location; Create-VirtualNetwork $labnumber; Create-VM <<<<  "ClassicSrv1" $
svcName "Server" $location $labnumber 1 "ADATUM-BRANCH-VNET"}
    + CategoryInfo          : ObjectNotFound: (Create-VM:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Removing cached Azure subscriptions and accounts info...
The term 'Remove-SubsAndAccounts' 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 co
rrect and try again.
At D:\modules\setup-azure\setup-Azure.psm1:70 char:27
+     Remove-SubsAndAccounts <<<<
    + CategoryInfo          : ObjectNotFound: (Remove-SubsAndAccounts:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 

Lab 2 setup is complete
Started at 12/10/2016 19:20:33
Ended at 12/10/2016 19:20:33
 
Total elapsed time is 0 minutes
 
Stop-Transcript : This host does not support transcription.
At D:\modules\setup-azure\setup-Azure.psm1:91 char:20
+     Stop-Transcript <<<<
    + CategoryInfo          : NotImplemented: (:) [Stop-Transcript], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StopTranscriptCommand
 

___________________________________________________________________________________________________________________________________________________________________________________________________________
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
I import all modules in my powershell profiles. Drawback is that it takes about 2.5 minutes to load initially
write-output('Enumerating Modules')
$modules = get-module -listavailable
Write-Output ('There are ' + {0} + ' Available' -f $modules.count)
Write-Output ('Hang on While I import modules')
Write-Output ('Importing ' + {0} +' Modules' -f $modules.Count)
if ([System.Windows.Input.Keyboard]::IsKeyDown('Ctrl') -eq $false)
    {
    $counter = 0
    foreach ($module in $modules) 
        { 
        $counter ++
        $total = $modules.Count
        $activity = 'Importing Module: ' + $module.name 
        Write-Progress -Activity $activity `
            -status "Module: $counter of $total" `
            -percentComplete ($counter / $modules.count*100)
        import-module -name $module.Name -erroraction SilentlyContinue -WarningAction SilentlyContinue
        }
        Write-Progress -Activity 'Done' -Completed
    }

Open in new window


in my powershell profiles I use these

documents\windowsposwershell\Microsoft.PowerShellISE_profile.ps1
documents\windowsposwershell\Microsoft.PowerShell_profile.ps1
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 250 total points
Comment Utility
+     Start-Transcript -Path "D:\Logs\Setup-Azure-$labnumber.log" -IncludeInvocationHeader <<<<  -Append -Force
    + CategoryInfo          : InvalidArgument: (:) [Start-Transcript], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartTranscriptCommand
To get rid of Start-Transcript error, you need to have PowerShell 5.0 or later..

To check powerShell version run $host.version from PowerShell console. If it's lower than 5 then upgrade it.

For all other errors, like the expert's said, you need to import all modules provided with the training lab.
To do that, if you have saved all lab module folders inside folder D:\Module, then run following command in PowerShell to add D:\Module to module path
$env:PSModulePath = $env:PSModulePath + ";D:\Module"

Open in new window

Once it's done you can run following command to load all modules..
Get-Module -ListAvailable | ?{$_.path -match "D:\\Module"} | Import-Module

Open in new window

once you complete above command run the Setup-Azure command and see the result.

PS: Modules should be saved as it is, including the folder. Example view of D:\Module folder shown below..
Untitled.jpg
0
 

Author Comment

by:Member_2_7966113
Comment Utility
Thank you sooooooooooooooo much guys ... Luv EE

Don't know who to assign points to? :-(
0
 

Author Closing Comment

by:Member_2_7966113
Comment Utility
Thanks guys
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now