|
That's super helpful. I will check both of those things. Had another related thing that I could use help with. After processing the attachments and pulling the various bits of information and saving that to a text file, I want to move the email from the Inbox to a "Processed" folder. Taking a quick look at Jethro's link - https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-1.0/mail-rest-operations-v1#move-or-copy-messages I wonder if I can do this: code:
code:
I really appreciate the help
|
# ? Nov 6, 2018 23:51 |
|
|
# ? Jun 13, 2024 05:50 |
|
Yes, move usually has the same effect as copy and delete original. The verbiage "This creates a new copy of the message in the destination folder." is a little ambiguous, but I take that to mean that the message in the destination folder has a new message_id and the old message_id now refers to a message that doesn't exist (or is in some deleted location or status).
|
# ? Nov 7, 2018 15:40 |
|
Definitely test it if at all possible first though. I've encountered countless "REST" APIs that don't work as expected and Microsoft doco isn't as good as it used to be (lol I know).
|
# ? Nov 9, 2018 10:40 |
I was told to do this after a review and don't think it's possible but want to confirm before ignoring it. Old code:
New code:
|
|
# ? Nov 12, 2018 18:13 |
|
You can try scoping the variable with $global:description or $script:description depending on what's defining it? (I'd start with $script: if it's possible.)
|
# ? Nov 12, 2018 18:17 |
|
Submarine Sandpaper posted:I was told to do this after a review and don't think it's possible but want to confirm before ignoring it. code:
|
# ? Nov 12, 2018 18:25 |
|
When I do Invoke-VMScript in PowerCLI - which feeds strings of code into a VM - and I need to dynamically update variables, I call the variable #variable and then to a $string.replace(#variable,$variable). For instance:code:
Happiness Commando fucked around with this message at 18:31 on Nov 12, 2018 |
# ? Nov 12, 2018 18:28 |
Call Script was a generic and I should have written call-function, $ExecutionContext.InvokeCommand.ExpandString($description) ended up working out. Hope I won't forget this one. Submarine Sandpaper fucked around with this message at 18:51 on Nov 12, 2018 |
|
# ? Nov 12, 2018 18:41 |
|
That seems way harder to read and understand compared to what you originally wrote.
|
# ? Nov 12, 2018 19:21 |
|
What issue is moving the line out of the foreach block solving? I'm sort of confused as to what the end goal is.code:
|
# ? Nov 12, 2018 20:16 |
Jowj posted:What issue is moving the line out of the foreach block solving? I'm sort of confused as to what the end goal is.
|
|
# ? Nov 12, 2018 20:22 |
|
Submarine Sandpaper posted:It's not solving an issue and the $ExecutionContext.InvokeCommand.ExpandString($description) has potential security concerns but I don't get paid enough to care or fight. I got to learn something new which is cool though. The next review may tell me to revert it due to the security concerns, which I'll then function it or do the replace like Commando. Ah. I've been there. Good luck and glad you're learning poo poo
|
# ? Nov 12, 2018 20:24 |
|
The only real reason I can see is if you're going to move the string template to the top of the file as some sort of setting that can be easily edited later, but in that case it wouldn't be clear what variables would be in scope when you call ExpandString later, so that probably wouldn't be a great solution either.
|
# ? Nov 12, 2018 20:43 |
|
mystes posted:You can do DON'T DO THIS! Just create a string with a placeholder keyword and then use the Replace() method to insert the required string inside the loop: code:
Remember ya'll, everything in PowerShell is a .NET object which exposes all of the methods and properties available to that class in the .NET Framework. If you use the GetType() method on an object and then Google the type name you'll get the MSDN (Or Microsoft Docs now I gues) page which details all of the methods and properties available for that type.
|
# ? Nov 13, 2018 02:27 |
|
Pile Of Garbage posted:DON'T DO THIS! Just create a string with a placeholder keyword and then use the Replace() method to insert the required string inside the loop: mystes fucked around with this message at 02:48 on Nov 13, 2018 |
# ? Nov 13, 2018 02:45 |
|
Anyone used the module here before? https://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb/view/Discussions/4 It's useful (in that it works), but I'm having issues when dling large files (50+GB) over and over as the Get-FTPItem always overwrites the local file, even if they are the same and already present on local disk
|
# ? Nov 20, 2018 21:41 |
|
Right in the comments section a guy mentions using overwrite:$false, except that he gets a prompt asking him if he wants to overwrite files or not, though that's about a year old now and the module was updated a few months later, no clue if that behavior changed or not...quote:Overwrite:$false without prompt
|
# ? Nov 20, 2018 22:35 |
|
I need to write an empty array to json instead of $null. What's the least hacky way to do this? $json = @{} [array]$array = @() $json.add('Thing',$array) $json | convertto-json Results are: "Thing" : $null Desired results are: "Thing" : [ ]
|
# ? Nov 22, 2018 01:42 |
|
Judge Schnoopy posted:I need to write an empty array to json instead of $null. What's the least hacky way to do this? ConvertTo-JSON is broken when pipelining. "ConvertTo-JSON $json" should do what you expect.
|
# ? Nov 22, 2018 01:52 |
|
Judge Schnoopy posted:I need to write an empty array to json instead of $null. What's the least hacky way to do this? That snippet worked fine for me with PowerShell 5.1: code:
code:
Toshimo posted:ConvertTo-JSON is broken when pipelining. "ConvertTo-JSON $json" should do what you expect. I've never had issues pipelining to ConvertTo-Json. The only instance where it appears to break is if you pass it an array but that's to be expected because JSON is a key/value format. Edit: lol why did I say pipelining? It's piping, I'm a dingus. Pile Of Garbage fucked around with this message at 16:06 on Nov 22, 2018 |
# ? Nov 22, 2018 04:17 |
|
Edit: too slow
|
# ? Nov 22, 2018 04:21 |
I have this script that successfully returns correct results against a csv of computer names. How do I make it show "X is True, Y is false" so I know which is which? When I run it, it just kinda runs randomly against the list, so it may not always be 1:1 against the CSV.code:
|
|
# ? Nov 29, 2018 19:20 |
|
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 |
The Fool posted: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. So something like this? I had started out here, but was advised to run it in an array passed to invoke-command so it'd run faster. code:
|
|
# ? Nov 29, 2018 19:34 |
|
Yeah, the for-each will be slower, but as you have observed, you lose control.
|
# ? Nov 29, 2018 19:35 |
Unfortunately when I run that latest version, I get false results. it says that the key is present, but I have one server in there where the key is not present. Is there no way for me to get names to results with it piped from an array, when everything returns correct results?
|
|
# ? Nov 29, 2018 19:40 |
|
MJP posted:Unfortunately when I run that latest version, I get false results. it says that the key is present, but I have one server in there where the key is not present. Try this. code:
Edit: Comments are great, but aren't needed when what you are doing is fairly obvious. It depends on your audience ofc. PBS fucked around with this message at 19:45 on Nov 29, 2018 |
# ? Nov 29, 2018 19:42 |
PBS posted:Try this. The comments are more for my own sanity. How would I output as columns? I'm happy to do so. As of now it outputs it like this, which is no good: RPC port reg key is present on Contoso1 RPC reg key is not present on Contoso2 RPC port reg key is present on Contoso-CLUS1 RPC port reg key is present on ContosoMSQCLUS1 MJP fucked around with this message at 19:53 on Nov 29, 2018 |
|
# ? Nov 29, 2018 19:50 |
|
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 |
|
MJP posted:The comments are more for my own sanity. You can get them all on one line fairly easily, Write-Output 'Test' $test will get you two lines Write-Output ('Test ' + $test) will get you one If you just wanted columns for your output, this is how I'd do it. code:
PBS fucked around with this message at 20:09 on Nov 29, 2018 |
# ? Nov 29, 2018 20:00 |
PBS posted:You can get them all on one line fairly easily, Yours just gives an error for each line in the CSV: code:
The Fool posted:You could do the cheap way: 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. code:
|
|
# ? Nov 29, 2018 20:08 |
|
MJP posted:Yours just gives an error for each line in the CSV: Yeah, I just fixed a mistake with my variable names. Check my edited post and try again. (Or just search/replace "$tempObject" with "$tmpObject")
|
# ? Nov 29, 2018 20:10 |
Wouldn't this work?code:
nielsm fucked around with this message at 20:15 on Nov 29, 2018 |
|
# ? Nov 29, 2018 20:13 |
|
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 |
|
Yeah, those are certainly more elegant solutions.
|
# ? Nov 29, 2018 20:20 |
|
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 |
|
I would have done it like PBS posted, I'm not very good at PS or elegant, but I did something similar a while back and this is what I did. I usually use import-csv for actual CSVs with headers, and get-content with txt files with single entries per line, but I'm guessing that CSV is single entry per line as well. code:
|
# ? Nov 29, 2018 20:36 |
PBS' latest iteration is running. It's taking its time but it ran with columns against the test script, now it's running against 103 hosts. Edit: Completed, and the vast majority (90 machines D: ) threw errors that the server name could not be resolved. Should I be redoing this against FQDNs rather than just hostnames? MJP fucked around with this message at 20:48 on Nov 29, 2018 |
|
# ? Nov 29, 2018 20:39 |
|
Yes
|
# ? Nov 29, 2018 20:46 |
|
|
# ? Jun 13, 2024 05:50 |
|
MJP posted:PBS' latest iteration is running. It's taking its time but it ran with columns against the test script, now it's running against 103 hosts. Really depends on your network, if DNS & Search Suffixes are properly setup it shouldn't matter. To answer the question it's usually better to be as explicit as you can be.
|
# ? Nov 29, 2018 20:47 |