|
anthonypants posted:If you use robocopy inside of PowerShell you can still use variable names as parts of the path or as excluded files/folders, so there's no* reason to use Copy-Item instead. However, this did give me an idea to (yet again) plug my new module Idempotion, which lets you use existing DSC resources directly in scripts. As it happens, there is an existing xRobocopy DSC resource, so here's how you can use Robocopy with Idempotion: code:
Note that you can also use Test-xRobocopy with the same parameters, which just checks to see if it's in the correct state, and if you wanted to do a test first/set if necessary, then you would just use Update-xRobocopy instead of writing the if statement yourself.
|
# ? Jul 21, 2017 23:39 |
|
|
# ? May 28, 2024 15:41 |
|
I have a script that does this:code:
code:
I also tried -ErrorAction SilentlyIgnore but it just tries to pass it to foo.exe. How do I modify my script to stop it seeing the errors and freaking out (but only on this one line)?
|
# ? Jul 24, 2017 21:29 |
|
Tried wrapping it in a try/catch?
|
# ? Jul 24, 2017 21:35 |
|
EssOEss posted:I have a script that does this: Also, is it '2 > &1' or is it '2>&1'?
|
# ? Jul 24, 2017 21:56 |
|
I used to have a script that was a wrapped around GAM, and I had to write the commands like so:code:
Note that error handling in this case requires you to scrape the output for the codes though. (I've since re-written it using gShell which makes my life much easier even if there are some API hooks missing from that module.) *Is that right? I'm pretty sure I just lifted that workaround wholesale from Stack Overflow. Inspector_666 fucked around with this message at 22:00 on Jul 24, 2017 |
# ? Jul 24, 2017 21:58 |
|
What appears to be happening is that this stderr output causes the call operator to write some ErrorRecords to the PowerShell error stream. It does not terminate the script or anything - the problem is that the thing calling the script (a build process) freaks out over those ErrorRecords. In other words, regardless of what I do with the output of the command (and I have tried everything) it does not matter because the problem is that the stderr entries show up in $Error. Wrapping it in a cmd /c seems to be the key, though! PowerShell stops seeing stderr once I do that. Good enough for me. If I try to pipe it to stdout then it breaks again but no problem - I do not need the stderr output anyway. Thanks for the suggestions! Edit: oh for gently caress's sake it randomly works and does not on different runs now. What the hell. Edit 2: gently caress this poo poo, Start-Process and the hell with doing it in a more natural scriptish way. EssOEss fucked around with this message at 11:36 on Jul 25, 2017 |
# ? Jul 25, 2017 09:38 |
|
Hey guys, I'm an incredibly new Powershell scripter who has been tasked with developing a script that pulls an XML feed, stores the information that I want, and exports it to a csv file. I'm trying to get the script to go further and count the number of instances that occur in the CSV file. I'm running into an Issue where the output csv is showing the count but not the entities that I want also populated. PowerShell code:
http://imgur.com/a/NFuJd I'd like for this to be able to keep original csv column structure if possible. Is there any way I can do this? Modulo16 fucked around with this message at 21:09 on Jul 27, 2017 |
# ? Jul 27, 2017 21:05 |
|
Frank Viola posted:Hey guys, anthonypants fucked around with this message at 21:18 on Jul 27, 2017 |
# ? Jul 27, 2017 21:15 |
|
anthonypants posted:Firstly, use the url of the image when you're using img or timg. As for the PowerShell, use the -NoTypeInformation flag when you use Export-Csv, and that'll get rid of the first few rows that have the #TYPE garbage in them.The problem you're getting with the Values and Group columns is probably that you're passing some object to those columns instead of a value associated with that object. The problem with the Name column is likely due to your use of Group-Object. Did you mean to use Sort-Object? This Feed is pulled once per minute. I pull the Objects I need and export them to a csv file, and append it to a master Csv as well. We're trying to see how many times a certain device falls out of communication with our server while in use, and I'm trying to pull duplicate entries in the Master csv to quantify that. The count Column was added to show the quantity of duplicates, and I'm trying to keep the consistency of the file intact, while adding this additional column. Does that make sense? I guess my question would be: "How can I add a column that shows me a count of duplicate entries in a csv?" Modulo16 fucked around with this message at 22:15 on Jul 27, 2017 |
# ? Jul 27, 2017 21:57 |
|
Group-Object seems to cram all the details of what was grouped as an object of a "Group" property. If you pipe that through code:
|
# ? Jul 27, 2017 22:15 |
|
thebigcow posted:Group-Object seems to cram all the details of what was grouped as an object of a "Group" property. If you pipe that through Yes! Here's the new Snippet: PowerShell code:
So, I wrote this last part that does what I want but it would Populate the other values. code:
How do I get this table to fill in those missing values? Modulo16 fucked around with this message at 16:14 on Jul 28, 2017 |
# ? Jul 28, 2017 11:41 |
|
Imgur gave you an album link instead of the picture itself. I'll look again when I have some time.
|
# ? Jul 28, 2017 17:46 |
|
You can get Group-Object to output just the number of times each row shows up, and you can get Select-Object -Unique to output just the unique rows, and it would be really helpful if you could take those two arrays and add them, but PowerShell doesn't work like that, as far as I know. Unless you want to reconsider what you're trying to accomplish, the best suggestion I can give you is to send the Group-Object and Select-Object arrays to temporary variables, add a Count column to it, do a for loop on the Select-Object array, and insert the Count value from the Group-Object array on each line. With luck, the rows will even match!
anthonypants fucked around with this message at 22:30 on Jul 28, 2017 |
# ? Jul 28, 2017 18:21 |
|
anthonypants posted:You can get Group-Object[/fixed to output just the number of times each row shows up, and you can get [fixed]Select-Object -Unique to output just the unique rows, and it would be really helpful if you could take those two arrays and add them, but PowerShell doesn't work like that, as far as I know. Unless you want to reconsider what you're trying to accomplish, the best suggestion I can give you is to send the Group-Object and Select-Object arrays to temporary variables, add a Count column to it, do a for loop on the Select-Object array, and insert the Count value from the Group-Object array on each line. With luck, the rows will even match! I'm having a hard time following the original question, but isn't what you described the same as doing this? code:
The key thing to remember is that Group-Object is working on some property, so the rows may not actually be unique; you have to be sure to choose a property (column) that accurately reflects the uniqutitude of the row.
|
# ? Jul 28, 2017 22:29 |
|
I'm doing some work with CSOM and needed to take a break to mention how awesome VS Code and the Powershell extension are. Really starting to flex the VS Code debugger with this project.
|
# ? Aug 2, 2017 01:12 |
|
VS Code is amazing. One of the best products that flew under the radar from Microsoft in recent years.
|
# ? Aug 2, 2017 10:12 |
|
code:
|
# ? Aug 3, 2017 01:53 |
|
Collateral Damage posted:VS Code is amazing. One of the best products that flew under the radar from Microsoft in recent years.
|
# ? Aug 3, 2017 21:13 |
|
NYC PowerShell Meetup tonight!
|
# ? Aug 14, 2017 15:02 |
|
Ok. Help me believe I'm not insane. I'm using the NTFSSecurity module to assign Domain Users permissions to a folder. code:
The script basically just
copies the network install of it to the newly created folder Gives domain\domain users modify access on it as the application auto-updates itself
|
# ? Aug 29, 2017 15:07 |
|
Irritated Goat posted:Ok. Help me believe I'm not insane. I'm not 100% familiar with that module but I suspect that the Add-NTFSAccess cmdlet doesn't accept pipeline input (Which is lovely design...). You'll probably just have to use the -Path parameter with either the full-path as a string or use Get-Item: code:
code:
Pile Of Garbage fucked around with this message at 16:38 on Aug 29, 2017 |
# ? Aug 29, 2017 16:34 |
|
cheese-cube posted:
I'm still getting Access Denied issues. I'm beginning to wonder if there's not really a good way to add rights to a folder via script.
|
# ? Aug 29, 2017 17:49 |
|
Are you running an elevated Powershell? Also you may not have appropriate permissions on objects, even as an administrator on the machine, so you may need to first take ownership and grant yourself appropriate permissions.
|
# ? Aug 29, 2017 17:52 |
|
The Claptain posted:Are you running an elevated Powershell? Also you may not have appropriate permissions on objects, even as an administrator on the machine, so you may need to first take ownership and grant yourself appropriate permissions. This is a good point. Are you running the script in the context of a local user or a domain user? A local user would not be able to resolve domain objects like the Domain Users group. Also what version of PS are you using? Can you just use the native Get-Acl and Set-Acl cmdlets?
|
# ? Aug 29, 2017 18:00 |
cheese-cube posted:Also what version of PS are you using? Can you just use the native Get-Acl and Set-Acl cmdlets? I think the point is that constructing an ACL manually for use with Set-Acl is somewhat difficult.
|
|
# ? Aug 29, 2017 18:34 |
|
To come back to the original question, if you need to allow Domain Users permission to modify the location then why don't you just copy the relevant files to somewhere like $env:PUBLIC or a similar location where users can write to by default? Relying on permission inheritance is always simpler than explicitly defining permissions. I'm assuming that you're attempting to copy something to local machines, correct?
|
# ? Aug 29, 2017 18:54 |
|
So I've gotten a bit better at this stuff, and now I want to expand my most-used script. I've got one that I use for setting AD users to disabled and change the description to the ticket number associated and the date. I want to expand this in two ways. 1. I also want to move the users to our disabled OU. 2. I would like the script to ask me for the User's ID, and the ticket number. My current script is code:
I got this bit of code from ADAC: code:
So is there a way to pipe the identity from set-aduser to move-adobject? I tried just doing | after filling out the set-aduser part manually, and the object didn't move. But that could be because my move script is non-functional. Thoughts?
|
# ? Aug 29, 2017 20:22 |
|
In my user termination script, I have a variable $findUser that's just the result of code:
Then to move them into the Disabled User Accounts OU is: code:
I think that you might be over-defining the identity in the example line you posted, but piping the object from Get-ADObject works. EDIT: I use the $findUser variable elsewhere in the script (removing from groups, disabling, password reset, etc), it's a good kind of "catch-all" for the AD identity for everything I need to do. Inspector_666 fucked around with this message at 20:34 on Aug 29, 2017 |
# ? Aug 29, 2017 20:31 |
|
cheese-cube posted:To come back to the original question, if you need to allow Domain Users permission to modify the location then why don't you just copy the relevant files to somewhere like $env:PUBLIC or a similar location where users can write to by default? Relying on permission inheritance is always simpler than explicitly defining permissions. I'm assuming that you're attempting to copy something to local machines, correct? Basically, it's an application that auto-downloads\updates itself on each run. If we plan to take away local admin from Domain Users, we need to make sure this can update on its own. I'm running it as a domain user with local admin rights currently, If that helps any. cheese-cube posted:This is a good point. Are you running the script in the context of a local user or a domain user? A local user would not be able to resolve domain objects like the Domain Users group. I'm running 5.1 currently. I can run native Get\Set ACL but crafting that is a bit out of my depth right now.
|
# ? Aug 29, 2017 20:54 |
Avenging_Mikon posted:2. I would like the script to ask me for the User's ID, and the ticket number. The best approach (IMO) is to declare these as parameters, that way you can also call your script as part of another script, with the "host script" supplying the values instead of being locked in to interactive prompting. I assume your script is a .ps1 file you run by itself. Put this block at the very top: code:
You can do a lot more with parameters, but this is the most basic. Read up on the param() block as well as on the Read-Host cmdlet. This way you can both call your script as "interactive" (e.g. right-click in File Explorer and choose Run, or click the Run button in the ISE), or you can call it with parameters from the prompt, like: .\DisableUser.ps1 -UserID fred -TicketID SDE0023523 nielsm fucked around with this message at 21:22 on Aug 29, 2017 |
|
# ? Aug 29, 2017 21:18 |
|
nielsm posted:The best approach (IMO) is to declare these as parameters, that way you can also call your script as part of another script, with the "host script" supplying the values instead of being locked in to interactive prompting. This is also what I do; you can specify the type of the parameter as well as whether it's mandatory or not, which is really useful. Going to second the suggestion on Read-Host too; I'm a big fan of confirmations in scripts I'm only running manually, so this sort of block is really useful: code:
|
# ? Aug 30, 2017 05:14 |
|
Just to expand on interactive confirmation prompts do/while loop is handy to ensure you get a desired response:code:
|
# ? Aug 30, 2017 06:15 |
|
I think I'm missing something important when it comes to credentials and permissions. I need to use Get-Certificate to request computer account certificates on a huge number of remote machines. It works fine when I RDP in, run Powershell as an administrator, and then run the command. I need to do something equivalent to that while connecting via Invoke-Command or Enter-PSSession. There has to be a way to do this, right?
|
# ? Sep 22, 2017 16:36 |
|
Sounds like the PowerShell double hop problem. Maybe this will help: https://blogs.technet.microsoft.com/ashleymcglone/2016/08/30/powershell-remoting-kerberos-double-hop-solved-securely/
|
# ? Sep 22, 2017 17:12 |
|
I want to run an updater on an application, but it's for Mozilla Firefox so the steps involved are incredibly convoluted and stupid and I hate it. It pushes the status of the updater process to a file, which is just a single word, like "applying" or "failed" or "succeeded". I also don't know how long it's going to take. Would something like do {Start-Sleep -s 60} until (Get-Content "\\path\to\update.status" = "succeeded") in a script do what I think it will?
|
# ? Sep 23, 2017 00:04 |
|
anthonypants posted:I want to run an updater on an application, but it's for Mozilla Firefox so the steps involved are incredibly convoluted and stupid and I hate it. It pushes the status of the updater process to a file, which is just a single word, like "applying" or "failed" or "succeeded". I also don't know how long it's going to take. Would something like do {Start-Sleep -s 60} until (Get-Content "\\path\to\update.status" = "succeeded") in a script do what I think it will? ((get-content "\\path\to\update.status") -eq "succeeded")
|
# ? Sep 23, 2017 00:29 |
|
The Fool posted:((get-content "\\path\to\update.status") -eq "succeeded")
|
# ? Sep 23, 2017 00:32 |
|
anthonypants posted:What I would like is for the script to hold up and not perform any of the post-install junk. I don't think that's going to do that. It will if you put use the do..until as you wrote it, I just corrected your conditional. code:
Works as you would expect The Fool fucked around with this message at 00:38 on Sep 23, 2017 |
# ? Sep 23, 2017 00:36 |
|
The Fool posted:It will if you put use the do..until as you wrote it, I just corrected your conditional.
|
# ? Sep 23, 2017 00:43 |
|
|
# ? May 28, 2024 15:41 |
|
anthonypants posted:buhh, I just realized I did an = instead of an -eq
|
# ? Sep 23, 2017 02:01 |