strange behavior with wcf and powershell - powershell

Working with Powershell and web service. With powershell I am running and updating a cirensen form . When the powershell compiles, I am calling back the service request Id and updating one property of the form.
Working fine with powershell.
With web servcie I am getting error:
"A parameter cannot be found that matches parameter name \'eq\'."
Get-SCSMObject -Class $sRClass -filter “ID -eq $serviceRequestId” | Set-SCSMObject -Property Source -Value “Other”

I don't think the -Filter parameter works like that!
Sounds like you probably want to use the Where-Object CmdLet:
Get-SCSMObject -Class $sRClass |
Where-Object {$_.ID -eq $serviceRequestId} |
Set-SCSMObject -Property Source -Value “Other”

Related

Piping parameters into cmdlet

This was done for testing and we have the solution but I would like to dig deeper.
I have a file list.txt that contains names of computers:
name
computer1
computer2
computer3
...
when I try
Import-Csv .\list.txt | Select-Object -property #{n="computername";e={$_.name}} | Get-Service
we get an error "Get-Service : Cannot find any service with service name '#{computername=computer1}'." Which I understand as Get-Service trying to map computername=computer1 to the parameter "name" (name="computername=computer1") even though the parameter "computername" is specified.
My solution was to add the "name" parameter and it works as expected
Import-Csv .\list.txt | Select-Object -property #{n="computername";e={$_.name}} | Get-Service -name *
My question is, why? Get-Service should accept pipeline input byPropertyName and it recognizes computername. Why doesn't it bind it unless I specify another parameter? Neither "name", nor "computername" is required. Also
Get-Service
and
Get-Service -computername "computer1"
both work without specifying "name".

How do I get a list of the servers as well as respective application and version of that very same app to be exported properly into excel?

With this script, I am able to find a specific application on a list of multiple remote devices and determine the version number of the application on their corresponding host system. This is outputted beautifully in the PS window. However, I am having trouble exporting the results properly into excel, that is, I want each property (Name, Version, PSComputerName) to be in a separate column vs all in one column. So far, I've tried the following
$list = Get-Content -Path C:\Users\bob\AppList.txt
$Servers = Get-Content -Path C:\Users\bob\ServerList.txt
foreach ($Serv in $Servers) {
Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_Product -ComputerName $Serv |
Select-Object -Property Name, Version, PSComputerName |
Where-Object -FilterScript { $_.Name -like "*$list*" } |
Export-Csv -Path C:\Users\bob\ServerListResults.csv
}
This resulted in simply just one device's information being extracted while every other cell was empty
I added -append at the very end! Thank you anyways!

create a txt file in PowerShell list of all running services

I am trying to create a txt file in PowerShell that provides a list of services that are running. This what I came up with but it keeps on giving me an error message that says its not valid.
Get-Service | Export-txt -path "C:\Windows\Temp\services.txt"
Get-Service | where {$_.Status -eq "Running"} | Export-txt -path "C:\Windows\Temp\services.txt"
There is no commandlet called Export-txt.
One option is to use Out-File. It uses -FilePath as a parameter (or no named flag).
Get-Service | Out-File -FilePath "C:\Windows\Temp\services.txt"
There is no cmdlet by the name of Export-txt. To get a list of cmdlets you can use, you can think logically and apply that to Get-Command. Running Get-Command will get you a list of all available cmdlets you may use in accordance with your Posh version.
Get-Command *out* returns a list of cmdlets you can send out to something. Same logic applies to Get-Command "Export*".
#This gets you all services
Get-Service | Out-File "C:\Windows\Temp\services.txt"
#This gets you only running services
Get-Service | where {$_.Status -eq "Running"} | Out-File "C:\Tmp.txt"
Use Get-Help Out-File to see how the cmdlet is used and what parameters it accepts. It also lists examples you can use.

Get startup type of Windows service using PowerShell

How can I get the Windows service startup type using PowerShell and not using WMI?
I looked inside the Get-Service command, and it does not provide something to display the "startup type".
With PowerShell version 4:
You can run a command as given below:
Get-Service | select -property name,starttype
WMI is the way to do this.
Get-WmiObject -Query "Select StartMode From Win32_Service Where Name='winmgmt'"
Or
Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='Winmgmt'"
In PowerShell you can use the command Set-Service:
Set-Service -Name Winmgmt -StartupType Manual
I haven't found a PowerShell command to view the startup type though. One would assume that the command Get-Service would provide that, but it doesn't seem to.
You can use also:
(Get-Service 'winmgmt').StartType
It returns just the startup type, for example, disabled.
As far as I know there is no “native” PowerShell way of getting this information. And perhaps it is rather the .NET limitation than PowerShell.
Here is the suggestion to add this functionality to the version next:
https://connect.microsoft.com/PowerShell/feedback/details/424948/i-would-like-to-see-the-property-starttype-added-to-get-services
The WMI workaround is also there, just in case. I use this WMI solution for my tasks and it works.
Once you've upgraded to PowerShell version 5 you can get the startup type.
To check the version of PowerShell you're running, use $PSVersionTable.
The examples below are for the Windows Firewall Service:
For the local system
Get-Service | Select-Object -Property Name,Status,StartType | where-object {$_.Name -eq "MpsSvc"} | Format-Table -auto
For one remote system
Get-Service -ComputerName HOSTNAME_OF_SYSTEM | Select-Object -Property MachineName,Name,Status,StartType | where-object {$_.Name -eq "MpsSvc"} | Format-Table -auto
For multiple systems (must create the systems.txt)
Get-Service -ComputerName (Get-content c:\systems.txt) | Select-Object -Property MachineName,Name,Status,StartType | where-object {$_.Name -eq "MpsSvc"} | Format-Table -auto
Use:
Get-Service BITS | Select StartType
Or use:
(Get-Service -Name BITS).StartType
Then
Set-Service BITS -StartupType xxx
[PowerShell 5.1]
If you update to PowerShell 5 you can query all of the services on the machine and display Name and StartType and sort it by StartType for easy viewing:
Get-Service |Select-Object -Property Name,StartType |Sort-Object -Property StartType
You can also use the sc tool to set it.
You can also call it from PowerShell and add additional checks if needed.
The advantage of this tool vs. PowerShell is that the sc tool can also set the start type to auto delayed.
# Get Service status
$Service = "Wecsvc"
sc.exe qc $Service
# Set Service status
$Service = "Wecsvc"
sc.exe config $Service start= delayed-auto
It is possible with PowerShell 4.
Get-Service *spool* | select name,starttype | ft -AutoSize
screenshot
By default StartType is not shown by Get-Service, but you can always explicitly ask for it:
Get-Service | select StartType,DisplayName | sort StartType,DisplayName
Use Get-Service | Get-Member to see all available fields.

Filter services when calling Get-Service

I did this in the past, and can't remember the correct command (I think I was using instring or soemthign?)
I want to list all the windows services running that have the word 'sql' in them.
Listing all the windows services is:
Get-Service
Is there a instring function that does this?
Get-Service -Name *sql*
A longer alternative would be:
Get-Service | where-object {$_.name -like '*sql*'}
Many cmdlets offer built in filtering and support wildcards. If you check the help files (Get-Help Get-Service -full), you will see
-name <string[]>
Specifies the service names of services to be retrieved. Wildcards are
permitted. By default, Get-Service gets all of the services on the comp
uter.
Required? false
Position? 1
Default value *
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? true
Usually if filtering is built in to the cmdlet, that is the preferred way to go, since it is often faster and more efficient.
In this case, there might not be too much of a performance benefit, but in V2, where you could be pulling services from a remote computer and filtering there would be the preferred method (less data to send back to the calling computer).
You can get all the services that are running and having words sql.
Get-Service | Where-Object {$_.Status -eq "Running"} | Where-Object {$_.Name -like "*sql*"}
If you want more information, see this (not much difference)
http://nisanthkv.blog.com/2012/06/29/get-services-using-powershell
Hope it helps...
Please enter below command:
Get-Service -Name '*<search string>*'
Above answers are great, but this is more useful:
Get-WmiObject -ComputerName <INSERT COMPUTER NAME> -Class Win32_Service | where-object {$_.name -like '*sql*'}
It allows for this query on remote computers.
The Search String might be in either Display Name or Service Name (e.g. searching Service Name for "*SQL*" does not include the SQL Integration Services ...) so I filter both:
get-service | Where-Object {$_.DisplayName -like "*MySearchString*" -or $_.ServiceName -like "*MySearchString*"}