|
Ithaqua posted:That was going to be my recommendation until I saw "PowerShell 2". Yeah
|
# ? Jun 17, 2016 00:15 |
|
|
# ? Apr 25, 2024 15:13 |
|
Wait, if I have a 2012 machine, can I make a DSC configuration and push it to client servers that may or may not have the right versions of powershell? Edit: Also there's VMware PowerCLI involved too. Dr. Arbitrary fucked around with this message at 00:54 on Jun 17, 2016 |
# ? Jun 17, 2016 00:45 |
|
Dr. Arbitrary posted:Wait, if I have a 2012 machine, can I make a DSC configuration and push it to client servers that may or may not have the right versions of powershell? No. All of the machines involved need WMF4 on them.
|
# ? Jun 17, 2016 00:54 |
|
I'm trying to write a script to get files off of a NAS. When I hit the line to copy them over, I get an error saying I don't have permission. I have manually copied files to and from this NAS repeatedly.code:
Where $location is the path in the NAS to the folder I'm copying from. Any ideas? I'm wondering if the NAS has its execution policy set to restricted, but I'm not even running it as a script yet. E: I've already tried running as an administrator, although UAC is off and that seems to make some stuff act weird. 22 Eargesplitten fucked around with this message at 19:43 on Jun 22, 2016 |
# ? Jun 22, 2016 19:00 |
|
22 Eargesplitten posted:I'm trying to write a script to get files off of a NAS. When I hit the line to copy them over, I get an error saying I don't have permission. I have manually copied files to and from this NAS repeatedly. Are you running the script locally, as in not part of an invoke-command statement or something? Can you post the error?
|
# ? Jun 22, 2016 22:19 |
|
Test-Path $location\foo Test-Path "$location\foo" See what you get?
|
# ? Jun 22, 2016 22:34 |
|
22 Eargesplitten posted:I'm trying to write a script to get files off of a NAS. When I hit the line to copy them over, I get an error saying I don't have permission. I have manually copied files to and from this NAS repeatedly. Rather than relying on string concatenation (unquoted even) try using (Join-Path $location 'foo') to deal with building a path. This sort of thing has caused me plenty of heartburn in the past. Quick and dirty is great for the command line but awful for any serious production scripts.
|
# ? Jun 22, 2016 22:45 |
|
What version are you running? I've had problems with UNC paths with version 3. My specific problem was trying to invoke commands from a UNC path. The shell just wouldn't see the file.
|
# ? Jun 23, 2016 00:43 |
|
Methanar posted:Are you running the script locally, as in not part of an invoke-command statement or something? Locally, just running it out of the terminal for now. I figured it out. For some reason I thought I needed gc to copy the files, so it was telling me I couldn't access the location, but it was still trying to get the files. The problem was Copy-Item wasn't given parameters to merge or overwrite folders that already exist. I also wasn't having it copy subfolders. This is what happens when someone with no understanding of powershell outside of get-help tries to automate what would otherwise be 100 hours of work. New error. code:
Copy-Item : The given path's format is not supported. At line:3 char:1 + Copy-Item -Path "$location\folder" -Destination "\\computer\C:\d ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: ( [Copy-Item], NotSupportedException + FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.CopyItemCommand 22 Eargesplitten fucked around with this message at 20:45 on Jun 24, 2016 |
# ? Jun 24, 2016 20:09 |
|
22 Eargesplitten posted:Locally, just running it out of the terminal for now. Is the destination share "C:"? Maybe it should be \\computer\c$\destinationpath
|
# ? Jun 24, 2016 20:50 |
sloshmonger posted:Is the destination share "C:"? Maybe it should be \\computer\c$\destinationpath I don't even think : is a valid character in share names.
|
|
# ? Jun 24, 2016 20:52 |
|
C$ did it. I didn't realize that wasn't allowed. This is supposed to transfer from a NAS to a user's PC, and it will be followed by sending a .bat and .ps1 to their computer. The .bat will launch the powershell script with a bypassed execution policy, which installs a ton of programs. Or is there a simpler way to do that part? I'm trying to automate a procedure that takes 2-2.5 hours every time, and I have dozens of computers to do it on. I'll still go on personally to check everything out, but spending ~10 minutes on each to look for errors and maybe do some final configuration is a whole lot better. Thanks for the help, I've been meaning to learn Powershell properly for over a year.
|
# ? Jun 24, 2016 21:40 |
|
22 Eargesplitten posted:Or is there a simpler way to do that part? SCCM or a similar system is probably the answer you're looking for here.
|
# ? Jun 24, 2016 22:21 |
|
We don't use SCCM. Or PDQDeploy. I'm not joking when I say the current expectation is spending weeks doing this manually.
|
# ? Jun 24, 2016 23:10 |
|
22 Eargesplitten posted:We don't use SCCM. Or PDQDeploy. I'm not joking when I say the current expectation is spending weeks doing this manually. How many machines are you responsible for?
|
# ? Jun 24, 2016 23:13 |
|
I'm not sure how many I'll be doing myself, the more senior people will probably be pitching in. But we have about 70 machines total. I've got a laptop I can test this on, at least. That way I'm not under the gun while I fix the inevitable errors.
|
# ? Jun 24, 2016 23:29 |
|
22 Eargesplitten posted:C$ did it. I didn't realize that wasn't allowed. This is supposed to transfer from a NAS to a user's PC, and it will be followed by sending a .bat and .ps1 to their computer. The .bat will launch the powershell script with a bypassed execution policy, which installs a ton of programs. Or is there a simpler way to do that part? 22 Eargesplitten posted:I'm not sure how many I'll be doing myself, the more senior people will probably be pitching in. But we have about 70 machines total. I've got a laptop I can test this on, at least. That way I'm not under the gun while I fix the inevitable errors. It's a bit more work to code, but you can build in some switches and error reporting so when something goes wrong it tells you and you can re-run the programs you need more easily. I've been working on something using functions and error checking, so I'll build out a little framework from that as an example. At the start of your script, you'll need a block like this: code:
Next, define a single variable to catch whether or not any errors happened in this script. code:
Next, you'll need a set of functions to be called by the main part of the script. For example: code:
SIDE NOTE: (There are other ways to test if a program is installed, for example by registry entries to uninstall software, just needed a quick error example) code:
|
# ? Jun 28, 2016 19:32 |
|
Cool, I'll start restructuring it like that. I cut out the .bat file part of the chain. Now I'm just calling the second script that I put on their computer from the first script. I'm using get-credential to run the second script on my admin account, but I want to verify the credentials because I fat finger the relatively complicated password a lot. How can I check that? I also want to pass those credentials into the second script because SQL server requires them for a command line install. I think I can do that with the arguments parameter in the powershell call.
|
# ? Jun 29, 2016 22:05 |
|
22 Eargesplitten posted:Cool, I'll start restructuring it like that. I cut out the .bat file part of the chain. Now I'm just calling the second script that I put on their computer from the first script. Assuming you're typing the credentials every time, you could try this: code:
|
# ? Jun 30, 2016 01:27 |
|
Thanks. I'm really learning a lot about powershell in this trial by fire, but sometimes googling doesn't turn much up. This thread is a big help.
|
# ? Jun 30, 2016 01:33 |
|
Edit: nm, got it to work after much frustration.
Sheep fucked around with this message at 14:18 on Jul 6, 2016 |
# ? Jul 6, 2016 14:08 |
|
Sheep posted:I am bad with Powershell. code:
|
# ? Jul 6, 2016 14:22 |
|
I wrangled your script into working, thanks!
|
# ? Jul 6, 2016 17:14 |
|
If I call a powershell script from within a powershell script, does the calling script keep going, or does it wait for the second to complete? I want to make mine keep going.
|
# ? Jul 7, 2016 19:12 |
22 Eargesplitten posted:If I call a powershell script from within a powershell script, does the calling script keep going, or does it wait for the second to complete? I want to make mine keep going. If you just call it, it runs synchronously. If you want it to be asynchronous, you need to put it inside a Job. Get-Help Start-Job
|
|
# ? Jul 7, 2016 20:10 |
|
I mistakenly posted this in the Enterprise thread, and received a workable answer but am still hoping for something a little more... clean.SeaborneClink posted:What's the most agnostic way to get the path of the Downloads folder? Anythonypants (a true hero) offered the below, which does work, but breaks tables. Any other ideas? anthonypants posted:Can you look up the registry setting for the path?
|
# ? Jul 8, 2016 04:01 |
SeaborneClink posted:I mistakenly posted this in the Enterprise thread, and received a workable answer but am still hoping for something a little more... clean. The right way is the Known Folders API. https://msdn.microsoft.com/en-us/library/windows/desktop/bb776911.aspx On mobile right now so csn't type up an example. Edit: As far as I can tell, the types for this isn't defined in .NET proper, so you have to declare the related COM interfaces and more to make it work. nielsm fucked around with this message at 08:00 on Jul 8, 2016 |
|
# ? Jul 8, 2016 05:52 |
Here's a "PowerShell" way of calling that function to get a known folder path:code:
nielsm fucked around with this message at 09:25 on Jul 8, 2016 |
|
# ? Jul 8, 2016 09:18 |
|
How would I make it so the script will start a file transfer on a computer asynchronously and then once that's done, continue by running a second script, but only after the file transfer is done? Would the ScriptBlock parameter for Start-Job do it? Like this?code:
I'm in the process of uninstalling everything so I can start testing the script again.
|
# ? Jul 11, 2016 16:33 |
More like this:code:
|
|
# ? Jul 11, 2016 16:55 |
|
Okay, thanks. I have to send the script to another computer because if I try to target the remote computer while running the second script from my machine Trendmicro blocks it. It seems to be working now, but I have to wait for the copying to finish to make sure the second script part is working right.
|
# ? Jul 11, 2016 17:36 |
|
Has anyone already written a script that does the following: Store network settings from existing adapter. Clear network settings from existing adapter. Remove adapter in VMware powercli. Add new adapter in powercli. Apply old network settings to new adapter. I'm sure I can figure it out. But if there's already a great script for it, I might save some time and avoid problems.
|
# ? Jul 12, 2016 00:17 |
|
Is there a maximum number of jobs you can have running at once? I'm looking at roughly 70/140 depending on whether copy then install counts as one or two.
|
# ? Jul 12, 2016 23:36 |
|
22 Eargesplitten posted:Is there a maximum number of jobs you can have running at once? I'm looking at roughly 70/140 depending on whether copy then install counts as one or two. I think it'll keep going until it chokes. I can only find articles on how to limit it, not how to get around the limit. Edit: There might be settings in WSMan that limit memory or processes. But you can change the settings.
|
# ? Jul 12, 2016 23:41 |
|
I got this to work precisely once, with only one username in the CSV file. If there are more users present, it will Move, Disable, and set the description properly, but doesn't strip out the AD group memberships. With only one name in the list, it will strip the AD memberships, but complains about 'Domain Users" which is fine. Any ideas on why its not stripping the AD groups from the subsequent users? code:
|
# ? Jul 13, 2016 18:03 |
Your code is an unreadable mess. Indent your poo poo properly, and stop making gigantic pipelines when writing scripts you intend to re-use. Gigantic long pipes mainly have use when experimenting on the commandline, and even then storing stuff into variables as intermediate steps makes it much easier to figure out where something might have gone wrong. Here's a possibly fixed version: code:
|
|
# ? Jul 13, 2016 18:16 |
|
I'm completely aware my code isn't pretty, but right now I'm working function over fashion. I ran your edited script and it completes, but no changes were made to the memberships regardless of how many users were in the .csv. The accounts disable, move, and change their description correctly though. I appreciate your tidy coding.
|
# ? Jul 13, 2016 18:27 |
Oh right, made a mistake editing it. The line should be: Remove-ADPrincipalGroupMembership -Identity $u.distinguishedname -MemberOf $_ -Confirm:$False
|
|
# ? Jul 13, 2016 18:34 |
|
You're a gentleman and a scholar! It's working great now. I added the following - it looks like it ignoring "Domain Users" now and isn't issuing a warning.code:
|
# ? Jul 13, 2016 18:45 |
|
|
# ? Apr 25, 2024 15:13 |
|
Mo_Steel posted:Assuming you're typing the credentials every time, you could try this: I used this, but without having it automatically filling in my username, so others can use the script down the line until we get a proper imaging solution. So I just deleted that part from after the get-credential. Now it requires the domain \username rather than just username. Do you know why that is?
|
# ? Jul 13, 2016 19:56 |