I'm on Win10+PS 7.1.
I used the PSSQLITE module v1.1.0 for one or two months, it worked perfectly. I used it even yesterday.
But today it suddenly didn't work.
$db = Get-DefaultSourceDB
$sql = "select * from users"
$result = Invoke-SqliteQuery -DataSource $db -Query $sql
Line |
429 | … $conn = New-Object System.Data.SQLite.SQLiteConnection -ArgumentL …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling ".ctor" with "1" argument(s): "Unable to load DLL 'SQLite.Interop.dll' or one of its
| dependencies: The specified module could not be found. (0x8007007E)"
I didn't touch anything on my PC. I uninstalled then reinstalled the pssqlite module but it didn't help.
I can see the SQLite.Interop.dll is a self-contained dll file in the PSSQLITE module. I see there's code in the module to check the OS version and load the necessary ones.
I have no clue and I've struggled on it for the whole day.
Can you please help?
BTW - this works under PS 5.1 on the same machine(same PSSQLITE version, seperate installation directory) but I have some other stuff didn't work under PS5.1
Here's my environment:
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Related
Below is example variable which once entered into PowerShell Core reports that the type was not found:
[Microsoft.Windows.Appx.PackageManager.Commands.AppxPackage] $test = $null
InvalidOperation: Unable to find type
[Microsoft.Windows.Appx.PackageManager.Commands.AppxPackage].
However once you run the following code:
Get-AppxPackage -PackageTypeFilter Main
Then the previous variable declaration will be just fine (no error):
[Microsoft.Windows.Appx.PackageManager.Commands.AppxPackage] $test = $null
How do I make this type get recognized by PowerShell session without running Get-AppxPackage?
I tried with using namespace Microsoft.Windows and few other namespaces but it doesn't work.
Environment data:
$PSVersionTable
Name Value
---- -----
PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I figured out, at the top of your script add this line:
Add-Type -AssemblyName Microsoft.Windows.Appx.PackageManager.Commands
Now we can use all the types from that assembly:
[Microsoft.Windows.Appx.PackageManager.Commands.AppxPackage] $test = $null
No error.
Reference
I'm trying to get correct screen resolutions from remote computers using Invoke-Command and a PSSession but both methods report one resolution of 1024 x 768. There are two screens, 1920 x 1080 and 1280 x 720. This is not a DPI thing.
Executing the code below (remotely) outputs the below snippet. Executing interactively, the correct resolutions are reported. All the other working methods posted online have the same behavoir.
Output:
PS > Add-Type -AssemblyName System.Windows.Forms
PS > [System.Windows.Forms.Screen]::AllScreens
BitsPerPixel : 0
Bounds : {X=0,Y=0,Width=1024,Height=768}
DeviceName : WinDisc
Primary : True
WorkingArea : {X=0,Y=0,Width=1024,Height=768}
It's surprising nothing in CIM can get these details from MULTIPLE monitors remotely, that I have found. Maybe time for a feature request to beef up some CIM cmdlets in 7.
I guess a workaround could be creating a Scheduled task on all target computers that runs a script locally to output the info to a local file, then use remoting to get the file or data.
If anyone has overcome this, your feedback would be greatly appreciated amongst the rest of us with this roadblock.
PowerShell 7:
Name Value
---- -----
PSVersion 7.0.1
PSEdition Core
GitCommitId 7.0.1
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Windows PowerShell:
Name Value
---- -----
PSVersion 5.1.18362.752
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.752
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Windows 10 Pro
I am not sure if this issue was resolved or not, but I am not able to find any way to get resolution of remote PC via powershell (i.e. using non-interactive session). Hence came up with the logic to get this via registry values :
Note :-
This script is tested with Windows 10 only
This will require remote user to have read access to registry value in variable "$videoRegistryPath"
$videoRegistryPath = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\'
$all_monitor_array_X=#()
$all_monitor_array_Y=#()
$screen_cnt= (Get-CimInstance -Namespace root\wmi -ClassName wmimonitorid -ErrorAction SilentlyContinue | measure )
$NumberOfScreens= $screen_cnt.Count
$allVideoGraphics = Get-ChildItem -Path ($videoRegistryPath).Replace('HKEY_LOCAL_MACHINE','HKLM:')
foreach ($instance in $allVideoGraphics ) {
$allVideoGraphicsChild= Get-ChildItem -Path ($instance.Name).Replace('HKEY_LOCAL_MACHINE','HKLM:')
if ($allVideoGraphicsChild.Property.Contains('PrimSurfSize.cx')) {
$allVideoGraphicsChildProperty = Get-ItemProperty -Path ($allVideoGraphicsChild.Name).Replace('HKEY_LOCAL_MACHINE','HKLM:')
$Screen_X= $allVideoGraphicsChildProperty.'PrimSurfSize.cx'
$Screen_Y=$allVideoGraphicsChildProperty.'PrimSurfSize.cy'
$all_monitor_array_X += $Screen_X
$all_monitor_array_Y += $Screen_Y
}
}
for ($i=0;$i -le ($NumberOfScreens-1);$i++){
[PSCustomObject]#{
Values = $all_monitor_array_X[$i];
Instance = "Monitor_"+($i)+"_x_coordinate";
}
[PSCustomObject]#{
Values = $all_monitor_array_Y[$i];
Instance = "Monitor_"+($i)+"_y_coordinate";
}
}
Hope this will help in this specific requirement to get resolution of remote computer using non-interactive session.
I was attempting to install the lastest VMWare PowerCLI, and I get an error: Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet, function...
Some digging shows that I don't have PowershellGet installed, and all of the documentation/downloads either say "Out of the box", or run install-module to install PowershellGet, as there's not a download available for Windows 10.
I don't have a PowershellGet folder in C:\Program Files\WindowsPowerShell\Modules, but I do have PackageManagement.
Where do I find a download for PowershellGet?
Windows 10 version 1709
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.248
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.248
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Install-Module is built in to PowerShell in Windows 10 so it should be present.
This can occur if the Language Mode is not Full Language. I've experienced this with Constrained Language Mode, but haven't tested the others.
Language Mode is controlled by the variable __PSLockdownPolicy. Constrained Language Mode was designed to limit the functionality available to non-administrator users when used with other products like AppLocker or Device Guard User Mode Code Integrity (UMCI).
More information:
https://blogs.msdn.microsoft.com/powershell/2017/11/02/powershell-constrained-language-mode/
https://blogs.technet.microsoft.com/kfalde/2017/01/20/pslockdownpolicy-and-powershell-constrained-language-mode/
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes
Get-Module -ListAvailable Microsoft*| Select name | Out-String | % {$_ -replace "Name"}|% {$_ -replace "-"}|% {$_ -replace " "} |out-file -filepath .\ModulesbyName_Microsoft.txt
Wait-Event -Timeout 5
Get-Content -Path .ModulesbyName_Microsoft.txt | Import-Module -verbose
Check out the PowerShellGallery and you should find everything you need to install PowershellGet. Also its a nice GUI browser for modules.
I'm having trouble with this command:
gc .\domains.txt | Get-ADDomain
As the name implies, domains.txt contains a list of Active Directory to query (all domains are in the same forest).
If I run it on my Windows 8 machine everything works fine and I get the expected results, instead on a Windows 2008 R2 SP1 member server (not a DC) with WMF 3.0 I get result only from the first domain in the list and for the others:
Get-ADDomain : A referral was returned from the server
If I query a domain in the list with:
Get-ADDomain <Domain name here>
it works fine.
My Workstation
Microsoft Windows 8 Enterprise (6.2.9200) x64
PS D:\Tools\Powershell> $PSVersionTable
Name Value
---- -----
PSVersion 3.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18010
BuildVersion 6.2.9200.16384
PSCompatibleVersions {1.0, 2.0, 3.0}
PSRemotingProtocolVersion 2.2
Server
Microsoft Windows Server 2008 R2 Standard SP1 (6.1.7601) x64
PS C:\Tools\Powershell> $PSVersionTable
Name Value
---- -----
WSManStackVersion 3.0
PSCompatibleVersions {1.0, 2.0, 3.0}
SerializationVersion 1.1.0.1
BuildVersion 6.2.9200.16398
PSVersion 3.0
CLRVersion 4.0.30319.269
PSRemotingProtocolVersion 2.2
Update
If i run on the server:
gc .\domains.txt | %{ Get-ADDomain $_ }
it runs fine
TRACE
trace-command -Name ParameterBinding { "DOMAIN_1","DOMAIN_2" | Get-ADDomain } -PSHost
Server: http://pastebin.com/sRVJHaCU
Workstation: http://pastebin.com/kj3JV6nV
Thanks in advance
I found an article that may help.
http://technet.microsoft.com/en-us/library/ee617224.aspx
From the look of your script you are providing the server using the text file. Is it possible the problem is the Windows 2008 server you are running the PowerShell script on is not in the same domain or the user you are logged in as does not have access to the domains where the other servers are members?
snippet from the above article:
-If the Server parameter is specified and the Credential parameter is not specified:
--The domain is set to the domain of the specified server and the cmdlet checks to make sure that the server is in the domain of the
LocalComputer or LoggedOnUser. Then the credentials of the current
logged on user are used to get the domain. An error is returned when
the server is not in the domain of the LocalComputer or LoggedOnUser.
You might try adding the additional parameters for the Get-ADDomain commandlet such as -Identity, -AuthType, and -Credential
Get-ADDomain [-Identity] [-AuthType { |
}] [-Credential ] [-Server ]
[]
Powershell v3.0 pipe issue
I just tried to run the cmdlet 'gc .\text.txt | Get-ADDomain' from a virtual Server 2008 R2 box that I have. I built a text file in the following format:
Domain1
Domain2
Domain3
One thing to be sure of is that each domain is on it's own line in the text file. I can understand why the one syntax worked when you piped the STDOUT to:
%{ Get-ADDomain $_}
because you are looping through all the information contained in the text file and only have the cmdlet work on a single value at a time. Unfortunately I don't have the RSAT package on my Win 8 desktop, so I can't test from my desktop. Hopefully this helps a little bit.
We are providing scripts to clients that will be working only in Powershell 2.0.
Through command we can ensure that powershell 2.0 is installed like below
$version = Get-host | Select-object Version
But if we provide script how to ensure that they are executing it from Powershell 2.0?
When executing the script , Powershell 2.0 features may give script errors while initiating the script itself.Isn't it?
You can annotate your script with #requires and state that it shouldn't run on anything less than PowerShell v2:
#requires -Version 2.0
(Side note: This is surprisingly hard to find even if you know vaguely that it exists.)
Relying on the host version is not the safest thing to do as the script can be run on hosts that do not have the same host version as PowerShell's version.
The $PSVersionTable variable was added in v2. You can check if the variable exists, if it does you're running v2 and above, you can also check PSVersion.Major property:
if($PSVersionTable)
{
'PowerShell {0}' -f $PSVersionTable.PSVersion.Major
}
else
{
'PowerShell 1'
}
I'd do something like this:
# get version
$ver = $PsVersionTable.psversion.major
# Check to see if it's V2
If ($ver -NE 2)
{"incorrect version - exiting; return}
# Everything that follows is V2
Hope this helps!
Try to use $PSVersionTable
You will get something like:
Name Value
---- -----
CLRVersion 2.0.50727.5456
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1