Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Problems with variables

$
0
0

Hello.

So, I've been working with Powershell for about a week.  Finally decided to dive in, and I'm stuck

What I'm trying to do is grab all the services running as a domain account and run that through Get-ADUser to grab some of the properties for that account.  Problem #1 is the script below comes back with the domain appended to the front:  AB\ServiceAccountName

Get-WmiObject -ComputerName $StrComputer Win32_Service | select-object startname | Where-Object {$_.startname -like "AB\*"}

$ServiceAccount=$_.startname

Get-ADUser doesn't like the AB\ in front of the name (or if it does, I'd love to know how).  So, I've looked at stripping off the first three characters, AB\, and passing that to Get-ADUser via this:

$ServiceAccount=$ServiceAccount.Substring(3)

This gives the error:

Method invocation failed because [Microsoft.ActiveDirectory.Management.ADPropertyValueCollection] doesn't contain a method named 'substring'.
At line:6 char:42
+ $serviceaccount=$serviceaccount.substring <<<< (3)
    + CategoryInfo          : InvalidOperation: (substring:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I'm at a loss.  Any help or pointing in the right direction would be greatly appreciated.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>