Solved

Unable to Run Powershell Command

Posted on 2016-10-11
42
155 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 15

Expert Comment

by:Todd Nelson
ID: 41839124
No image or attachement.
0
 

Author Comment

by:Member_2_7966113
ID: 41839132
My apologies

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

Expert Comment

by:Qlemo
ID: 41839156
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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 20

Expert Comment

by:n2fc
ID: 41839159
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
ID: 41839164
Qlemo

Thanks for responding.

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

pshell2
0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41839167
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 69

Expert Comment

by:Qlemo
ID: 41839170
Please note the dot backslash in my code line.
0
 
LVL 15

Expert Comment

by:Todd Nelson
ID: 41839173
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
ID: 41839175
0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41839176
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
ID: 41839188
Todd,

I have followed your suggestion, see image below:

pshell3
0
 
LVL 15

Expert Comment

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

Author Comment

by:Member_2_7966113
ID: 41839195
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 69

Expert Comment

by:Qlemo
ID: 41839196
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
ID: 41839197
Hi Nitenkumar,

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

Expert Comment

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

Author Comment

by:Member_2_7966113
ID: 41839204
Hi,

So I have installed Windows Powershell ISE from Azure,

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

Expert Comment

by:Todd Nelson
ID: 41839208
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
ID: 41839209
David,

Yes, is D:\Modules in my psmodulepath

See attached
pshell5.png
pshell6.png
0
 

Author Comment

by:Member_2_7966113
ID: 41839219
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
 

Author Comment

by:Member_2_7966113
ID: 41839231
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 80

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 250 total points
ID: 41839247
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
ID: 41839252
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
ID: 41839257
I meant to say how to import the module
0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41839263
import-module -name modulename
0
 

Author Comment

by:Member_2_7966113
ID: 41839271
Can you let me know how to load the module ?

Cheers
0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41839276
get-help import-module -examples

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 250 total points
ID: 41840267
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
ID: 41840331
Subsun,

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

Cheers
0
 

Author Comment

by:Member_2_7966113
ID: 41840652
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 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41840663
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
ID: 41840711
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 80

Expert Comment

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

Author Comment

by:Member_2_7966113
ID: 41840734
David,


I got it from Microsoft Azure Training Lab.

Thanks
0
 

Author Comment

by:Member_2_7966113
ID: 41840740
The full suite of modules looks like...

mods
0
 

Author Comment

by:Member_2_7966113
ID: 41840744
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
ID: 41840763
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 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41840820
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
ID: 41841051
+     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
ID: 41841827
Thank you sooooooooooooooo much guys ... Luv EE

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

Author Closing Comment

by:Member_2_7966113
ID: 41841837
Thanks guys
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 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