How to deploy a Powershell module in company? - powershell

I have my own Powershell module which I use on many servers. I keep it on a network share which is added on some machines to the PSModulePath variable: \\\Server\Scripts\MyModule\.
This allowed me to always use the latest version of my module on each server and I only had to update a single copy.
Now with Powershell 5 there is an issue. If I have this network path in PSModulePath I can't remote onto this machine.
Enter-PSSession : The term 'Measure-Object' is not recognized as the name of a cmdlet, function, script file, or operab
le 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:1
+ Enter-PSSession Server
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Measure-Object:String) [Enter-PSSession], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
It's a known error and it could be fixed with enabling second hoop.
Is there a better way to deploy a module and keep it always up-to-date then my approach?

Related

MSI install powershell program but no modules available

I installed AutomatedLab.msi from here - https://github.com/AutomatedLab/AutomatedLab/releases
it installed without any errors but there doesn't appear to be any powershell modules available... or it doesn't seem to know where the modules are? Is there anything else that I can do...
PS C:\Users\Administrator\Downloads> Get-LabAvailableOperatingSystem -Path C:\LabSources
Get-LabAvailableOperatingSystem : The term 'Get-LabAvailableOperatingSystem' 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:1
+ Get-LabAvailableOperatingSystem -Path C:\LabSources
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-LabAvailableOperatingSystem:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Is there some special way I'm supposed to install msi executables? Ive tried 'start-process' I've tried "Install-Module MSI" I can't seem to get anything to work.
Any suggestions?

PowerShell does not recognize the command Resolve-DnsName

Error on power shell script,
Import-Module DnsClient
Import-Module : The specified module 'DnsClient' was not loaded because no
valid module file was found in any module directory.
At line:1 char:1
+ Import-Module DnsClient
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (DnsClient:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Resolve-DnsName
Resolve-DnsName : The term 'Resolve-DnsName' 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:1
+ Resolve-DnsName
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Resolve-DnsName:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\aquib> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
Resolve-DnsName is one of the commands added in Windows 8/Windows 2012 and later. By design, it is not available on versions of Windows prior to that regardless of which version of PowerShell you use. The command is unavailable on Windows 7 and Windows 2008 R2 and earlier. Most sources I've read say that the underlying WinAPI functions that the command depends upon were added in Windows 8/2012.
I would recommend using [System.Net.Dns]::GetHostEntry($HostnameOrIP) or one of the other non-obsolete static methods in that class. However, that only works for A, AAAA, and PTR records, and there isn't a class in the .Net Framework CLR for generic DNS requests. You'd have to roll your own or use a third-party library like ARSoft.Tools.Net.

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

Powershell Runbook - The term 'Get-AzureRMWebAppSlot' is not recognized as the name of a cmdlet

I'm trying to switch connection strings of a website to perform DB Failover, as part of HighAvailability. Please suggest if there are any suitable workarounds for the current requirement.
However, the same script which ran on my local machine is not executing while in the Azure portal as a PowerShell Workflow Runbook.
Powershell Code:
Set-AzureRMWebAppSlot -ResourceGroupName $reourceGroupName -Name $WebSiteName -ConnectionStrings $SecnodaryConnectionStrings -Slot $WebSiteSlot
Error:
Set-AzureRMWebAppSlot : The term 'Set-AzureRMWebAppSlot' 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 AppService-DBConnnectionFailoverSwitch:37 char:37
+
+ CategoryInfo : ObjectNotFound: (Set-AzureRMWebAppSlot:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This can be done by adding modules to your automation account under Assets
Assets > Modules > Add a Module
Browse Gallery to find AzureRM.Compute

Import-Module stops working sporadically

I have a problem where Import-Module -Name "./MyAssembly.dll" stops working sporadically. If I restart the computer, everything seems to work as normal for a while, but it's getting really frustrating.
The reason for importing the same module (in different Powershell sessions) is because I'm currently writing a cmdlet using C#, and I start a powershell instance as part of debugging the cmdlet.
The Import-Module command gives me no feedback whatsoever of whether or not the loading succeeded.
PS C:\Source\MyProject> Import-Module -Name "./MyAssembly.dll"
PS C:\Source\MyProject> Get-Stuffz
Get-Stuffz : The term 'Get-Stuffz' is not recognized as the name of a cmdlet, function, script file, or ope
rable 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:1
+ Get-Stuffz
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-Stuffz:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any help or suggestions are welcome.