New-CimSession not available on Windows 7? - powershell

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.

Related

The term 'oh-my-posh' is not recognized as a name of a cmdlet

I have configured oh-my-posh to be working on powershell and all is working as expected if I run powershell from windows terminal (which is what the document say clearly)
However I tend to run powershell from my WSL terminal as I have alias like this
psl='/mnt/c/Program\ Files/PowerShell/7/pwsh.exe'
but now when I run that alias I got the following error
oh-my-posh: C:\Users\username\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:19
Line |
19 | oh-my-posh init pwsh --config 'C:\Users\username\OneDrive\Documents\Powe …
| ~~~~~~~~~~
| The term 'oh-my-posh' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the
| name, or if a path was included, verify that the path is correct and try again
Any idea ?
Thanks
I tried to change the path but it seems the terminal is not recognize the oh-my-posh
On Windows, validate the location of the executable using Get-Command oh-my-posh and add that to the PATH when starting PowerShell, preferably by adding that to your $PROFILE.
$env:Path += ";/mnt/c/Program\ Files/exact/location/oh-my-posh.exe"
That said, it's discouraged to use the Windows version of oh-my-posh on WSL as that will be slower than a native linux build. Same goes for the Windows version of PowerShell.

get-odbcdsn in Windows 7

Is it possible to run get-odbcdsn in Windows 7?
Powershell in windows 7 does not seem to understand the cmdlet.
PS C:\Windows\system32> get-help "odbc"
get-help : Get-Help could not find odbc in a help file in this session. To download updated help topics type:
"Update-Help". To get help online, search for the help topic in the TechNet library at
http://go.microsoft.com/fwlink/?LinkID=107116.
At line:1 char:1
+ get-help "odbc"
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Get-Help], HelpNotFoundException
+ FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand
I have tried to update-help but it is still not getting any further.
Running Get-odbcdsn caused this error:
Get-OdbcDsn : The term 'Get-OdbcDsn' 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 have updated my powershell in windows 7
PS C:\Windows\system32> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 0 10586 117
How do I run get-odbcdsn in windows 7? Please help.
If get-odbcdsn could not be run in windows 7, is there a way to get around the issue? I need to eventually create odbc connection for 100 workstations, most of them have windows 7 on it. Is there a way to do that through powershell?
As pointed out, the 'Get-ODBCDSN' cmdlet requires Windows 8/Server 2012 or higher.
In lieu of this, you could use the "Configure a Data Source Item" in Active Directory Group Policy to achieve this.
Or failing that, you could add the required registry keys directly under HKLM\SOFTWARE\ODBC\ODBC.INI.
Even if you have updated your version of PowerShell you do not get the addition cmdlets that you would assume would be included.
The reason for that is cmdlet require OS level APIs to be present for them to function, in this case the MSFT_OdbcDsn WMI class that was first introduced in Windows 8 and Server 2012, and are not included in Windows 7 and earlier.

Write-SqlTableData is giving error in 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

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.

How to run get-vm command on windows powershell

I tried run get-vm command on windows powershell. It is throwing this exception:
"Error in script : The term 'Get-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."
but I run same command on system center powershell it's run successful. But i need run on windows powershell. can i run it on windows powershell?
Import the VMM snapin. System Center's Powershell shortcut loads it per default. Vanilla Powershell doesn't.
Use Get-PSSnapin -Registered to list all available snap-ins. The one you are looking for is Microsoft.SystemCenter.VirtualMachineManager
Load the snap-in: Add-PSSnapin -Name Microsoft.SystemCenter.VirtualMachineManager
Get and set default VMM Server: get-vmmserver myVMMServer.VMMServeror use-VMMServer` switch to specify the VMM server the cmdlet is going to interact with.