How to show all the available options for a PowerShell command? - windows

For example, this command:
get-netadapter -name "WI-FI"
shows my WIFI network adapter's details with 5 columns of information about it.
but if i do this:
(get-netadapter -name "WI-FI").
and then press tab, I can see a whole lot more information about it that show up after the dot.
now this is only a simple example, there are many more commands like that which by default only show a few columns of information.
what is the universal way of showing all of the available information for each command, like all of the available commands that go after the . in the example above and with their output? I want to show them in console in a nice way like with ft -wrap if possible so I can quickly get a general idea of what information is accessible to me to work with.
I use latest version of PowerShell (7.4 preview) and Windows 11
p.s sometimes pressing tab doesn't work, like in this example:
(get-bitlockervolume -MountPoint $env:SystemDrive).
but we can still use ProtectionStatus after the dot

I usually use command | gm (gm is an alias for Get-Member).
In your case you could type get-netadapter -name "WI-FI" | gm. This returns to you the name, the methods, and properties of the returning object.
To output all properties with values: get-netadapter "WI-FI" | Format-List *

Related

check if process is running with only Path provided

I want to check in Powershell if a process is running with only providing the process's path.
As example, the path to the .exe is "C:\Users\Administrator\Desktop\1\hello.exe".
However, there are also multiple .exe's with the same name, just in a different path:
"C:\Users\Administrator\Desktop\1\hello.exe"
"C:\Users\Administrator\Desktop\2\hello.exe"
"C:\Users\Administrator\Desktop\3\hello.exe"
So I can not just do Get-Process "hello".
How can I find out if a process is running by providing a Path, instead of a process name? It also should return the PID of the specific process.
Get-Process sadly does not even shows you the path to the process.
You can filter by Path and select Id:
Get-Process | Where-Object {$_.Path -EQ "C:\Users\Administrator\Desktop\1\hello.exe"} | Select-Object Id
By the way:
Get-Process sadly does not even shows you the path to the process.
It does, if you ask it to (it returns an object like all those commands do, and it has a default selection of properties to list but that doesn't mean you can't access the remaining properties by specifically selecting them):
Get-Process explorer | Select-Object Path
(or use Select-Object * to see all available properties)
It appears you haven't yet understood how PowerShell objects work, so I'd recommend you to check out some tutorials about this topic, for instance this article about selecting and filtering and this one that goes more into detail about the filtering options.

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]

How can i find all windows with a particular _NET_WM_NAME?

I need to set a custom property for all windows which have a particular window name.
I tried to first list all windows with the particular name and the problem i faced was that xprop or xwininfo would only list me details for one instance of that window inspite of multiple windows with the same name being available.
xprop -name 'xyz'
xwininfo -name 'xyz'
Eventually i will be using the below command to set the custom property
xprop -name 'xyz' -f Onkar 8s -set Onkar Hello
Another thing to note is that i dont have access to wmctrl or xdotool
Here is a programmatic approach (in C) :
First, get the window IDs using _NET_CLIENT_LIST property using Atoms and XGetWindowProperty().
Then get the window names using WM_NAME under Atoms, again using XGetWindowProperty(). Now you have the list of all active windows in your system, so you can use strcmp() to check the desired name of the window.
The working code is given here:
https://cboard.cprogramming.com/linux-programming/125534-accessing-windows-x11.html
About XGetWindowProperty()
https://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html
About Atoms:
https://tronche.com/gui/x/xlib/window-information/properties-and-atoms.html

Windows Powershell command line equivalent of dd

I am writing a Powershell script to make a raw copy of a drive and I have been unable to find a way to complete this.
On Linux, I would use 'dd' to perform this copy.
There are a handful of tools that can do this on Windows but none that I can control directly from the command line. (All have GUI interfaces)
Is there a method to make a physical copy of a drive through Powershell?
Thanks.
I've been trying to do this for a while myself and I finally found a good answer.
Git for windows ships with the whole set of GNU core utilities (updated vs what you can find separately) including dd!
Just install Git for Windows or extract the portable version, from there inside of the install directory in git\usr\bin\ you will find the binaries for all of the GNU utils including dd (tested working)
Some further notes on usage in windows since \dev\sda\ isn't a thing:
$DiskDrives = Gwmi Win32_diskdrive | select DeviceID,BytesPerSector,Index,Caption,InterfaceType,Size,TotalSectors,SerialNumber | Out-GridView -OutputMode Multiple -Title 'Select Source Drive(s)'
$BaseOutputPath = 'D:\'
$DiskDrives | %{
. ('C:\Program Files\Git\usr\bin\dd.exe if={0} of={1} bs={2}' -f $_.DeviceID,(-join($BaseOutputPath,(-
join($Env:ComputerName,$_.Index)),'.img')),$_.BytesPerSector)
}
The included filename logic is just a placeholder, you can replace that parenthetical with a call to Read-Host if you want it to prompt you for the filename/path.
It is a bit annoying but you really do have to use WMI as the values returned by Get-Disk don't seem to work.
You might already know that cygwin on Windows supports some Linux commands including dd. I have used it on several occasions to copy disks and load ISOs to USB and it works perfectly.
Windows 10 comes with linux now. Windows Subsystem for Linux. You can enable it as a feature. You can even get WSL 2 with the real kernel in 1903 & 1909: https://devblogs.microsoft.com/commandline/whats-new-in-the-windows-subsystem-for-linux-september-2020/
Get-CimInstance -ClassName Win32_DiskDrive | Format-List -Property DeviceID,BytesPerSector,Index,Caption,InterfaceType,Size,TotalSectors,SerialNumber
Following up #Chirishman answer, for Powershell 7.2, The Gwmi may missing from the powershell.
The alternative command to get the DeviceId and other info is available as above.
Then you can use dd if={DeviceId} of=<target_file>.

Resources