Importing Azure Rm gives me an error - powershell

I have a windows 7 Professional SP1 machine and have installed the windows azure poweshell version 3.7.0 and also have installed the azure rm successfully. But whenever i am trying to import the Azure Rm via the admin login i get the following error
PS C:\Users\swagh> Import-Module AzureRM
Import-Module : File C:\Program Files\WindowsPowerShell\Modules\AzureRM\4.2.1\AzureRM.psm1 cannot b
its operation is blocked by software restriction policies, such as those created by using Group Pol
At line:1 char:1
+ Import-Module AzureRM
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [Import-Module], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
I have tried several ways, uninstalling and reinstalling etc...but failed. Can anyone please help me?

The answer is right there in the error message, though it's not copied completely from the Powershell console:
Import-Module : ...
its operation is blocked by software restriction policies, such as those created by using Group Pol
This means that a domain SRP prevents you loading the module. Contact your domain administrator to discuss SRP settings.

To fix this you need to change the execution policy by this simple command:
PS c:> Set-ExecutionPolicy RemoteSigned
then reply Y(yes) to the popup to change setting. Now try running again the import command, it will run:
PS c:> Import-Module AzureRM
this worked for me , i hope it helps you too

Related

I am getting "PackageManagement\Install-Package : Access to the cloud file is denied" errors while installing Az module in power shell

I am trying to install Az module on windows power shell by "Install-Module -Name Az -Scope CurrentUser -Force -Allowclobber command". But i am getting below error.
PS C:\WINDOWS\system32> Install-Module -Name Az -Scope CurrentUser -Force -Allowclobber
PackageManagement\Install-Package : Access to the cloud file is denied
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:9711 char:34
+ ... talledPackages = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.RemoveItemCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.Instal
lPackage
I searched and found some issue is with onedrive sync activated in my system. Can you please help me on this to install Az module in powershell.
I think the reason is PowerShell Gallery is blocked by the firewall. Anyway, try installing it using MSI. It worked for me.
I tried to install the latest release of the Az module and it worked Az 6.0.0.
Used the below link for reference.
https://github.com/Azure/azure-powershell/releases
See if/where you have Az module installed already using this command
Get-Module -ListAvailable
I found az installed in onedrive/documents/WindowsPowershell, and removed it by deleting the package manually.
Once deleted, I tried the install command again. That helped me.
To your question, I guess you'll have to check the PATH variable I guess, for you to avoid packages being installed in OneDrive(Happens probably when you run powershell with normal user rather than when run as admin).
This is a security measure that decides which scripts can be run. The execution policy has four main configurations:
Restricted This configuration, which is the default, doesn’t allow you
to run scripts.
AllSigned This configuration allows you to run only scripts that have
been cryptographically signed by a trusted party
RemoteSigned This configuration allows you to run any script you
write, and any script you download as long as it’s been cryptographically signed by a trusted party.
Unrestricted This configuration allows you to run any scripts.
Solution:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force
NOTE:
The solution above was dependent for my use case, yours may slightly be different from mine so apply extreme caution before using the solution provided.

Why am I getting this error in PowerShell even though the CMDpath I entered is correct?

I was trying these power forensics command from the powerforensics website the 1st two commands worked perfectly while the next 3 commands gave errors, I am sharing one of the errors below. Please tell me the solution to get rid of this error. enter image description hereWhat's wrong with the path of the cmd?
Command - PS C:> Get-ForensicFileRecord -Path C:\Windows\system32\cmd.exe
Error: Get-ForensicFileRecord : Path C:\Windows\system32\cmd.exe not
found. At line:1 char:1
Get-ForensicFileRecord -Path C:\Windows\system32\cmd.exe +
CategoryInfo : NotSpecified: (:) [Get-ForensicFileRecord],
Exception + FullyQualifiedErrorId :
System.Exception,PowerForensics.Cmdlets.GetFileRecordCommand
link which I followed for this tutorial: https://powerforensics.readthedocs.io/en/latest/modulehelp/Get-ForensicFileRecord
PS: This command worked fine in one of my friend's machine but its throwing error for my machine.
You dont have the module installed in your system. It doesn't come by default.
So, what you need to do is below:
#To Find the module
Find-Module -Name *Forensic*
The Module name is actually PowerForensics. So, you can install it using:
Install-Module -Name PowerForensics
Press A, to Confirm All installation.
Then,
#To Import the module
Import-Module PowerForensics
#To Get all the available commands in the module
Get-Command -Module PowerForensics

Powershell doesn't running scripts even after setting execution policy

I am trying to run virtualenv script to activate it on powershell using:
.\env\Scripts\activate.ps1
but I get this error:
.\env\Scripts\activate.ps1 : File C:\Users\user\Desktop\tranning\env\Scripts\activate.ps1 cannot be loaded because running scripts is disabled on this
system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\env\Scripts\activate.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
I read this article and I tried to solve this by running powershell as administrator and type this command:
Set-ExecutionPolicy RemoteSigned
but unfortunately nothing change
According to this earlier asked question there are a few other things you can try:
PowerShell says "execution of scripts is disabled on this system."
To summarize from the link:
If you are running from a windows server make sure you set the execution policy on all versions of powershell that you have on the system(both x64 x86 versions of powershell)
OR
Run the following to bypass the Execution Policy:
powershell -ExecutionPolicy ByPass -File script.ps1

'Set-AzureRmDataFactoryV2' is not recognized as the name of a cmdlet

I have installed Powershell 6.0.0 on Ubuntu 16.04. I am getting following error when trying to create Azure Data Factory using Powershell
Set-AzureRmDataFactoryV2 : The term 'Set-AzureRmDataFactoryV2' 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:16
+ $DataFactory = Set-AzureRmDataFactoryV2 -ResourceGroupName $ResGrp.Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-AzureRmDataFactoryV2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Then I tried to install the module and getting the following error
Install-Module AzureRM -AllowClobber
Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y
PackageManagement\Install-Package : The member 'TypesToProcess' in the module manifest is not valid: Cannot find path '/tmp/787167149/Azure.Storage/.\Microsoft.WindowsAzure.Commands.Storage.Types.ps1xml' because it does not exist.. Verify that a valid value is specified for this field in the '/tmp/787167149/Azure.Storage/Azure.Storage.psd1' file. At /opt/microsoft/powershell/6.0.0/Modules/PowerShellGet/1.6.0/PSModule.psm1:2057 char:21 + ... $null = PackageManagement\Install-Package #PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (/tmp/787167149/...re.Storage.psd1:String) [Install-Package], Exception + FullyQualifiedErrorId : Modules_InvalidManifest,Microsoft.PowerShell.Commands.TestModuleManifestCommand,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Currently, Set-AzureRmDataFactoryV2 cmdlet is not supported on Linux. AzureRM.NetCore supports following services.
Virtual Machine
App Service (Websites)
SQL Database
Storage
Network
More information please refer to this official document.
If possible, I suggest you could use Azure CLI.
I have solved this issue in my machine by updating Az.DataFactory module.
Install/update latest AzureRM.DataFactoryV2 module.
Restart your powershell.
try the above command.
it will work successfully.

Add-PSSnapin Microsoft.Crm.PowerShell not installed error

Trying to script an upgrade for my Dynamics organization following this TechNet blog.
But running into the below error which I understand, but not sure the process to get the PSSnapin onto my system.
PS C:\Program Files\Dynamics SDK\SDK\Bin> Add-PSSnapin Microsoft.Crm.PowerShell
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.Crm.PowerShell' is not installed on this computer.
At line:1 char:1
+ Add-PSSnapin Microsoft.Crm.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Crm.PowerShell:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
First of all, sign in with the Administrator account on your Microsoft Dynamics 365 server.
Then in elevated mode Run
Add-PSSnapin Microsoft.Crm.PowerShell
If you have no registered then use the Use PowerShell cmdlets for XRM tooling to connect to Dynamics 365
You can externally also download the same from GITHUB:
Link provided by theMadTechnician
Hope it helps