|
Try -like or -contains E: also, I like to wrap comparisons in ()’s, but it shouldn’t be necessary Ex: ((x -eq y) -and (z -like w)) The Fool fucked around with this message at 23:04 on May 1, 2018 |
# ¿ May 1, 2018 23:02 |
|
|
# ¿ May 13, 2024 23:53 |
|
If you're language agnostic about it, Python + Pandas may be a better choice. If you still want to use powershell, check out this blog post: http://ramblingcookiemonster.github.io/Join-Object/
|
# ¿ May 15, 2018 19:59 |
|
PSA: Be aware of typing.
|
# ¿ May 18, 2018 23:21 |
|
Noted and fixed. In this script the floats(now decimals) are just used in a couple conditions. The actual data is all strings coming from one csv to another.
|
# ¿ May 19, 2018 00:24 |
|
I'm literally just merging two CSV's, the conditions in my screenshot are from the VSCode debugger and are watching some code that I wrote to do some sanity checks. (making sure the files selected have the expected data, follows the spec from the vendor, the data isn't obviously bad, etc) Maybe I'll think twice about posting some quirk that amuses me next time.
|
# ¿ May 21, 2018 19:16 |
|
Anyone have any suggestions on handling XML templating? I need to build xml requests to interact with an API and don't really feel like code:
|
# ¿ Jul 23, 2018 22:20 |
|
Sanity check. I am using VSTS to automate a bunch of stuff. I have some scripts that require having credentials to service accounts. I have this as a preliminary solution, but want to make sure I'm not being totally terrible. I use this function to generate an encrypted string and key: code:
Then I have them available as environment variables in the script that needs the credentials, and can use this function to build a credential object. code:
|
# ¿ Jul 30, 2018 18:22 |
|
New Yorp New Yorp posted:Why can't you just store them as encrypted values in the build/release definition and pass them into the script when running? Because VSTS doesn't pass encrypted variables as enviroment variables, I would have to pass them as command line arguments which means they would end up getting logged in plain text. peak debt posted:You can store a password in DPAPI like this: DPAPI is encrypted per account and per machine. The entire point is to be able to store credentials in a way that doesn't require me pregenerating and storing them for a dozen servers.
|
# ¿ Aug 5, 2018 03:33 |
|
Your VSTS repo needs to be the remote origin for your local repo, then you commit and push and your changes will show up.
|
# ¿ Aug 10, 2018 06:04 |
|
Powershell comparisons use argument flags. Your comparison should be code:
|
# ¿ Aug 24, 2018 18:59 |
|
code:
|
# ¿ Aug 24, 2018 19:23 |
|
Wicaeed posted:Has anyone run into issues with VSCode not properly honoring PSBreakpoints while debugging Powershell? IIRC, VSCode breakpoints only trigger on executed code. As a result, you cannot place breakpoints on empty lines or in comments and expect them to trigger. Also, I have no idea how this compares to ISE, but if you put a breakpoint on a line in VSCode, it will trigger before the line is executed.
|
# ¿ Sep 11, 2018 19:19 |
|
nielsm posted:Does anyone know of a PS module or method for reading/querying/updating SharePoint lists? The idea being to write tools in PS that fetch some data and store in a SharePoint list for a web-based lookup tool to use. Use the CSOM https://social.technet.microsoft.com/wiki/contents/articles/29518.csom-sharepoint-powershell-reference-and-example-codes.aspx
|
# ¿ Sep 12, 2018 17:19 |
|
my cat is norris posted:Hi, friends. I'm looking for some help with Azure AD. I'm trying to mass-remove Yammer licenses from everyone in my environment, but I'm having a dickens of a time putting together a functional PowerShell script. Most guides I've found online refers to the MSOLService commands that have been replaced with AzureAD commands (I think?). A straight update of scripts doesn't seem to work for me, though. This one-liner should get you a list of everyone with ENTERPRISEPACK. code:
code:
|
# ¿ Sep 12, 2018 18:16 |
|
There is actually a a git specific thread. It is fairly slow, but enough people have it bookmarked that questions get answered. The Fool fucked around with this message at 23:31 on Oct 1, 2018 |
# ¿ Oct 1, 2018 23:28 |
|
Use try {} catch {} ?
|
# ¿ Oct 4, 2018 14:47 |
|
CzarChasm posted:I'm trying to write a small powershell script that will go to active directory and return all records (users and distribution groups) and the boolean value of the attribute msExchRequireAuthToSendTo which will be either true, false, or not set. Get-Aduser won't return groups, you should use get-adobject. Following Inspector_666's advice, something like this should work: code:
|
# ¿ Oct 4, 2018 18:08 |
|
I prefer ForEach in scripts. I have used ForEach-Object in one liners, but generally if my one liners is starting to get that complicated I probably need to unpack it a bit.
|
# ¿ Oct 9, 2018 23:47 |
|
FISHMANPET posted:fam just gently caress me up This is how I felt the first time I tried to do a for loop in Python.
|
# ¿ Oct 10, 2018 23:12 |
|
I've always done loops in C/C++/C# ascode:
code:
|
# ¿ Oct 10, 2018 23:29 |
|
I recently wrote up a script to migrate our on-prem distribution lists to O365 with the ultimate goal of eliminating our hybrid exchange server. As part of the script I wanted to be able to connect to on-prem exchange and O365 at the same time, so combined a couple different methods that I found and came up with this: code:
code:
code:
The Fool fucked around with this message at 21:51 on Nov 1, 2018 |
# ¿ Nov 1, 2018 19:44 |
|
Instead of passing the array to Invoke-Command, wrap it in a For-Each so you know which computer it is running against, and it will run in the order specified by the csv.code:
The Fool fucked around with this message at 19:34 on Nov 29, 2018 |
# ¿ Nov 29, 2018 19:29 |
|
Yeah, the for-each will be slower, but as you have observed, you lose control.
|
# ¿ Nov 29, 2018 19:35 |
|
You could do the cheap way:code:
code:
The Fool fucked around with this message at 20:03 on Nov 29, 2018 |
# ¿ Nov 29, 2018 19:58 |
|
Because I felt like wasting time at work:code:
nielsm posted:In fact, I'm pretty sure PS remoting automatically decorates returned objects with note properties containing the host that produced it. It does, it's the PSComputerName member, I had to look it up
|
# ¿ Nov 29, 2018 20:18 |
|
MJP posted:I'm sorry, but I'm totally confused by where you want me to put these. I don't know if this is what you meant. I wasn't very clear, and was wrong anyway. I will fix it in this space. edit: If you have a thing returning results like your script, usually what you want to do is to build a custom object that you can easily export to a CSV. There are a number of different ways to create custom objects in Powershell, but I like using Select-Object for simple objects since I feel it is easier to read. For Example, this creates a custom object with the properties "Computer" and "Result" code:
code:
The Fool fucked around with this message at 20:37 on Nov 29, 2018 |
# ¿ Nov 29, 2018 20:20 |
|
Yes
|
# ¿ Nov 29, 2018 20:46 |
|
If you want to get some practice in, Advent of Code is up and is fun.
|
# ¿ Dec 3, 2018 19:55 |
|
Is there a reason that ConvertTo-JSON and ConvertFrom-JSON wouldn't work for you?
|
# ¿ Jan 10, 2019 19:45 |
|
I wouldn't do it in Powershell, but maybe either C# or Python using something like Selenium
|
# ¿ Jan 18, 2019 19:51 |
|
Instead of code:
code:
edit; the full command: code:
|
# ¿ Jan 22, 2019 19:35 |
|
Because I was
|
# ¿ Jan 22, 2019 19:46 |
|
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 |
|
I can all but guarantee that your searchbase value is wrong somehow.
|
# ¿ Jan 22, 2019 20:09 |
|
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 |
|
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 |
|
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 |
|
You can try using the call operator with string concatenation:code:
|
# ¿ Jan 29, 2019 19:46 |
|
Not sure if typo, but it should be code:
code:
|
# ¿ Feb 20, 2019 20:16 |
|
|
# ¿ May 13, 2024 23:53 |
|
Irritated Goat posted:Now that I'm at a PC, the code I'm using is: Stop doubling up on Select-Object and use Where-Object instead of Select-String. Something like code:
|
# ¿ Feb 20, 2019 21:27 |