Share found, but no ShareSecurity - windows

I found a list of Windows shares using this cmdlet:
gwmi -Class win32_share -ComputerName blah
However, when I use the below cmdlet, it does not show the security setting for ALL shares:
gwmi -Class Win32_LogicalShareSecuritySetting -ComputerName blah
I can see the share w/ the missing security via the Server Management console. Can anyone help? thx!
NOTE: There's a huge discrepancy between the number of record returned from win32_share and win32_logicalsharesecuritysetting.

An alternative to using WMI classes directly is to use the SmbShare cmdlets. For example, the following will list all of the share permissions on the local machine (can also work remotely):
Get-SmbShare | Get-SmbShareAccess

Related

Display the remote computer name

This is a script to get the version of an installed software on remote computers.
Is there any way I can show the computer names in the result?
Please check the screenshot.
$pcname1 = 'TestServer1','TestServer2','TestServer3'
Get-WmiObject -Class Win32_Product -ComputerName $pcname1 |
where name -eq 'VMware Tools' |
select Name,Version
Both the obsolete Get-WmiObject cmdlet and its successor, Get-CimInstance,[1] add a .PSComputerName property to its output objects whenever the -ComputerName parameter is used.
Therefore:
$pcnames = 'TestServer1','TestServer2','TestServer3'
Get-CimInstance -Class Win32_Product -ComputerName $pcnames |
Where-Object Name -eq 'VMware Tools' |
Select-Object Name, Version, PSComputerName
[1] The CIM cmdlets (e.g., Get-CimInstance) superseded the WMI cmdlets (e.g., Get-WmiObject) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell (Core) v6+, where all future effort will go, doesn't even have them anymore. Note that WMI still underlies the CIM cmdlets, however. For more information, see this answer.

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
}

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

Powershell Get-Service to show all services executed with specific service account name

How to sort the services under windows 2012r2 with powershell to show only ones executed with service account "...name..." In the enterprise domain environment
You can do that by querying the WMI Win32_Service class using the Get-WmiObject cmdlet.
For example, this will retrieve all the Windows Services that run under the LocalSystem account:
Get-WmiObject -Query "select name, startname from Win32_Service where startname = 'LocalSystem'"
Alternatively, you can retrieve all Windows Services from WMI and filter them in PowerShell using:
Get-WmiObject Win32_Service | where StartName -eq "LocalSystem"

How to pull physical path of a Windows Service using Get-Service command

I need to pull Physical Execution paths of all the Windows Services on a Set of Servers, that run on Win 2k8. As, the powershell version that is shipped with this OS is 2.0, I wanted to use Get-service command instead of Get-WmiObject.
I know that I can pull the physical path using the command given below
$QueryApp = "Select * from Win32_Service Where Name='AxInstSV'"
$Path = (Get-WmiObject -ComputerName MyServer -Query $QueryApp).PathName
I donot want this command to pull the physical path but wanted to use Get-Service command that comes with PS Version 2.0.
Any help would be much appreciated.
Even with PowerShell 3, I don't see a way to get it with Get-Service.
This 1-liner will get you the pathname, albeit with a little less of the preferred "filter left" behavior:
gwmi win32_service|?{$_.name -eq "AxInstSV"}|select pathname
Or, if you want just the string itself:
(gwmi win32_service|?{$_.name -eq "AxInstSV"}).pathname
#alroc did good, but there's no reason to filter all services. Querying WMI is like querying a DB, and you can just ask WMI to do the filtering for you:
(Get-CimInstance Win32_Service -Filter 'Name = "AxInstSV"').PathName
To explore all of the meta available for that service:
Get-CimInstance Win32_Service -Filter 'Name = "AxInstSV"' | Select-Object *
I wanted to do something similar, but based on searching / matching the path of the process running under the service, so I used the classic WMI Query syntax, then passed the results through format-table:
$pathWildSearch = "orton";
gwmi -Query "select * from win32_service where pathname like '%$pathWildSearch%' and state='Running'" | Format-Table -Property Name, State, PathName -AutoSize -Wrap
You're welcome to turn this into a one-liner by skipping defining and passing $pathWildSearch, or you could just back gwmi statement up to continue after the semi-colon.
Perhaps little less verbose,
wmic service where "name='AxInstSV'" get PathName
This should work on command prompt as well, not just powershell.
Or else if you have process name itself you could do:
wmic process where "name='AxInstSV.exe'" get ExecutablePath
To read process path you would need permission, so mostly I have better luck with service name.
I was never able to do this through the Get-Service command but if your service runs as it's own process then you can use the Get-Process command for this via the following code:
(Get-Process -Name AxInstSV).path
Source:
https://blogs.technet.microsoft.com/heyscriptingguy/2014/09/15/powertip-use-powershell-to-find-path-for-processes/

Resources