How do I check, at user logon, if a Firefox plugin exists? - firefox

I want to check if the users on our domain have a certain Firefox plugin installed. Maybe we can have a script that checks if the folders created by the plugin exist. And if not raise some sort of alert to the user.
An example of the plugin folder is below. There are randomly generated parts that will probably make it more complicated.
C:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles{random}.{profile name (“default”)}\ {random-id}#jetpack\resources{same random-id}-at-jetpack-pluginname-data\
I have NO clue about Windows scripting, this is the first time I'm even thinking about it
This question is a bit of a "please do it for me" because of 1.

Is this possible? Definitely. I'm not sure the best method, but I'll attack this from the PowerShell angle.
It might be difficult to use PowerShell because you need to verify that everyone has PowerShell installed. If you can verify that, it's a pretty simple request.
Use
$firefoxfiles = Get-ChildItem -Path ($env:appdata + "\Mozilla\Firefox\Profiles") -Recurse
This will give you a list of all the files in that directory... treat all of the code in this answer as an example, you'll certainly have to change it.
if (!($firefoxfiles | Where-Object {$_.Name -eq "PluginFileName"} ) {
...code for pop up...}
There's a ton of samples out there for an error dialog from PowerShell.
Good luck!

Here is some PowerShell that will search the appdata directory for all folders containing that special plugin name. On error, you should alert the user and force them to interact with the alert (the Read-Host). When they continue, you can launch Firefox directly to the installer page.
if(-not(Get-ChildItem "$env:appdata\Mozilla\Firefox" -recurse -include "*#jetpack" | ?{ $_.PSIsContainer }))
{
Read-Host "The Firefox 'jetpack' plugin was not found. You will be redirected to the plugin page now. Please install the 'jetpack' plugin. (press any key to continue)"
& 'path\to\firefox.exe' 'http:\\path.to.plugin.com'
}
The output on the console should look something like
The Firefox 'jetpack' plugin was not found. You will be redirected to the plugin page now. Please install the 'jetpack' plugin. (press any key to continue):

Related

Using Powershell to drive advanced search in Windows Explorer - How to pipe Out-GridView to Windows Explorer?

I have a folder on a remote computer containing security camera video footage. I want to only search the *.mp4 files for those that are created between 2300 and 0600. The code:
$root = "F:\ispy\video\SWVL"
(Get-ChildItem -Path $root) | Where-Object {$_.lastWriteTime.TimeOfDay.Hours -gt 23 -or $_.LastWriteTime.TimeOfDay.Hours -lt 06} | ls | Out-GridView -PassThru
Does this perfectly, and passes the output (file list) to a PowerShell gridview.... BUT, I need the out to show the files in Windows Explorer.
I'm essentially trying to use a PowerShell script as an advanced search filter.
Hoping someone has some ideas. Eventually, I'm planning to use this as a flow -somehow- in power automate and power apps.... but need to crack this first part.
Thanks,
Gregg
AZ
Your use case is not valid. Windows Explorer
You can, in your script, do something like this.. (dropping the call to Out-GridView as it's not needed for your end results)
# find those files
Get-ChildItem -Path 'F:\ispy\video\SWVL' |
Where-Object {
$PSItem.lastWriteTime.TimeOfDay.Hours -gt 23 -or
$PSItem.LastWriteTime.TimeOfDay.Hours -lt 06} |
# copy them to a temp location
Copy-Item -Destination 'SomeTempPath' -Verbose
# open explorer in that location
Invoke-Item -Path 'SomeTempPath'
... then delete that location when you are done.
Windows Explorer-specific search/filtering is only possible in Windows Explorer. So, that means you can only search to get a specific property, then use GUI automation to send that to the Windows Explorer search box.
Otherwise, just skip the script and know this to avoid overcomplicating what you are after.
In Windows Explorer, you can filter the files by date in File Explorer using the date: keyword. You can use this keyword to find files created before, on or after a certain date. You can use the “>” and “<” signs to find files created after or before the given date. “>=” and “<=” also apply here. While you can manually type the date, File Explorer provides a simple calendar that will show up every time you type date: on the search box.
In a script, you'd have to duplicate the aforementioned. Thus capturing the date in your search, opening Windows Explorer and using SendKeys or AutoIT to select the search box and paste the info then sending enter.
Update as per my comment regarding the pop-up calendar. You can do this, in Windows Explorer to filter by date/date ranges
Manually type it in manually, which of course you could GUI automate via SendKeys or AutoIT.
Click the down arrow on any date column.
In the built-in Windows Sandbox on the latest WinOS builds, the popup still works from the Windows Explorer searchbox.
... but not on other host systems.
Update as per our last comments ...
Yet, if you are really trying to send to the Explore serachbox, then this kludge can do it,...
Start-Process -FilePath 'Explorer' 'd:\temp'
Add-Type -AssemblyName System.Windows.Forms
Start-Sleep -Seconds 2
[System.Windows.Forms.SendKeys]::SendWait('+{TAB}'*2)
[System.Windows.Forms.SendKeys]::SendWait('date: 04-Apr-20..11-Jan-21')
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait('{Enter}')
... but warning SendKeys is quirky, timing-wise, etc. Sometimes is works, sometimes it does not.

Windows PowerShell default open location

I have been googling and trying different options but I didn't really find anything useful or that worked.
My question is how to set default open location for windows PowerShell, I want it to always open c:/programming/ folder when I start it from like start menu, instead what it opens now.
I'm using windows 10.
Thnx for help
the usual way to tell PoSh where to start up at is to add a Set-Location line to one of your powershell profile files. i added ...
Set-Location D:\Data\Scripts
... to my CurrentUserCurrentHost file. you can learn more about profiles with ...
Get-Help about_Profiles
you can find your version of the profile i used thus ...
$profile |
Select-Object -Property *
please note that none of these files exist by default. you will likely need to make one. if you do be sure it is a plain text file, not a .doc file! [grin]

PS: Emulate CCleaner "Uninstall" tool to list programs installed on PC

CCleaner contains a tool to list and then uninstall programs on your PC. This list seems to include applications in a more comprehensive way than a walk through the uninstall registry keys. One example of this, is Atom (the Open Source text editor). This program does not appear in the uninstall registry, and is installed in the AppData folder of the user (I'm not aware of a way to install this for all users without building a custom package).
I wrote a script that installs and updates certain software packages on a regular basis. This makes it easy for me to keep them up to date without visiting a dozen or so websites every week or building a custom installer every time I want to update them (they don't auto-update like Chrome or Firefox). Therefore, I need a list that I can create dynamically and use to check for updates and if I need to execute the installer.
So my question is: How do I emulate what CCleaner does when it creates its list of programs for uninstalling -- programmatically? I can execute the GUI and navigate to the uninstall tool and click "save to text file" but that isn't dynamic. Any answer that allows me to capture (in a Powershell script) the same list of applications that CCleaner generates in the uninstall tool will be acceptable.
You can use Get-Package to list installed programs as well. It will list Atom. You may need to combine the registry approach with Get-Package in the case it doesn't show all.
Get-Package | Where-Object name -like *atom*
Name Version Source ProviderName
---- ------- ------ ------------
Atom 1.53.0 Programs
What you are asking for used to be done with Get-CimInstance, but that comes at a cost and as you pointed out is no longer accurate. It used to be a WMI command. Now CIM. It is not a fast command, more on that later.
Get-CimInstance win32_product
The cost is Get-CimInstance can return incomplete data. It also runs a consistency check on all applications and performs automatic and silent repairs. Yes, when you run this command, it automatically runs a consistency check on all applications and performs automatic and silent repairs. That is why this simple command is so slow to report back.
Microsoft's documentation on this: Link Here
So we do not use that anymore, now what? What you are looking for is gathering the information from both 32 and 64 bit installers that looks like this and must be done, I do it first, always.
$installedApplications = #()
$installedApplications+= Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" # 32 Bit
$installedApplications+= Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" # 64 Bit
One caveat to the above is that the above method will return a ton more elements than the Win32_Product command does. It will have things such as Service Packs, Office Updates, Language Packs, etc. You will most likely need to filter out things you aren’t interested in, though you shouldn't have an issue using PowerShell to filter results.
To complete the answer to your question, how do you quantify data from installers regardless of their install location? Specifically finding the userprofile\AppData install information. The good news is these applications have their installation information documented in the registry as well, under HKEY_CURRENT_USER instead of HKEY_LOCAL_MACHINE. What this means is every user's install location information is sitting in the registry hive under their profile, for instance c:\users\inet\NTUSER.DAT.
What else needs to be said about this;
If a user is logged in this can be accessed by any other admin user on the system by using the HKEY_USERS\$ACCOUNT_SID key.
If a user is not logged in, the hive can be manually mounted using REG LOAD
If a user's registry hive is already loaded it cannot be loaded a second time and will give you the obligatory "this file is being used by another process."
So how do we get what you are asking for, which is to replicate the "full install data" for the device, and not just what's in the 32 and 64bit directories?
This is what I use, if one so chooses you can pipe the info to CSV/HTML/etc...
$installedApplications = #()
$installedApplications+= Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
$installedApplications+= Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"
$32BitPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
$64BitPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"
$tigerStripes= Get-CimInstance Win32_UserProfile | Select LocalPath, SID, Loaded, Special | Where {$_.SID -like "S-1-5-21-*"}
$unavailableProfiles = $tigerStripes| Where {$_.Loaded -eq $true}
$availableProfiles = $tigerStripes| Where {$_.Loaded -eq $false}
#Mounted
$unavailableProfiles | % {
$installedApplications += Get-ItemProperty -Path "Registry::\HKEY_USERS\$($_.SID)\$32BitPath"
$installedApplications += Get-ItemProperty -Path "Registry::\HKEY_USERS\$($_.SID)\$64BitPath"
}
#Unmounted
$availableProfiles | % {
#Mount Hive
$Hive = "$($_.LocalPath)\NTUSER.DAT"
if (Test-Path $Hive) {
REG LOAD HKU\temp $Hive
$installedApplications += Get-ItemProperty -Path "Registry::\HKEY_USERS\temp\$32BitPath"
$installedApplications += Get-ItemProperty -Path "Registry::\HKEY_USERS\temp\$64BitPath"
#This lets the hive be unmounted, using a manual Get-Content
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
REG UNLOAD HKU\temp
} else {
Write-Warning "Unable to access registry at $Hive"
}
}
$installedApplications

Invoke Windows copy from PowerShell

I am busy with creating a PowerShell script where a folder needs to be copied to another folder as a part of the script.
For this I would like to use the standard Windows copy interface and leverage from the prompts and selections like “There is already a file with the same name in this location.”, “Do you want to merge this folder”, “Do this for all”, etc. instead of programming this all myself.
I investigated a view directions:
Using the IFileOperation::CopyItem method as e.g. HowTo: Display progress dialog using IFileOperation but I could find any hint of how to embed this in PowerShell
Using Verbs() Copy/Paste but although the example Invoke-FileSystemVerb -Path "C:\TestDir -Verb Cut; Invoke-FileSystemVerb -Path "\\server\share" -Verb Paste” suggests otherwise, I can paste files that are manually copied/cut but could not copy/cut files with using the CmdLet or simply using the Verb.DoIt() method (I suspect this for a security reason).
Simulate a drag-drop?
But could not find any working solution.
Any suggestion how to do this from PowerShell?
I use this to extract from ZIP files which seems to come up with all the prompts and progress bar:
$shell = New-Object -Com Shell.Application
$folder = $shell.NameSpace(“$path\Folder”)
$shell.NameSpace($otherpath).CopyHere($folder)

Copy-Item shortcut fails to copy

I have a list of files I need to put on every new computer my company gets and I have automated it all with PowerShell, but I can't get this last part to work.
This is the command that is not working I'm wanting to put a shortcut in the start_Menu. What I have found out is that in order for myself to put a file in the location it requests administrator permission to copy. My account is an Admin so I just click continue and file will transfer. I want it automated.
Copy-Item G:\Work\BGInfo\updatebginfo.lnk C:\ProgramData\Microsoft\Windows\Start_Menu -Force
Also when I test the file location it comes back false even if I have manually put the shortcut at the location.
Test-Path C:\ProgramData\Microsoft\Windows\Start_Menu\updatebginfo.lnk
So after looking into more of the Developer code from Microsoft I found the answer. According to what I found was to add "" when any code in PowerShell needs to have a space.
Original code:
Copy-Item G:\Work\BGInfo\updatebginfo.lnk C:\ProgramData\Microsoft\Windows\Start_Menu -Force
Correct code:
Copy-Item "G:\Work\BGInfo\updatebginfo.lnk C:\ProgramData\Microsoft\Windows\Start Menu" -Force

Resources