Link to home
Start Free TrialLog in
Avatar of Member_2_7966113
Member_2_7966113

asked on

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
Avatar of Todd Nelson
Todd Nelson
Flag of United States of America image

No image or attachement.
Avatar of Member_2_7966113
Member_2_7966113

ASKER

My apologies

Please see image and file.User generated image
Regards
Setup-Azure---Copy.txt
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.
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/
Qlemo

Thanks for responding.

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

User generated image
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
Please note the dot backslash in my code line.
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 ".\"
is D:\Modules in your psmodulepath?
Probably a better location is in c:\iusers\<username>\documents\WindowsPowershell\Modules
Todd,

I have followed your suggestion, see image below:

User generated image
Will you type "dir" so we can see the name of the files in the directory?
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
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!
Hi Nitenkumar,

I think I have it. Installing it now. Will let you know how I get on
get-module -listavailable
import-module modulename
setup-azure
Hi,

So I have installed Windows Powershell ISE from Azure,

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

Yes, is D:\Modules in my psmodulepath

See attached
pshell5.png
pshell6.png
Todd,

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

User generated image
However, I just get the following:

User generated image
Any thoughts why?

Cheers
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.

User generated imageSetup-Azure.txt
SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
David

Thanks.  

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

Cheers
I meant to say how to import the module
import-module -name modulename
Can you let me know how to load the module ?

Cheers
get-help import-module -examples

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Subsun,

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

Cheers
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:

User generated image
Any thoughts
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
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
 

___________________________________________________________________________________________________________________________________________________________________________________________________________
where did you get this module? So the experts can follow along with you
David,


I got it from Microsoft Azure Training Lab.

Thanks
The full suite of modules looks like...

User generated image
Would you happen to know if there is a script that will enable me to load a bunch of modules in one shot?

Cheers
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
 

___________________________________________________________________________________________________________________________________________________________________________________________________________
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you sooooooooooooooo much guys ... Luv EE

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