|
Thanks, I ended up doing it like this:code:
TITTIEKISSER69 fucked around with this message at 19:32 on Jan 22, 2019 |
# ? Jan 22, 2019 19:30 |
|
|
# ? May 15, 2024 03:36 |
|
Instead of code:
code:
edit; the full command: code:
|
# ? Jan 22, 2019 19:35 |
|
The Fool posted:Instead of I always forget the correct syntax for -Filter, thanks for this. I was trying to concoct a much more complicated loop to check the values and make an array, etc. Inspector_666 fucked around with this message at 19:39 on Jan 22, 2019 |
# ? Jan 22, 2019 19:36 |
|
Tried the full command and got "Missing an argument for parameter 'Filter'"
|
# ? Jan 22, 2019 19:42 |
|
Because I was
|
# ? Jan 22, 2019 19:46 |
|
Yeah, I tried removing one then the other but still got errors.
|
# ? Jan 22, 2019 19:48 |
|
Removing the first -Filter works for me. Are you changing the searchbase to match your domain and OU structure? What is the error you are getting?
|
# ? Jan 22, 2019 19:51 |
|
code:
|
# ? Jan 22, 2019 19:54 |
|
I can all but guarantee that your searchbase value is wrong somehow.
|
# ? Jan 22, 2019 20:09 |
|
That was it, I had to change it to "OU=SubOU,OU=TopOU,DC=etc..." Thanks!
|
# ? Jan 22, 2019 20:13 |
|
Inspector_666 posted:
And if you _just_ wanted the number as you originally asked wrap the query in count: (Get-ADUser -Filter yadayada). count
|
# ? Jan 22, 2019 20:27 |
|
Thanks all!
|
# ? Jan 22, 2019 20:57 |
|
On the subject of AD cmdlets it's worth noting that Get-ADObject is always faster than the other Get- cmdlets like Get-ADUser, Get-ADComputer or Get-ADGroup. The only downside with Get-ADObject is that you have to include filters to only return the objects you want whereas it's implied with the other cmdlets. Still, even with the filters Get-ADObject is faster. This doesn't mean much for small stuff but it really adds up when you're dealing with huge directories. code:
code:
|
# ? Jan 23, 2019 13:23 |
|
I'm a complete idiot when it comes to PS. I downloaded a module to get access to a gmail account, and I can't even get the first step to go because I don't understand the syntax.code:
|
# ? Jan 23, 2019 15:34 |
|
CzarChasm posted:I'm a complete idiot when it comes to PS. I downloaded a module to get access to a gmail account, and I can't even get the first step to go because I don't understand the syntax. PSCredential is expecting a credential object. The easiest way to get one is to type the following before your cmdlet. code:
Then use the variable $cred as the value for the -Credential flag.
|
# ? Jan 23, 2019 16:09 |
|
If you need it in an automated way, you can pass your user password into the following to generate a credential object, assuming you can access it locally:code:
|
# ? Jan 23, 2019 16:17 |
|
OK, that's what I'm looking for is the automated bit. Thank you. Also, on the off chance that anyone is looking for using the gmail plugin for PS, you need to get a 16 character security code from the google account, not your standard password.
|
# ? Jan 23, 2019 16:21 |
|
PierreTheMime posted:If you need it in an automated way, you can pass your user password into the following to generate a credential object, assuming you can access it locally: Depending on security concerns, you probably don't want to actually do this in a script since you will be saving your password in plain text.
|
# ? Jan 23, 2019 18:30 |
|
The Fool posted:Depending on security concerns, you probably don't want to actually do this in a script since you will be saving your password in plain text. Absolutely don't hardcode your passwords in plaintext, I didn't mean to imply that. If you have a method to access secured passwords, you can then pass them as shown.
|
# ? Jan 23, 2019 18:33 |
|
Assuming you're talking about this module: https://github.com/nblagoev/Gmail.ps It actually includes some code to read a credential from the Credential manager. It looks like if you create a "generic" type credential under the "Windows Credential" store in Credential manager, and set the address to "mail.ps:default" it'll grab that credential by default every time if you don't specify a credential on the command line. So that's a safe way to save your credentials.
|
# ? Jan 23, 2019 20:59 |
|
Hey thread. Need some help escaping variables.... I'm hella confused by the quotes, single quotes, backtick, etc. I'm running an AWS cli command for each AD group member, and stuck at making it escape $user.SamAccountName What I have: code:
Notes: - the option --workspaces appears to require that the parameters get fed in quoted. If I don't use quotes, it screams about params missing - if I use double quotes for the params for --workspaces, then I get errors about the "WorkspaceProperties" parameter list So, the question is: how do I get the aws cli command to read in the actual $user.SamAccountName?
|
# ? Jan 29, 2019 19:25 |
|
What happens when you double quote --workspaces, but single quote WorkspaceProperties? Is that when you get the error, or were you double quoting both of them? The Fool fucked around with this message at 19:46 on Jan 29, 2019 |
# ? Jan 29, 2019 19:30 |
|
I get acode:
|
# ? Jan 29, 2019 19:36 |
|
Alfajor posted:So, the question is: how do I get the aws cli command to read in the actual $user.SamAccountName? In the WorkspaceProperties, try: code:
|
# ? Jan 29, 2019 19:39 |
if it's looking for a dict @ that @{RunningMode=AUTO_STOP,RunningModeAutoStopTimeoutInMinutes=60,RootVolumeSizeGib=80,UserVolumeSizeGib=50} Anyone have experience using ROBO copy from SMA to remote fileshares? I'm having a bitch of a time. Looking to just get number of files in a specific user's share. Gotta use a PSSession somehow due to rights over the shares.
|
|
# ? Jan 29, 2019 19:39 |
|
slartibartfast posted:In the WorkspaceProperties, try: I had tried that before. Not taking a full screenshot, but this is what AWS CLI is seeing when I do that, it's still passing it literally: code:
|
# ? Jan 29, 2019 19:44 |
|
You can try using the call operator with string concatenation:code:
|
# ? Jan 29, 2019 19:46 |
|
Yeah, I was thinking of going down that route.... so thank you for saving me some time and effort!
|
# ? Jan 29, 2019 19:50 |
|
From About Quoting Rulesquote:When you enclose a string in double quotation marks (a double-quoted string), variable names that are preceded by a dollar sign ($) are replaced with the variable's value before the string is passed to the command for processing. So, if you want to substitute variables into strings while still having " in the string, use " to surround the string and use "" in it. code:
|
# ? Jan 29, 2019 20:23 |
|
Submarine Sandpaper posted:if it's looking for a dict @ that code:
quote:Anyone have experience using ROBO copy from SMA to remote fileshares? I'm having a bitch of a time. Looking to just get number of files in a specific user's share. Gotta use a PSSession somehow due to rights over the shares. I don't know what SMA is and searching was unhelpful. Are you running into problems with the powershell double hop ?
|
# ? Jan 30, 2019 04:34 |
|
I hate PowerShell sometimes. Let's say I have this: code:
code:
code:
code:
Meanwhile, this works correctly: code:
|
# ? Jan 30, 2019 05:55 |
|
I recently joined a team that's trying to remediate thousands of legacy and/or non-standard systems. Two of us are using Powershell to automate software deployments, maintenance, and updates. Thanks to the nature of the environment we have a random mix of 32- and 64-bit systems and have to push and invoke different installers for each. This morning the other scripture asked how I was detecting processor architecture. It turns out, his way code:
A quick code:
|
# ? Jan 30, 2019 05:59 |
|
code:
|
# ? Jan 30, 2019 06:38 |
thebigcow posted:
Turns out permissions are the issue. SMA is service manager automation. To my understanding it's like in house azure.
|
|
# ? Jan 30, 2019 14:24 |
|
New Yorp New Yorp posted:I hate PowerShell sometimes. So I had a mini-rant here talking about how I somewhat agreed with you, but most of the time when you are piping stuff you want to operate on the members of the collection so we'll just have to deal... and then I discovered the unary , operator. code:
|
# ? Jan 30, 2019 18:21 |
|
Edit: an explanation of the difference between unary , and @() https://blogs.msdn.microsoft.com/powershell/2007/01/23/array-literals-in-powershell/ True edit: Quote -ne edit
|
# ? Jan 30, 2019 18:34 |
|
Jethro posted:So I had a mini-rant here talking about how I somewhat agreed with you, but most of the time when you are piping stuff you want to operate on the members of the collection so we'll just have to deal... and then I discovered the unary , operator. That's good to know. It's just unintuitive. Like, if we're saying we want to operate on members of the array, fine. If @( @{ a = 'b' }) gives me { "a": "b" }, I would expect @( @{ a = 'b' }, @{ c = 'd' }) to give me an array with index 0 being { "a": "b" } and index 1 being { "c": "d" }. That makes sense and logically follows with your explanation that we're operating on members of the collection, not the entire collection. But that's not what happens. The second case gives you a string with [ { "a": "b", "c": "d" } ]. That's not the only place the behavior pops up. Where-Object will also engage in shenangians where a single result is just the result, but multiple results are an array of the results. It's easy enough to deal with, but it's just a constant footgun unless you boilerplate every Where-Object by wrapping the results in @(). New Yorp New Yorp fucked around with this message at 19:19 on Jan 30, 2019 |
# ? Jan 30, 2019 19:15 |
|
I agree it's somewhat unintuitive, but it also makes sense when we remember that Powershell is first and foremost designed to be a shell script environment. In that sort of environment, most of the time (especially when you're piping stuff around) you want to do stuff to the stuff in the collection, not to the collection itself. So to help you with this, when you ask Powershell to evaluate an array, it returns the members of the array. @( @{ a = 'b' }, @{ c = 'd' }) as a statement all by itself essentially says "create an array with two hashtables, then return the individual hashtables." Then there's something else that Powershell does that is usually helpful, but also may be somewhat unintuitive. When you are piping things along, the cmdlets and functions have begin, process, end blocks, so it can do something at the start (like create the object that will be converted to JSON), do something for each item in the pipeline (like add it to the object (while also being smart about adding the members of hashtables as members of the object instead of adding the hashtables themselves)), and then do something at the end when all the processing is done (like return one JSON representation). So, if you want to have ConvertTo-Json return an array, you can either pass it an array as a parameter or put your array in an array and pipe that (which then, in effect, takes the inner array out and passes that to the cmdlet). And to put your array in an array, you need to use the , operator to create the array, because @() doesn't create arrays, it converts to arrays, which means if you are trying to put a single array inside another array, @($some_array) is a no-op because it's already an array. Oh, or you can play around with the -AsArray switch parameter on ConvertTo-Json.
|
# ? Jan 30, 2019 21:48 |
|
Jethro posted:So, if you want to have ConvertTo-Json return an array, you can either pass it an array as a parameter or put your array in an array and pipe that (which then, in effect, takes the inner array out and passes that to the cmdlet). And to put your array in an array, you need to use the , operator to create the array, because @() doesn't create arrays, it converts to arrays, which means if you are trying to put a single array inside another array, @($some_array) is a no-op because it's already an array. You're blowing my loving mind here. This is the most useful thing I think I've ever read in this thread.
|
# ? Feb 2, 2019 02:42 |
|
|
# ? May 15, 2024 03:36 |
|
Judge Schnoopy posted:You're blowing my loving mind here. This is the most useful thing I think I've ever read in this thread.
|
# ? Feb 4, 2019 16:43 |