|
GPF posted:This isn't an answer to anyone's deep question, or a question about some odd thing. This is me being happy. The DHCP cmdlets are nice. If you're using the new DHCP failover features just be aware that the Invoke-DhcpServerv4FailoverReplication cmdlet can be subject to kerberos double-hop issues if you try to use it remotely.
|
# ? Jan 5, 2016 02:08 |
|
|
# ? May 15, 2024 03:28 |
|
GPF posted:This isn't an answer to anyone's deep question, or a question about some odd thing. This is me being happy. I wish I could be happy. This place is stuck with version 2. Dr. Kayak Paddle fucked around with this message at 03:43 on Jan 7, 2016 |
# ? Jan 7, 2016 03:41 |
|
Went from an all windows shop hacking powershell about 15% of the time, left the midwest to go work for a Ruby on Rails shop running exclusively on Macs out west. I've spent 16 hours so far this week hacking powershell at work for a sales demo We did manage to draw a line in the sand and officially not support anything lower than Powershell v3, at least. Powershell v2 is not terribly functional once you start getting in to the guts of it.
|
# ? Jan 7, 2016 06:52 |
|
I'm trying to construct the parameters for an exe and executing it from within Powershell. For reference, I'm using CreateMedia.exe in SCCM: https://msdn.microsoft.com/en-us/library/jj155402.aspx I'm having trouble getting quotation marks to appear in the right places. I'm using the call (&) operator. To start I just manually created the command line and parameters I needed. code:
code:
So then I use these variables to build the call command. code:
Invalid parameter: Manager So, am I constructing this incorrectly? Is there another way I should be doing this? E: Found this article that includes a tool that will just print the arguments as passed, and it looks like the quotes are preserved but there are some extra ones, so now I'm not entirely sure what's going on. E2: And I was wrong about not being able to use variables in command parameters, I misinterpreted what I read. So I have very little idea what I'm doing here apparently. FISHMANPET fucked around with this message at 18:48 on Jan 7, 2016 |
# ? Jan 7, 2016 18:12 |
|
Nah you're on the right track kind of, it's a pain in the rear end and you can use write-host to get around it. $program = 'quser.exe' $flag1 = '/server:' $flag2 = 'localhost' "& $program $flag1$flag2" won't work, neither will "& $program ($flag1)($flag2)" The valid syntax for my example uses write-host for var interpretation, like code:
Roargasm fucked around with this message at 19:43 on Jan 7, 2016 |
# ? Jan 7, 2016 19:31 |
|
So that appears to pass the string the right way to the showargs.exe, but somehow fails miserably with createmedia.exe. The createmedia.exe logs the full parameter list it's given (sort of, it strips the quotes in the logs) and the parameters it understands, and it apparently wasn't able to read anything from that. E: Screw it, took my hand constructed string, dropped the variables I actually want to change, and it works just fine. code:
FISHMANPET fucked around with this message at 20:12 on Jan 7, 2016 |
# ? Jan 7, 2016 19:51 |
|
I'm trying to write a script to cull old Exchange mailboxes after exporting them, but I can't quite get it to work. I'm also starting to suspect that a. I'm abusing the hell out of piping and could do what I want in a simpler way, and b. There's probably something built in to Exchange anyway. Here's what I have so far: code:
Any tips on how to simplify / do this a different way?
|
# ? Jan 11, 2016 16:18 |
If you're on PowerShell 3 or later, this part:code:
code:
code:
The old version compatible syntax would be: code:
Doing that allows you to simplify the following two lines to: code:
How about this? code:
|
|
# ? Jan 11, 2016 18:14 |
|
Interesting! I didn't know about filter script. I can't find much about it in Microsoft's official documentation though. Is it an alias for something else? Also this is all in Exchange 2010 shell, which I think corresponds to only Powershell 2, sadly. Thanks so much for your help!
|
# ? Jan 13, 2016 01:19 |
|
2010 SP3 supports installing PS 3.0
|
# ? Jan 13, 2016 01:44 |
beepsandboops posted:Interesting! I didn't know about filter script. I can't find much about it in Microsoft's official documentation though. Is it an alias for something else? It's a filter function, placed in the "script" namespace. The "filter" keyword introduces a filter function. A filter function is pretty much a shortcut to write a full function, that only has a Process block, and implicitly takes a single pipeline input, and produces pipeline output. They're a simple way to wrap sub-operations you want to either name, or maybe re-use. The "script:" part is a qualifier that ties to the "Where-MailboxIsOld" name. I'm honestly not entirely sure about it, but it's supposed to place the function in the script namespace, meaning it wouldn't get exported if you load the script as a module, or source it in an interactive session. The rest of it is effectively a Process block inside a function, meaning the body of the filter function gets executed once for every item in the input pipeline. Because of that, it should also be possible to write it with an if statement, that then only outputs the mailbox back out if it's sufficiently aged. Something else is, consider having PS 4 or 5 on your workstation, and then set up a remoting session to your Exchange server. It's much more convenient, lets you work on Exchange through a local PS window, or even use the ISE, without having to open a remote desktop to another machine, or even having the Exchange management tools installed. nielsm fucked around with this message at 22:28 on Jan 13, 2016 |
|
# ? Jan 13, 2016 22:26 |
|
Is there a way to perform arithmetic on the results of a regex inside a -replace statement? Something like: code:
|
# ? Jan 15, 2016 23:10 |
I don't think there is. Instead, you can try matching the entire filename into three match groups, a prefix, the number, and a suffix, with an if ($x -match "re"). Then use the match groups to reconstruct the new filename and perform the rename.
|
|
# ? Jan 15, 2016 23:30 |
|
beepsandboops posted:Interesting! I didn't know about filter script. I can't find much about it in Microsoft's official documentation though. Is it an alias for something else? code:
|
# ? Jan 17, 2016 09:20 |
|
In one of my 'make my day easier' scripts it looks like I may need to figure out how to SFTP something from powershell (Well.. i guess I could use a command-line SFTP client but everything from powershell would be better). Has anyone done this/know of sites I can look at? Is there a .net class I can use? I'm guessing not As long as I'm in here, does anyone recall the changes from Powershell V3 to V5 in regards to handling com objects differently? I installed V5 last week and it really broke my script that was written with V3, where I heavily use IE COM objects. I didn't have the desire to dig far into it but it seemed like instead of waiting for the com operation to complete, it would execute all the operations without waiting for any status back (i.e. $ie = new-object -com internetexplorer.application; $ie.visible = $true; $ie.navigate($site)). With V3, it would open up IE, make it visible, and navigate to the site. With V5, it would make the object, then every other command would just return an exception.. just kinda wondering..
|
# ? Jan 26, 2016 01:26 |
|
Danith posted:In one of my 'make my day easier' scripts it looks like I may need to figure out how to SFTP something from powershell (Well.. i guess I could use a command-line SFTP client but everything from powershell would be better). Has anyone done this/know of sites I can look at? I've not used it myself but you might be able to use WinSCP to do it: https://winscp.net/eng/docs/guide_dotnet. It's not exactly from Powershell but it's the closest I was able to find. I was going to dive into it to automate an SFTP task but since the only manual steps are opening WinSCP, dragging the file over, and closing WinSCP I haven't bothered.
|
# ? Jan 26, 2016 05:38 |
|
Danith posted:In one of my 'make my day easier' scripts it looks like I may need to figure out how to SFTP something from powershell (Well.. i guess I could use a command-line SFTP client but everything from powershell would be better). Has anyone done this/know of sites I can look at? Fenrisulfr posted:I've not used it myself but you might be able to use WinSCP to do it: https://winscp.net/eng/docs/guide_dotnet. It's not exactly from Powershell but it's the closest I was able to find. I was going to dive into it to automate an SFTP task but since the only manual steps are opening WinSCP, dragging the file over, and closing WinSCP I haven't bothered.
|
# ? Jan 26, 2016 06:25 |
|
I'm pretty new to powershell and I'm having some difficulty with a script. I need a script to get just the last 4 digits of the TelephoneNumber field for all users in a specific OU, and then copy them to the ipPhone field. If the telephone number field is empty, do nothing to that entry Here's what I have so far: code:
I know what I need to do, it's the how that is giving me fits. Any advice/tips/pointers?
|
# ? Jan 26, 2016 22:17 |
|
Mr. Clark2 posted:I'm pretty new to powershell and I'm having some difficulty with a script. I need a script to get just the last 4 digits of the TelephoneNumber field for all users in a specific OU, and then copy them to the ipPhone field. If the telephone number field is empty, do nothing to that entry code:
|
# ? Jan 26, 2016 22:31 |
nm do the above
|
|
# ? Jan 26, 2016 22:32 |
|
Briantist posted:The DHCP cmdlets are nice. If you're using the new DHCP failover features just be aware that the Invoke-DhcpServerv4FailoverReplication cmdlet can be subject to kerberos double-hop issues if you try to use it remotely. That is damned good to know about. We are going to use the new load-balancing/failover setup very soon, so I'm actually going to send myself an email so I won't forget about it.
|
# ? Jan 27, 2016 05:01 |
|
So this is not necessarily a PowerShell question, but it is related. I have a simple script I want to run every 15 minutes to make sure our digital signage is running off the most recent files. Everything's going great except for taskeng.exe crapping up the display every time my script runs. I've been loving with it for a few hours and nothing works, and at this point I'm ready to just go use something else like CygWin's cron unless there's some simple thing I'm missing.
|
# ? Jan 27, 2016 07:26 |
|
I've never heard of task scheduler interfering with other processes/video If it's giving you that much grief, try something else? I personally hate task scheduler but it's dead reliable at what it does, so I'm thinking your issue lies elsewhere.
|
# ? Jan 27, 2016 08:50 |
|
Turns out you're right and it was a dumb thing I was doing in my script that was causing the issue.
|
# ? Jan 27, 2016 16:05 |
|
Zaepho posted:
Thanks! You got me about 98% of the way there, just had to modify the last line slightly.
|
# ? Jan 27, 2016 21:52 |
|
Mr. Clark2 posted:Thanks! You got me about 98% of the way there, just had to modify the last line slightly. Depending on the size of that OU you probably don't want to do -properties *, -properties TelephoneNumber should work fine. Sidenote, does having just -identity $user work? I always specify $user.SamAccountName. I'll have to test it when I get back to work.
|
# ? Jan 28, 2016 03:34 |
|
Yeah, the AD cmdlets will accept (relevant) AD objects for identity, as well as SamAccountName, SID, DistinguishedName, etc. The only time you really need to be careful is when passing them to other things - I usually need to use $user.UserPrincipalName when passing output filtered in AD to Exchange 2007 commands.
|
# ? Jan 28, 2016 09:36 |
|
Venusy posted:Yeah, the AD cmdlets will accept (relevant) AD objects for identity, as well as SamAccountName, SID, DistinguishedName, etc. The only time you really need to be careful is when passing them to other things - I usually need to use $user.UserPrincipalName when passing output filtered in AD to Exchange 2007 commands. I abuse the poo poo out of SamAccountName for any O365 stuff. I can't think of anything I've had to not use it on actually..
|
# ? Jan 28, 2016 17:43 |
|
I've got a quick question regarding PS, because I'm dumb and haven't used it much. I'm looking to modify some NIC settings, specifically here I'm trying to disable VMQ on a few different adapters, and I'm not sure what the issue is, whether it's syntax or perhaps I'm using a cmdlet that isn't available Let's say my adapter name is: The Network Adapter code:
Generally other cmdlets I've used, when I add -whatif, it actually tells me what is going to happen. So I don't know if the issue is syntax related (perhaps the way I'm presenting the name of the adapter is incorrect) or if the cmdlet is not available to me for :reasons: Running Server 2012 R2 with powershell major 4, build -1 revision -1... according to $host.version. MF_James fucked around with this message at 22:06 on Feb 4, 2016 |
# ? Feb 4, 2016 22:01 |
|
I think the author of the cmdlet has to write in support for -whatif, so that command just does it poorly. Are you having actual roubles executing the command, and/or is there a reason you're not using Disable-NetAdapterVmq?
|
# ? Feb 4, 2016 22:26 |
|
FISHMANPET posted:I think the author of the cmdlet has to write in support for -whatif, so that command just does it poorly. Are you having actual roubles executing the command, and/or is there a reason you're not using Disable-NetAdapterVmq? I could use that one. I'm not having troubles, except with "testing" the cmdlet to make sure it will run, these commands are getting compiled into a larger script so I can do logging and run it on multiple machiens with (hopefully) the same results without me typing out 20-30 different commands across all the machines.
|
# ? Feb 4, 2016 22:32 |
FISHMANPET posted:I think the author of the cmdlet has to write in support for -whatif, so that command just does it poorly. Are you having actual roubles executing the command, and/or is there a reason you're not using Disable-NetAdapterVmq? Do that if it's all you need to do. Apart from that, the parameter is called "-enabled". I think -WhatIf is dependent on the implementation having confirmation checks. In WhatIf mode it'd then just print the step to be confirmed, and continue as if the user rejected. nielsm fucked around with this message at 22:35 on Feb 4, 2016 |
|
# ? Feb 4, 2016 22:33 |
|
Thanks for the info guys, I have "one" more question, we are setting up our 6 hyper-V hosts to handle anti-affinity, I've essentially shamelessly ripped this from another site, while changing some info (site here: https://robertsmit.wordpress.com/2014/02/14/separate-vm-in-hyper-v-virtual-machines-using-anti-affinity-winserv-hyperv-drs/)code:
code:
MF_James fucked around with this message at 00:13 on Feb 5, 2016 |
# ? Feb 5, 2016 00:10 |
|
MF_James posted:Thanks for the info guys, I have "one" more question, we are setting up our 6 hyper-V hosts to handle anti-affinity, I've essentially shamelessly ripped this from another site, while changing some info (site here: https://robertsmit.wordpress.com/2014/02/14/separate-vm-in-hyper-v-virtual-machines-using-anti-affinity-winserv-hyperv-drs/) It's creating a collection and adding a single item to the collection.
|
# ? Feb 5, 2016 04:12 |
|
I just started doing some work for a programmer who has a big problem with if statements. I don't know the whole deal yet, but I assume it's a normal thing for some kinds of coding. Are there good ways to avoid IF with Powershell or is the language just not built for that?
|
# ? Feb 5, 2016 19:19 |
|
Dr. Arbitrary posted:I just started doing some work for a programmer who has a big problem with if statements. I don't know the whole deal yet, but I assume it's a normal thing for some kinds of coding. Does he have a background in functional programming? PowerShell isn't a functional language, don't try to shoehorn it into that mold. I mean, yeah, you can avoid writing if statements if you like unreadable code.
|
# ? Feb 5, 2016 19:31 |
|
Is Ruby functional programming? If so, I think we've cracked the case.
|
# ? Feb 5, 2016 19:32 |
|
Dr. Arbitrary posted:Is Ruby functional programming? If so, I think we've cracked the case. It isn't.
|
# ? Feb 5, 2016 19:52 |
|
Well... I guess I've got to set up a meeting to figure out what this guy is all about. Either he's really good or really bad. I know that I don't know enough to tell the difference. Either way I'll learn something!
|
# ? Feb 5, 2016 19:59 |
|
|
# ? May 15, 2024 03:28 |
|
Ok. Had a quick meeting and figured out his deal. IF statements are great for things like pre:if ($DiskSpaceUsed -gt $AlarmThreshold) { $Alarm = $True}| pre:if ($Serverclass -eq "Win2008db") { Apply Rule 1A Apply Rule 2A } elseif ($Serverclass -eq "Win20012db") { Apply Rule 1B Apply Rule 2B } elseif ($Serverclass -eq "Win2008app") { Apply Rule 1C Apply Rule 2C } and so on Instead, you'd want to do something like create a simple program that queries rules.xml and servertypes.xml or something.
|
# ? Feb 6, 2016 02:33 |