Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

Unable to Run Powershell Command

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
Member_2_7966113
Asked:
Member_2_7966113
  • 21
  • 9
  • 4
  • +4
3 Solutions
 
Todd NelsonSystems EngineerCommented:
No image or attachement.
0
 
Member_2_7966113Author Commented:
My apologies

Please see image and file.pshell
Regards
Setup-Azure---Copy.txt
0
 
QlemoC++ DeveloperCommented:
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
A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

 
n2fcCommented:
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
 
Member_2_7966113Author Commented:
Qlemo

Thanks for responding.

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

pshell2
0
 
David Johnson, CD, MVPOwnerCommented:
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
 
QlemoC++ DeveloperCommented:
Please note the dot backslash in my code line.
0
 
Todd NelsonSystems EngineerCommented:
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
 
Niten KumarPrincipal Systems AdministratorCommented:
0
 
David Johnson, CD, MVPOwnerCommented:
is D:\Modules in your psmodulepath?
Probably a better location is in c:\iusers\<username>\documents\WindowsPowershell\Modules
0
 
Member_2_7966113Author Commented:
Todd,

I have followed your suggestion, see image below:

pshell3
0
 
Todd NelsonSystems EngineerCommented:
Will you type "dir" so we can see the name of the files in the directory?
0
 
Member_2_7966113Author Commented:
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
 
QlemoC++ DeveloperCommented:
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
 
Member_2_7966113Author Commented:
Hi Nitenkumar,

I think I have it. Installing it now. Will let you know how I get on
0
 
David Johnson, CD, MVPOwnerCommented:
get-module -listavailable
import-module modulename
setup-azure
0
 
Member_2_7966113Author Commented:
Hi,

So I have installed Windows Powershell ISE from Azure,

Please see below for dir and command outputs
pshell4.png
0
 
Todd NelsonSystems EngineerCommented:
Okay.  I suppose you will need to type ".\setup-azure.psm1" for the command to run properly (or at least start.
0
 
Member_2_7966113Author Commented:
David,

Yes, is D:\Modules in my psmodulepath

See attached
pshell5.png
pshell6.png
0
 
Member_2_7966113Author Commented:
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
 
Member_2_7966113Author Commented:
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
 
David Johnson, CD, MVPOwnerCommented:
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
 
Member_2_7966113Author Commented:
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
 
Member_2_7966113Author Commented:
I meant to say how to import the module
0
 
David Johnson, CD, MVPOwnerCommented:
import-module -name modulename
0
 
Member_2_7966113Author Commented:
Can you let me know how to load the module ?

Cheers
0
 
David Johnson, CD, MVPOwnerCommented:
get-help import-module -examples

Open in new window

0
 
SubsunCommented:
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
 
Member_2_7966113Author Commented:
Subsun,

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

Cheers
0
 
Member_2_7966113Author Commented:
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
 
David Johnson, CD, MVPOwnerCommented:
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
 
Member_2_7966113Author Commented:
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
 
David Johnson, CD, MVPOwnerCommented:
where did you get this module? So the experts can follow along with you
0
 
Member_2_7966113Author Commented:
David,


I got it from Microsoft Azure Training Lab.

Thanks
0
 
Member_2_7966113Author Commented:
The full suite of modules looks like...

mods
0
 
Member_2_7966113Author Commented:
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
 
Member_2_7966113Author Commented:
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
 
David Johnson, CD, MVPOwnerCommented:
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
 
SubsunCommented:
+     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
 
Member_2_7966113Author Commented:
Thank you sooooooooooooooo much guys ... Luv EE

Don't know who to assign points to? :-(
0
 
Member_2_7966113Author Commented:
Thanks guys
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 21
  • 9
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now