Write-SqlTableData is giving error in powershell - powershell

I often use Write-SqlTableData on my computer but for some reasons I cant make it work on a different pc. I have tried to do this before:Install-Module SqlServer and Import-Module SQLPs but I still get the error below:
Write-SqlTableData : The term 'Write-SqlTableData' 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.
Is there anything am doing wrong here?

I have upgraded from powershell 4 to 5 and installed (install-module sqlserver) it then worked.
You can also check solution here: Time to Upgrade Windows PowerShell to Version 5.0

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 term 'powershell.exe' is not recognized as the name of a cmdlet in VSTS Task

All of sudden I m getting the error
"2018-08-30T06:19:30.8460321Z ##[error]The term 'powershell.exe' 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.
" while executing PS task in VSTS .
My PS task has simple Write-Host $variable statement, it worked till y'day and something went wrong, tried rebooting target machine, ensured PS is available etc.
Any debugging steps please ?
Just in case somebody gets this error message on a hosted vm. I had the same issue and it was caused by a Pipeline variable called "Path". So just be smarter than me and don't name your variables like that.
This is what you definitely should avoid:
Refer to these steps:
Check Path variable of System variables
By default, there is %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ item, if it isn’t existing, please add related path that contains PowerShell.exe to the Path variable
Restart your machine.
Check the environment variables on the machine - the "Path" variable should have the path to the Windows PowerShell directory in system32
Issue was with Inline PS script, any script error throws .
The term 'powershell.exe' 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.
Created a new release definition and it worked
So I noticed that release definitions created before is not having the same issue but if I add a new VSTS-task for PowerShell (Microsoft version) to a release definition it is unable to recognize powershell. I am wondering whether they pushed a change to the task and it broke something. My agent path directory is correct.
As an alternative, I am using a 3rd party developer's task. https://thinkrethink.net/2016/05/20/using-the-inline-powershell-vsts-task/

New-CimSession not available on Windows 7?

I'm trying to use WMI with PowerShell. In order to connect another computer, I use
$CimSession = New-CimSession -ComputerName 127.0.0.1
But I got an error:
The term 'New-CimSession' 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.
Any ideas?
Windows 7 originally came with PowerShell version 2, whereas the New-CimSession cmdlet was introduced in PowerShell version 3.
You can upgrade your Windows 7 computer (SP1 or higher) to PowerShell version 5.1 (the current version as of this writing) with this download. For an overview of the available upgrade options see here.

Load Sqlanywhere data provider in powershell

In Powershell v5 I'm Trying to load the ianywhere provider dll. I'm getting this loader exception:
 : The term 'Â' 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.
Weird, right?
My load command is
Add-Type -path "C:\Temp\sa\iAnywhere.Data.SQLAnywhere.v4.0.dll"
The ianywhere dll requires accompanying native dlls, which I have placed in the same folder. Those come in two versions, 32bit and 64 bit. I've tried both, and I've tried 32bit powershell and 64bit powershell. My shell is running as admin as well.

Powershell- NewAcceptedDomain Command is not working in not working in visual studio. But it works fine in powershell

I am trying to run this powershell command from visual studio.
My command is
add-pssnapin microsoft.exchange.management.powershell.snapin; New-accepteddomain –name domain123.com –domainname domain123.com
It always give me an error.
The error is:
"The term 'New-AcceptedDomain' 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."
But when i tried this command in powershell it works fine. But every time when i had try to run this command from my code it gives me error that i mentioned above.
IIRC the Exchange snapin is 64-bit therefore it is not available to the 32-bit PowerShell engine hosted in the 32-bit devenv.exe (Visual Studio) process. From the Nuget Package Manager console, execute:
Get-PSSnapin -Registered
To see if the Exchange snapin shows up.