trying to import hyperv not working - powershell

I'm writing a powershell script that will start/stop hyper-v VM's but it gave this message:
The term 'Get-VM' is not recognized as the name of a cmdlet, function,
script file, or operable program
I found this helpful link:
http://social.technet.microsoft.com/Forums/windowsserver/en-US/07decd82-270e-4dd0-b8e8-789d693099dd/powershell-getvm-error?forum=winserverpowershell enter link description here
Then I added import-module HyperV but get this message:
Import-Module: The specified module 'HyperV' was not loaded because no
valid module file was found in any module directory at
c:\scripts\startStopVMShell.ps1
I found a link that was helpful here: Power shell: Import-Module enter link description here
I tried this at the powershell cmd line:
Get-Module -listavailable
But it's not listing HyperV with any spelling.
I'm using Server 2008 R2. How do I get the HyperV module on my server? Or maybe I have it on my server but powershell is looking in the current directory instead of where the module is loaded?

The Hyper-V Module for Windows PowerShell was introduced as part of the Windows Server 2012 OS. There is a CodePlex project under the "same" name that you might be able to port to 2008 R2.
PowerShell Management Library for Hyper-V
Let me know how that goes for you.
Related blog post.

Related

Getting error when I try using Sharepoint Online power shell commands

When I try to execute Powershell command, it gives the error:
Connect-SPOService : The term 'Connect-SPOService' 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.
Tried uninstalling and reiinstalling S P Online Management shell. None of the SPO commands are working.
On my system this came down to a conflicting .dll (different versions) that was found in both the SharePoint PowerShell module folder and the Global Assembly Cache.
I deleted the following file from the GAC:
C:\Program Files\WindowsPowerShell\tmp\Microsoft.SharePoint.Client.Publishing\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Publishing.dll
After that everything was running smoothly. Full details on research leading to this is found here:
https://www.easy365manager.com/the-term-connect-sposervice-is-not-recognized/
Are you using the cmdlet in the SharePoint Online Management Shell or in the PowerShell? If you are using it in PowerShell, still you need to import the module with
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
Besides, ensure you are running the management shell under administrator privilege.
Here is a doc which may be helpful:https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online?view=sharepoint-ps
On mac run the following command:
rm -rf Users/<username>/.local/share/powershell/Modules/Microsoft.Online.SharePoint.PowerShell/16.0.22810.12000/Microsoft.SharePoint.Client.Publishing.dll
PS: replace with username

The specified module ActiveDirectory was not loaded

I have an SSIS job that executes a powershell module that's attempting to pull information from Active Directory. However, when I run the script I get this error:
The specified module ActiveDirectory was not loaded because no valid
module file was found in any module directory
I found this similar question, however they are using Windows Server 2008, whereas I am using Windows Server 2016. I tried to follow the instructions in the question, but I wasn't able to locate neither "Remote Server Administration Tools" nor "Active Directory module for Windows Powershell."
Can you check whether Active Directory Web Services service is running under services?
If not start it and run below command
Get-module -list
You can check whether Active Directory module is listed down.
Run below command to Enable Active Directory module
Add-WindowsFeature RSAT-AD-PowerShell

Import-Module WebAdministration wont load from script but does from command line

I'm coming onto a project that uses PowerShell to script the build. The build makes use of the WebAdministration module to manage the local IIS instance. When I run the build script the following error is thrown when trying to import WebAdministration.
Error: 06/29/2016 17:28:35: At
C:\dev\src\nib-ravendb\build\ConfigureIis.ps1:10 char:1 +
Import-Module WebAdministration + ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
[<<==>>] Exception: The specified module 'WebAdministration' was not
loaded because no valid module file was fo und in any module
directory. ERROR: 1
How ever when I run Import-Module WebAdministration at the PowerShell command line the module is imported and I can use features from it. Subsequently running the build script still fails.
I have IIS 7.5 and PowerShell 4
Does anyone have an idea why this import would be failing in the script but not at the command line, and how to fix it?
For servers you need to install the role Management Tools under Web Server (IIS) to use the WebAdministration module. To see if you have the module available use Get-Module -ListAvailable.
For Windows 7 to 10 you will need to install the feature IIS Management Scripts and tools under Internet Information Services >> Web Management Tools.
You could try manually locating the WebAdministration .psd1 file and then import it. Use $env:psmodulepath to help locate where your modules are stored then run:
Import-Module -Name 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration\WebAdministration.psd1'
If Server 2008 you could try the following but this may not work on 2012 and upwards:
Add-PSSnapin WebAdministration
Note You will need to run the script with administrator rights to be able to load the WebAdministration module with Import-Module or Add-PSSnapin.
Also check that you have PowerShell's execution Policy set to Unrestricted:
Set-ExecutionPolicy unrestricted
You might want to see this Question.
I had the same situation, i've fixed it installing the Windows Feature Web-Scripting-Tools on W2016 Server:
Add-WindowsFeature Web-Scripting-Tools
In the end there was a problem something, possibly chocolatey?, was truncating $env:PSModulePath to the first entry, this is why the script was working if I typed it in but not in the script.
I found it by logging $env:PSModulePath at different points in the scripts that I was running.
I worked around it by reordering the entries in $env:PSModulePath.
Have a look at #Richard's answer for some other good suggestions.
In my case (Windows 10) I was using Powershell 7 and this simply refused to install the WebAdministration module, despite it being present in Windows Features.
Using a previous version of PS: e.g. Developer PowerShell for VS worked.

'Invoke-Sqlcmd' is not recognized as the name of a cmdlet

We have recently started using SQL Server 2012 SP3 and building the SQL server 2012 using a PowerShell script. There is a requirement in our automation process to run multiple database scripts on a db and I have found Invoke-Sqlcmd very reliable until I found this issue.
When I run Invoke-sqlcmd with a proper set of parameters in PowerShell's debug mode on the system on which the SQL server is installed recently, I don't have problem.
PowershellCommand   : Invoke-Sqlcmd -InputFile $sStrJBSPExecRolePath -ServerInstance $sStrSQLName -ErrorAction Stop
But when I execute same query through a PowerShell automation script after rebuilding the same server, I end up getting below error 
The term 'Invoke-Sqlcmd' 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.
I did research online many suggested to Import SQLPS, etc., so for testing I added the below command in my script
get-pssnapin -Registered
Import-Module “sqlps” -DisableNameChecking**
Even after adding the above into the script, I still end up with same error. But when I run the same script manually it runs perfectly fine. I don't understand what is wrong.
PowerShell automation script - This script installs the .Net Framework 3.5, SQL Server 2012, SQL Server 2012 SP3, and then loads the SMO assembly that I use to change SQL settings such as the Max Memory limit of SQL.
Open up PowerShell as an Administrator and install the sqlserver module by Install-Module sqlserver
After the module has installed, the module commands including the Invoke-sqlcmd should be readily available.
You can check the same using Get-Command -Module sqlserver.
If this module is not readily available, you can Import-Module sqlserver after installing it.
This is not a complete solution, but just a work around which is working for me.
When you execute the query from automation the user which is executing that is not having access to the sqlcmd. Execute you command for the directory where your sqlcmd.exe is present.
Just put
CD "C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn".
to get the location for sqlcmd search the location for SQLCMD.exe in the search box.
if not found, you need to install that where it is missing, but in your case I think it is present, you just need to get the location right.
Also you will need set the path variable for the user executing the automation script or else it will only recognize the sqlcmd, but wont execute that.
$env:Path += ";C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\"
you can get this path from you local user for which it is working by $Env:Path

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

I am trying to change company name using 'Set-AdfsGlobalWebContent' of powershell 4.0 .
I am using power-shell ISE but I am not able to get this command.
I am working on windows server 2012 R2
Anybody explain me Why that command is not showing in intelligence? is I am missing something?
after executing this command forcefully it gives "'Set-AdfsGlobalWebContent' is not recognized as the name of a cmdlet" error.
Thanks in Advance !!!
From technet:
To use these cmdlets you must have previously installed the AD FS server role. This can be done using the Add Roles and Features Wizard in Server Manager or optionally, you can use the Install-WindowsFeature AD-Federation-Services cmdlet at a Windows PowerShell prompt to add the role.