The command "wmic printer get MarkingTechnology" doesn't show me any value - winapi

I'm trying to get details on the marking technology my printer uses but upon running the "wmic printer get MarkingTechnology" command i just get a blank screen here's a picture of the command prompt displaying the command after being run

I don't know if this source How to get model of printer with POWERSHELL? can help you or not ?
get-wmiobject win32_printer -ComputerName localhost
or
get-wmiobject win32_printer | ft
get-wmiobject win32_printer | ?{$_.ShareName -eq "Printer01"} | fl *
get-wmiobject win32_printer | ft Name,ShareName,DriverName -Autosize

Related

How to get the full list of applications like in control panel

I have been stuck at this stage of my little project.
What I try to do is list the applications that are installed and choose one of the apps to uninstall, the issue I have is that not all the apps appear, so I can't select them. For example Google chrome is not appearing while I'm using it right now to write this question.
I use this function to get all the apps:
Get-WmiObject Win32_Product -ComputerName $ComputerName | Select-Object -Property Name | Out-GridView -Title "All apps on destination Computer"
and this is whole script:
$ComputerName = Read-Host -Prompt 'Input the computer name' # the name of the computer to remove the app from
Get-WmiObject Win32_Product -ComputerName $ComputerName | Select-Object -Property Name | Out-GridView -Title "All apps on destination Computer"
$Name = Read-Host -Prompt 'Input name of the application (has to be exact name)' #name of the application
$Application = Get-WmiObject Win32_Product -ComputerName $ComputerName | Where-Object {$_.Name -eq $Name} #choose the object, this will be the app that we will delete
if ($Application) {
$Application.Uninstall()
"The removal was successful"
}
else {
$Name + ' is not installed on ' + $ComputerName
}
Start-Sleep -Seconds 10
I'm not that good with PowerShell so excuse me if this is a stupid question
Or get-package, which should be faster. Uninstall-package only works on msi providers. Powershell 5.1 only. Metadata['uninstallstring'] has the uninstall string for Programs providers. It can take wildcards and arrays as arguments. Install-package works with msi files, but without any extra options.
get-package

Check if specific programs are installed on a remote server using powershell

I am writing a script where I need to check specific applications if installed or not on a remote server. I am fairly new to PowerShell, but here is the script I have written
ForEach ($computers in $computer){
Get-WMIObject -Class win32_product -Filter {Name like "%Microsoft%"} -ComputerName $computers -ErrorAction STOP | Select-Object -Property Name,Version | export-csv "C:\progrms.csv"
}
The problem I am facing here is I can get details of only Microsoft application which are installed and if I give multiple names for filter parameter like "Microsoft", "SQL", "app1" so on. This script does not seem to work.
Please let me know what has gone wrong and what needs to be done in order to get the list of specific software's that are installed. Also, note that I will be using this script for both Windows 2008 and 2012 servers.
Remove the -Filter {Name like "%Microsoft%"} part of the script to have it return all installed software.
You probably want to be doing ForEach ($computer in $computers) rather than the other way around, assuming you're creating a $computers variable somewhere above this code with the list of computer names.
You also need to -Append to the Export-CSV command as otherwise each computers output will overwrite the output of the previous, however another issue you'll then have is knowing which software comes from which computer. You can address this by using a Calculated Property to add in the computer name to the output, as follows:
ForEach ($Computer in $Computers){
Get-WMIObject -Class win32_product -ComputerName $Computer -ErrorAction Stop |
Select-Object -Property #{N='Computer';E={$Computer}},Name,Version |
Export-Csv "C:\progrms.csv" -Append
}

Get Client ComputerName for Process on Terminal Server

I'm running a script to gather info for running apps on a terminal server. I would like to get the remote ComputerName of the user running the app but I'm only able to get the ComputerName of the Terminal Server instead. Any idea on how I could achieve that? Here's the part of my script to gather the info.
Get-WmiObject Win32_Process -ComputerName MYTSSERVER | Where-Object {
$_.mainwindowhandle -ne 0 -and
$_.Name -eq "WINWORD.exe"
} | Select-Object CSName, ProcessName
You can't get the client hostname or IP address from the Word process, because that process is running locally on the Remote Desktop server. Remote Desktop login information is recorded in the eventlog, so you need to extract it from there. However, you need the remote username for finding the correct logon session, so you still need to run the WMI query first.
Example for a single Word process running on the Remote Desktop server:
$server = '...'
$p = Get-WmiObject Win32_Process -Computer $server -Filter "Name='WINWORD.exe'"
$u = $p.GetOwner().User
$fltr = "*logon type:`t`t`t10*new logon:*account name:`t`t$u"
$addr = Get-EventLog -Computer $server -LogName Security -InstanceId 4624 -Message $fltr -Newest 1 |
Where-Object { $_.Message -match 'source network address:\s*(.*)' } |
ForEach-Object { $matches[1] }
The filter for the eventlog query matches the most recent Remote Desktop login (event ID 4626, logon type 10) of the user who started the Word process (account name:`t`t$u).
That will just give you the client's IP address, though. If you require the hostname you need to resolve it via a reverse DNS lookup or get it from the host itself with another WMI query:
$hostname = Get-WmiObject Win32_OperatingSystem -Computer $addr |
Select-Object -Expand CSName

win32_printer not appear in wmiobject (Windows Power Shell)

I have an issue on a PC with Windows 7 Professional. I need to list the network printers in my local network, I tried to run the list object classes in PowerShell with the command:
Get-WMIObject -List | where {$_.name -match 'win32_printer'}
This shows empty, any suggestion to fix this problem?
EDIT:
My script for get the network printers is this:
Set-Location -Path C:\; get-WmiObject -class Win32_printer | ConvertTo-Json | Set-Content -Encoding utf8 C:\\xampp\\htdocs\\project\\view\\data\\printers.json
I need to list the printers in a json file, In my PC runs well, but in the PC where i need to run this script fail
Your command list out all WMI classes then filters those classes showing all of them that contain Win32_Printer. It seems that you want use:
Get-WMIObject Win32_Printer
This will list all printers that are connected to your computer (Not all of them that are on your network). Note that it will only show network printer connected to your user account.
If you are looking for all printers on your network you could list all of the queues published in Active Directory
Get-ADObject -Filter "ObjectCategory -eq 'printQueue'"
Note: This command requires the AD module from RSAT

Kill specific powershell window

I am trying to end a powershell window I spawned from a task running as SYSTEM. I don't have the ID of the process since I am launching it through psexec to be able to set the session id. The task and the target powershell process are in different sessions.
I thought it would be simple just to set a window title and then query on the window title but I am running to issues since processes running under the system don't seem to see the window title. For example when I run get-process powershell | format-table -property Name, MainWindowTitle as a user I get:
Name MainWindowTitle
---- ---------------
powershell Administrator: C:\Windows\System32\cmd.exe
powershell My Title
powershell
By when I run the same command under the system account I get:
Name MainWindowTitle
---- ---------------
powershell
powershell
powershell
I am not sure what is going on here. Is there a way to get the MainWindowTitle from the SYSTEM account? If not, is there something else I could query for that would return my powershell window and leave any other powershell processes running?
I am on Window 7 x64
Name Value
---- -----
CLRVersion 2.0.50727.5477
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
If there is something unique about the command line of the process you'd like to kill, maybe you could use something like:
Get-CimInstance Win32_Process -Filter "Name='powershell.exe'" |
Where-Object { $_.CommandLine -match $commandLineToMatch } |
ForEach-Object { Stop-Process -WhatIf -Id $_.ProcessId }
I added -WhatIf for testing purposes.
You need to call the GetOwner() method on the Win32_Process object to get the user that started the process.
Get-WmiObject -Class Win32_Process -Filter "Name='powershell.exe'" | ForEach-Object {
if ($_.GetOwner().User -match 'system') {
$_.Terminate()
}
}

Resources