Powershell script gives wrong Windows Updates information - powershell

I have the below script to detect Windows Updates that are not installed, however it always says IsDownloaded = false, but they are downloaded, I have windows updates set to Download Only. Anyone know why its not returning the correct info?
$updatesession = [activator]::CreateInstance([type]::GetTypeFromProgID("Microsoft.Update.Session"))
$updatesearcher = $updatesession.CreateUpdateSearcher()
$searchresult = $updatesearcher.Search("IsInstalled=0")
$searchresult
I am using windows server 2016.

Related

Selenium, InternetExplorerDriver, ForceCreateProcessApi, timeout or no browser launch?

We've been using Selenium to automate some browser testing in Internet Explorer. On Windows 7 32-bit it works fine. However we're testing it on Windows 10 64-bit and it fails miserably.
Sometimes the browser doesn't even launch
If i change the driver versions, i can get the browser to launch but it hangs on the first page
The issue is only present when I use ForceCreateProcessApi. However I need to use ForceCreateProcessApi in order to use BrowserCommandLineArguments!
The exception is: The HTTP request to the remote WebDriver server for URL http://localhost:16639/session timed out after 60 seconds.
Here is the PowerShell code i use:
$seleniumOptions = New-Object OpenQA.Selenium.IE.InternetExplorerOptions
$seleniumOptions.InitialBrowserUrl = $SiteUrl
$seleniumOptions.ForceCreateProcessApi = $true
$seleniumOptions.BrowserCommandLineArguments = "-k"
$seleniumOptions.IgnoreZoomLevel = $true
New-Variable -Name IEDS -Value ([OpenQA.Selenium.IE.InternetExplorerDriverService]) -Force
$defaultservice = $IEDS::CreateDefaultService()
$seleniumDriver = New-Object OpenQA.Selenium.IE.InternetExplorerDriver -ArgumentList #($defaultservice, $seleniumOptions)
I've tried the following versions (x86 and x64 versions), and none of them work:
2.25.3
3.141
3.9.0
Can anybody advise on how to make this work? I've made sure that TabProcGrowth etc is set according to the documentation.
Thanks.
Try to use a 3.150.1 32-bit driver.
I'm not sure how it looks on PS - but I'm able to run IE with this driver config.
ie: { version: "3.150.1", arch: "ia32" }
Also I have a key for iexplore.exe here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
from this config link

Powershell, Invoke Web-Request Error (just at Windows Server 2012R)

at the moment i am writing some scripts to handle our Backups of our Costumers.
So the backups are running over a Synology Box.
The Script works really fine with Windows 10 and Windows Server 2019.
But i can not start it at WindowsServer 2012R2. And i tried so many things to handle but it didnt work.
$ip = "XXXXXXXXXX"
$u = "XXXXXXX"
$p = "XXXXXXX"
$d = "XXXXXX"
#Session ID auslesen & Authentifizierung
$a = Invoke-WebRequest -UseBasicParsing "http://$ip/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=$u&passwd=$p&session=ActiveBackup&format=cookie"
$ajson = $a.Content
$aobject = ConvertFrom-Json -InputObject $ajson
$s = $aobject.data.sid
At first he shows me the error that he can not handle utf-8, ive updated Powershell to Version 5.1 and now Windows always tells me that the Value of $a is not allowed to be null. It Seems that he cannot receive any session Number. On Windows 10 and Windows Server 2019 it runs perfectly. Please can anybody help me please. Would beeee really nice
Greetings
Yaspo
Edit i got it.
For everybody who got the same problems just go the classic way without
invoke-webrequest
$url = "http://$ip/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=$u&passwd=$p&session=ActiveBackup&format=cookie"
$wc = New-Object System.Net.WebClient
$result = $wc.DownloadString($url)

How to access mdb file in windows10 by powershell?

Following the suggestion that shown in the following link,
I have created a powershell script to access the mdb file.
https://devblogs.microsoft.com/scripting/hey-scripting-guy-can-i-query-a-microsoft-access-database-with-a-windows-powershell-script/
which is:
$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset
$cn.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $path")
However, i have updated my computer to windows 10 (64bit) and installed ACCESS 2016. The powershell script does not working anymore. And it shows that the
Provider = Microsoft.Jet.OLEDB.4.0 is not found.
I have tried to change the Provider = Microsoft.ACE.OLEDB.12.0
But it does not help, as it shows the same error that the provider is not found.
Moreover, I have tried to open it with ACCESS 2016, it also does not help as it shows that can not open the database file that created in previous version.
Please help....
Thanks for whom reply my question.
Finally I got insight and find the answer myself.
I search the provider from Microsoft and find the link below.
https://www.microsoft.com/en-us/download/details.aspx?id=13255
After install the 64bit version, I can use the following code with the Microsoft.ACE.OLEDB.12.0 provider.
$cn = new-object -comobject ADODB.Connection
$rs = new-object -comobject ADODB.Recordset
$cn.Open("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = $path")
If Win 10 OS 64 bits with MS Office 32bits / click2run , use 32bits Powershell ;)

How do I run Invoke-WebRequest cmdlet from third party program?

I have been trying to get this to work via a game control panel TCAdmin.
$ModPg1 = Invoke-WebRequest "http://steamcommunity.com/sharedfiles/filedetails/?id=731604991"
$ModVer1 = ($ModPg1.ParsedHtml.getElementsByTagName('div') | Where{ $_.className -eq 'detailsStatRight' } ).innerText | Select -Last 1
If I run this cmdlet via a program like TCAdmin (or task scheduler), I get the following error....
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
Explorer is installed, and set up. The script works just fine if I run it manually.
My guess is there is a way to get TCAdmin to run the scripts the same way I would as a windows User.
Cant find a way nearly as simple to scrape the info 'm looking for.
As for this...
get TCAdmin to run the scripts the same way I would as a windows User.
For any app to run as a user, that users profile must be used on the host where the code is to be run. You cannot natively run PoSH on a host as another user context. This is not a PoSH issue, it is a Windows User Principal security boundary. There are tools that let you do this. For example SysInternal PSExec and AutoIT. Yet as stated that error is pretty specific. The user profile for Internet Explorer has not been created and that only happens when you use IE at least once.
So, as Adam points, out, use the setting the error message states to use or use your code to start IE at least once.
$SomeUrl = 'https://stackoverflow.com'
$ie = New-Object -com internetexplorer.application
$ie.visible = $true
$ie.navigate($SomeUrl)
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1 } # Wait for IE to settle.
Again, if trying to run this in the context of another user, the two above tools will get you there, but you still have to fire up IE to have a profile for it.

PSImageTools cannot load Wia.ImageFile

I have installed the PowerShellPack on a Server 2008 R2 machine, but am unable to use the PSImageTools module. All image operations yield the error New-Object : Cannot load COM type Wia.ImageFile. I have tried installing the same package on my Windows 7 laptop, and there it works.
I figure this must be because of missing Dll:s on the server, but even copying the wia*.dll files to System32 from the laptop (there are no corresponding files already in place) helps. It is not possible to register the dlls (regsvr32 wiaaut.dll, for instance), that is replied to with "The file failed to load".
So, has anybody successfully used Wia on Windows Server 2008? We're going to run a scheduled powershell script to update the outlook image of our users, so it needs to be able to run on the server.
I get the same error on Windows Server 2008 x64. Tried both x64 and x86 version of PowerShell v2.
As an alternative you might be able to use System.Drawing.Image. Depends on what your script needs to do. Perhaps post some example code.
http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx
Add-Type -AssemblyName System.Drawing
$image = [System.Drawing.Image]::FromFile("C:\pic.bmp")
EDIT: Here's how you can change an image's dimensions:
$pixWidth = 90
$pixHeight = 90
$image2 = New-Object System.Drawing.Bitmap -ArgumentList $image, $pixWidth, $pixHeight
$image2.Save('C:\new_pic.bmp', [System.Drawing.Imaging.ImageFormat]::Bmp)
Found this article after quite a bit of searching:
http://kb.winzip.com/kb/entry/207/
Basically, you need to enable and set to Automatic the "Windows Image Acquisition" service in Windows 2003, or in Windows 2008, install the Desktop Experience feature first, then enable the "Windows Image Acquisition" service and set to Automatic.