|
Had a fun thing that I nearly came into this thread to ask about. I've been using the type three letters then tab autocomplete in PowerShell ISE to run my various .ps1's. Turns out it will pick other extensions first if they have the same name... I was wondering why that .CSV file kept opening in excel every time I tried to run the script!
|
# ? May 12, 2020 01:03 |
|
|
# ? May 15, 2024 04:20 |
|
Can anyone explain the reasoning why if Invoke-WebRequest or Invoke-RestMethod are successful, you can check $response.StatusCode but if it encounters an error like a 4xx/5xx you need to look at $_.Exception.Response.StatusCode.Value__? I just had a colleague "fix" a script I wrote by taking the Value__ from my catches and use it on status code checks on the not-exceptional responses as well.
|
# ? May 12, 2020 13:35 |
|
Can only guess why it was designed that way, but your observation is because the cmdlet throws an exception (and never writes the response back to your variable). The exception throw can be disabled in PowerShell 7 and the PR for it offers some insight.
|
# ? May 13, 2020 00:27 |
|
I have 50 security groups that I need to add 2 users to the Delivery Management list so they can send to all of them. They're all in the format companyname.office.cityname, is it possible to add user1@company.com and user2@company.com to the allowed senders for companyname.office.* ?
|
# ? May 27, 2020 16:24 |
TITANKISSER69 posted:I have 50 security groups that I need to add 2 users to the Delivery Management list so they can send to all of them. They're all in the format companyname.office.cityname, is it possible to add user1@company.com and user2@company.com to the allowed senders for companyname.office.* ? if I"m reading right: Set-Mailbox -Identity "Robin Wood" -AcceptMessagesOnlyFrom "Lori Penor","Jeff Phillips" -AcceptMessagesOnlyFromDLMembers "Legal Team 1" https://docs.microsoft.com/en-us/exchange/recipients/user-mailboxes/message-delivery-restrictions?view=exchserver-2019
|
|
# ? May 27, 2020 16:35 |
|
Submarine Sandpaper posted:if I"m reading right: I'm thinking it would be more like the example linked here: https://community.spiceworks.com/topic/2232835-remove-member-from-delivery-management-with-exhange-powershell quote:Set-DistributionGroup "GROUP-NAME-HERE" -AcceptMessagesOnlyFromSendersOrMembers((Get-DistributionGroup "GROUP-NAME-HERE").AcceptMessagesOnlyFromSendersOrMembers + "IDENTITY-OF-USER-OR-GROUP-HERE") The trick is I'm hoping I can literally enter companyname.office.* so all of the groups can be updated at once.
|
# ? May 27, 2020 16:48 |
|
TITANKISSER69 posted:I'm thinking it would be more like the example linked here: https://community.spiceworks.com/topic/2232835-remove-member-from-delivery-management-with-exhange-powershell I'm not sure if you can wildcard that line, but you should be able to use Get-DistributionGroup -Filter or maybe -Anr to put the list into a variable you can then go through with a ForEach loop.
|
# ? May 27, 2020 16:57 |
|
Inspector_666 posted:I'm not sure if you can wildcard that line, but you should be able to use Get-DistributionGroup -Filter or maybe -Anr to put the list into a variable you can then go through with a ForEach loop. The Identity parameter of Set-DistributionGroup accepts value from pipeline input so you can just pipe Get-DistributionGroup straight into it instead of using a loop (Make sure to run your Get-DistributionGroup command separately first to validate the output before piping it through).
|
# ? May 28, 2020 13:47 |
|
e. Didn't read the last post.
|
# ? May 30, 2020 05:44 |
|
I just rediscovered Powershell can do pass by reference. Oh yeah, it's coding horror time
|
# ? Jun 2, 2020 12:42 |
|
Antigravitas posted:I just rediscovered Powershell can do pass by reference. Oh fuuuuuuuuuun.
|
# ? Jun 2, 2020 21:23 |
|
Antigravitas posted:I just rediscovered Powershell can do pass by reference.
|
# ? Jun 2, 2020 21:30 |
|
I'm doing something dumb, but can't figure out exactly what it is (been a few years since I've worked with PS) I'm looping through a file to set variables. Some of them I need to convert to SecureString. The ones that are converted to SecureString lose their value at the end of the loop where the ones that aren't don't. Any help would be appreciated. code:
|
# ? Jun 4, 2020 14:51 |
|
Twat Waffle posted:I'm doing something dumb, but can't figure out exactly what it is (been a few years since I've worked with PS) You're not creating the variable you're expecting to in the case of Username or Password. When you're trying to create the new variable you're just overwriting the 0 index of the $var array. Try changing that line to: code:
|
# ? Jun 4, 2020 15:13 |
|
Thanks for the explanation and help! It is very much appreciated. I had tried using the Set-Variable bit and couldn't get the convertto-securestring to work as I was passing it incorrectly.
|
# ? Jun 4, 2020 15:20 |
Okay, I need to take a basics of computer programming course because when I'm trying to do what every other person in my area seems to be able to do without even blinking, I completely struggle with, and I don't know the right terms or way to google what I need. I need some help on this, and please I beg of you, put it in high school level terms, because I'm trying really hard to catch up beyond simple one-line scripts. When I run the script herein, it doesn't even do anything. It just enters onto the next line, nothing. Even with -whatif. I ran $writeverbose="continue" in the terminal in hopes that I could just get it to show me everything it's doing, but it still does nothing. How do I tell a script to just dump everything into a console so I can troubleshoot what I'm doing and at least try to learn? code:
|
|
# ? Jun 12, 2020 20:29 |
|
MJP posted:Okay, I need to take a basics of computer programming course because when I'm trying to do what every other person in my area seems to be able to do without even blinking, I completely struggle with, and I don't know the right terms or way to google what I need. Without giving any thought to what you're asking, I see you have a typo: ($subscriptionguid in $subscriptionguidss)
|
# ? Jun 12, 2020 20:35 |
|
MJP posted:How do I tell a script to just dump everything into a console so I can troubleshoot what I'm doing and at least try to learn? Write-Host is your friend. code:
|
# ? Jun 12, 2020 21:05 |
Zaepho posted:by using Import-CSV you're getting an object with a property for each field of the CSV file So if what I want to do is make $subscriptionguid a variable that uses the next GUID in the array, what should I use if not import-csv? https://lukesalter.wordpress.com/2014/06/12/powershell-read-a-csv-file-into-an-array/ seems to indicate that import-csv is what I should use.
|
|
# ? Jun 13, 2020 22:06 |
|
Nth Doctor posted:Without giving any thought to what you're asking, I see you have a typo: Fix this first, then keep asking questions if that wasn't the only thing wrong.
|
# ? Jun 14, 2020 06:15 |
if your csv/text file is something like 1337 6969 420 then use get-content
|
|
# ? Jun 14, 2020 12:18 |
Toast Museum posted:PowerShell Scripting in a Month of Lunches by the same authors. Formerly called PowerShell Toolmaking in a Month of Lunches. Full disclosure, I got sidetracked by actual scripting projects and never finished this one, but it seems like a good resource. Thanks I needed this
|
|
# ? Jun 16, 2020 06:46 |
|
mllaneza posted:If that's a copy n' paste of all your code, there's your problem. You've got one reference to $extx, which has an assigned value, and one to $ext which doesn't. Not all the code, just two lines. Line above was xls extension. Sorry - I have been too busy at work to check the forum. Thanks for the help though everyone, I got what I needed.
|
# ? Jun 18, 2020 16:50 |
|
Is anyone aware of a way to have Powershell interact with a SSH session that's compatible with Powershell Core? I'm updating a team member's script which used Posh-SSH, but in troubleshooting some errors I was having I found out Posh-SSH only works with Desktop and not Core at this point and it seems kind of dumb to develop script limited to Desktop in 2020.
|
# ? Jun 29, 2020 04:53 |
|
are you basically looking for MS expect ?
|
# ? Jun 29, 2020 05:12 |
|
Potato Salad posted:are you basically looking for MS expect ? I had to look up Expect, but that's not really what I was looking for. I have some devices which can take API commands over SSH and I wanted to send some commands and evaluate what they return in order to validate some testing. This was fairly straightforward with Posh-SSH, but I didn't want to be stuck with Desktop. Fortunately they can also take HTTP API calls, so I think I'm just going to have to go in that direction.
|
# ? Jun 30, 2020 17:42 |
|
BeastOfExmoor posted:I had to look up Expect, but that's not really what I was looking for. I have some devices which can take API commands over SSH and I wanted to send some commands and evaluate what they return in order to validate some testing. This was fairly straightforward with Posh-SSH, but I didn't want to be stuck with Desktop. Fortunately they can also take HTTP API calls, so I think I'm just going to have to go in that direction.
|
# ? Jun 30, 2020 18:11 |
|
What command can I use to generate a list of mailboxes that one employee has Send As permission on?
|
# ? Jul 10, 2020 16:01 |
|
A single command won't do it, but two commands piped together willcode:
Also, if you have more than 1000 mailboxes, you will want to specify ResultSize https://docs.microsoft.com/en-us/powershell/module/exchange/get-mailbox?view=exchange-ps https://docs.microsoft.com/en-us/powershell/module/exchange/get-recipientpermission?view=exchange-ps
|
# ? Jul 10, 2020 16:57 |
|
That's showing me FullAccess, but not Send As
|
# ? Jul 10, 2020 17:20 |
|
code:
|
# ? Jul 10, 2020 18:27 |
|
Get-RecipientPermission should only work for SendAs permissions. If you are checking for other permissions, you would use Get-MailboxPermission
|
# ? Jul 10, 2020 18:40 |
|
code:
|
# ? Jul 10, 2020 18:49 |
|
I suppose I assumed and did not ask. Get-RecipientPermission is O365 only and will not work with on-prem exchange.
|
# ? Jul 10, 2020 18:50 |
|
My bad, I should have stated that up front
|
# ? Jul 10, 2020 18:51 |
|
A quick google found me this: https://www.beaming.co.uk/knowledge-base/powershell-commands-view-mailbox-permissions-migrating-exchange-server/ Where you need to query ad extended permissions to get what you're looking for. Not something I've ever tried to do though.
|
# ? Jul 10, 2020 18:55 |
Depends on the Exchange version, really. As far as I understand the extended AD permission is what Exchange 2007 did, and some update to 2013 changed it to be a MailboxPermission, while still accepting the AD permission. But O365 is always the RecipientPermission.
|
|
# ? Jul 10, 2020 20:37 |
I'm writing a script module to wrap a web service. Some parts of the web service don't have great lookup features yet, so to find an object by e.g. display name I have to fetch all objects of the class and then filter them myself. I have something like this: code:
But when I try the ByName or ByFrob parameter set I get nothing back. Fake edit: I found the answer while writing this post, so leaving it here so anyone else can maybe learn too. The issue is that Invoke-RestMethod technically returns a object[] array instead of a PowerShell collection or PSCustomObject, when the web service call returns a JSON array. You need to do "something" to the result to force it to convert into a regular PowerShell collection of PSCustomObject data. One thing you can do is simply wrap the call in parentheses, like this: code:
By the way this is on PowerShell 5.1.17763.1007 on Windows 10 1809. Maybe it's fixed/improved in the newer versions.
|
|
# ? Aug 7, 2020 12:39 |
|
nielsm posted:Fake edit: I found the answer while writing this post, so leaving it here so anyone else can maybe learn too. I'm working on a similar project and can confirm that the behavior is the same for PowerShell 7.0.3 on Windows 10 2004.
|
# ? Aug 7, 2020 14:08 |
|
|
# ? May 15, 2024 04:20 |
|
nielsm posted:Fake edit: I found the answer while writing this post, so leaving it here so anyone else can maybe learn too. mystes fucked around with this message at 14:36 on Aug 7, 2020 |
# ? Aug 7, 2020 14:30 |