|
Roargasm posted:yeah my only real problem right now is this logic:
|
# ? Apr 27, 2017 17:32 |
|
|
# ? May 14, 2024 10:52 |
|
That string was right, it was just the array comparison loving me I think. Ran out of time I ended up doing a really lovely nested loop and used remove duplicates in excel $nodeVMs | % { $vmName = $_.Name $noLiveMigrateVM | % { if ("$vmName" -match $_) { echo "$hostname" }
|
# ? Apr 27, 2017 17:52 |
|
I'm wrong and dumb.
The Fool fucked around with this message at 00:12 on Apr 29, 2017 |
# ? Apr 28, 2017 21:20 |
|
anthonypants posted:Is your script calling another script? No. Opening the PowerShell console takes almost exactly five seconds, the ISE loads near immediately. This is a new behavior since the last Windows Update that I haven't noticed until today because I guess I've been using the ISE for everything. I made a blank profile.ps1 to see if that was it and no dice. There is no profile.ps1 in $PSHOME. The x86 version loads almost immediately. I need to catch up on month end stuff before I can look into this again.
|
# ? May 1, 2017 19:44 |
|
There are four profiles you can look at. In an affected PowerShell window, check:code:
Also try opening powershell without a profile: code:
|
# ? May 1, 2017 20:34 |
|
thebigcow posted:I have a few scripts that I run from the right click menu because they have to be used by non-technical people if I'm out. Current execution policy is RemoteSigned. A recent Windows update installed PowerShell 5.1 and now I get a prompt after running these scripts:
|
# ? May 1, 2017 23:07 |
|
Just going to leave this here as a monument to my stupidity. It took me entirely too long to figure this out. edit: vvv- The actual code does stuff, those are just watch expressions in the VS Code debugger. The Fool fucked around with this message at 23:29 on May 1, 2017 |
# ? May 1, 2017 23:08 |
|
The Fool posted:Just going to leave this here as a monument to my stupidity. It took me entirely too long to figure this out. code:
|
# ? May 1, 2017 23:27 |
|
anthonypants posted:
code:
code:
Briantist fucked around with this message at 17:47 on May 2, 2017 |
# ? May 2, 2017 17:42 |
|
For those interesting in such things, the Powershell.org channel on YouTube just uploaded sessions from last week's PowerShell + DevOps Global Summit. Content from previous years has been very good, so I figured I would pass this along.
|
# ? May 3, 2017 17:13 |
|
Okay, I need a sounding board for this. We're changing the name of a building, and they want it updated on everyone's AD profile. How's this look? code:
|
# ? May 19, 2017 19:19 |
|
Avenging_Mikon posted:Okay, I need a sounding board for this. Looks like it's just -Office. code:
anthonypants fucked around with this message at 19:43 on May 19, 2017 |
# ? May 19, 2017 19:32 |
|
That's what I get for doubting myself. I had -office in my first draft but changed it because of a random article I found. Thanks.
|
# ? May 19, 2017 19:57 |
|
There's Office and StreetAddress, but yeah, no PhysicalDeliveryOfficeName. Just do a Get-Aduser your.name -properties * to double check.
|
# ? May 19, 2017 20:01 |
|
To be fair, if you're in the Attribute Editor, and maybe if you're looking at ADSIEdit or at LDAP, there is an attribute named pysicalDeliveryOfficeName. But it's also the Office field under the General tab of an ADUC window, and that's just the way it is in Set-ADUser.
|
# ? May 19, 2017 20:18 |
|
Thanks anthonypants, your revision worked perfectly.Inspector_666 posted:There's Office and StreetAddress, but yeah, no PhysicalDeliveryOfficeName. I saw a script sample with a screenshot of attribute editor, and when I checked, the office line in properties was the same as the pdon line in attribute editor, so I made an assumption, which was wrong! But you guys continue to be super helpful.
|
# ? May 19, 2017 20:39 |
|
Dumb question time: Some times when concatenating variables I see people use $($variable) and some times just $variable. What's the difference?
|
# ? Jun 1, 2017 13:31 |
Collateral Damage posted:Dumb question time: Some times when concatenating variables I see people use $($variable) and some times just $variable. What's the difference? The former lets you concatenate with variable-name-valid characters right of the name. E.g.: "Free space: $(variable)MB" If you wrote "$variableMB" it would look for a variable actually named variableMB instead. Actually, what it really does is let you put entire expressions inside an interpolated string, so you can do things like: "Free space: $($freeSpace/$totalSpace*100)%"
|
|
# ? Jun 1, 2017 14:55 |
|
Collateral Damage posted:Dumb question time: Some times when concatenating variables I see people use $($variable) and some times just $variable. What's the difference? I feel like $($var) is more explicit. Additionally, it is more consistent when you may be accessing an object's properties a la $($Var.Prop) which otherwise would come out more like $($Var).Prop generally not what you're intending. In my scripting I use $() in every single case of a variable inside a quoted string much like I refuse to use aliases like GCI instead of get-childItem or cast a variable I expect to be an array and will treat as an array as an array. I want to be clear and specific in my code so there is a little room for misinterpretation and be as explicit as reasonably possible to ensure things work as expected in as many use cases as possible.
|
# ? Jun 1, 2017 14:57 |
|
I figured it was something like that, but some times I see people do it when there's whitespace around as well like "There are $($foo) items available", but I guess there's some value in being consistent.
|
# ? Jun 1, 2017 15:05 |
I certainly think the parentheses makes it easier to pick out when reading code without syntax highlighting, too.
|
|
# ? Jun 1, 2017 15:14 |
|
Collateral Damage posted:Dumb question time: Some times when concatenating variables I see people use $($variable) and some times just $variable. What's the difference? It's to use an entire sub-expression. Inside those parentheses, you can have an entire script; the result of it will be converted/coerced to a string and put inside. If you're using a property of an object, or anything other than the variable name then you would have to use this syntax; I wouldn't recommend using it for other purposes. If you have to disambiguate between the variable name and the rest of the string, or if you have a variable name with odd characters, then you can use the curly brace syntax instead: code:
So you can do either of these: code:
code:
When I must use a sub-expression, like for a property or method call, I often just end up assigning to a local variable instead so the string is nicer. code:
|
# ? Jun 1, 2017 15:40 |
|
nielsm posted:The former lets you concatenate with variable-name-valid characters right of the name. code:
anthonypants fucked around with this message at 17:36 on Jun 1, 2017 |
# ? Jun 1, 2017 17:32 |
|
Hm. Weird question. I'm connecting to Exchange 2010 Powershell from my workstation. I can see my own mailbox via commands like Get-Mailbox. I can't seem to see anyone else's? Does that make sense? The script I'm using to connect is: Function Connect-Exchange {$credentials = Get-credential $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI [url]http://[/url]{Server}/powershell/ -Authentication kerberos import-PSSession $session} I'm using PS 4 if it makes some kind of difference.
|
# ? Jun 2, 2017 16:39 |
You're not passing the credential you prompt for to the Exchange session, so it gets logged in with the account you're running PowerShell under (probably your regular domain account). If you need to use a different login to get administrative access, make sure you're actually passing $credentials to New-PSSession.
|
|
# ? Jun 2, 2017 17:06 |
|
Yeah, change the first two lines of that function block to $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI [url]http://[/url]{Server}/powershell/ -Authentication kerberos -Credential (Get-Credential)
|
# ? Jun 2, 2017 17:14 |
|
nielsm posted:You're not passing the credential you prompt for to the Exchange session, so it gets logged in with the account you're running PowerShell under (probably your regular domain account). I can't believe I missed something so simple. anthonypants posted:Yeah, change the first two lines of that function block to $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI [url]http://[/url]{Server}/powershell/ -Authentication kerberos -Credential (Get-Credential) That'll work even better. Thanks. Irritated Goat fucked around with this message at 17:19 on Jun 2, 2017 |
# ? Jun 2, 2017 17:17 |
|
For what it's worth, you can preserve the $credential variable, but if you're not going to use it after that why leave a variable with your login credentials hanging around? One good use is if you want to connect to all the Office 365 services in one PowerShell window, but that's a different beast.
|
# ? Jun 2, 2017 17:26 |
|
thebigcow posted:No. Update for the zero people that cared: It fixed itself after Windows Update installed some compatibility update.
|
# ? Jun 4, 2017 00:21 |
|
Hey, complete novice, I've got a task to complete: I’m creating calendar appointments for outlook using Exchange Web Service. Is “set extended property” a means for me to append my own id for later use on an appointment? I want to store a (string) member of an associated object when appointments are created so I can find them later for updates, but am not sure where to put it. Or should store in uiCaluid?
|
# ? Jun 20, 2017 01:07 |
|
I'm really sorry to ask this, but there's a jackhammer going on outside my window that's totally destroyed my ability to think. I'm trying to get a list out of AD that has all the expired accounts listed. Not disabled, just expired. I'm using get-aduser, and the property accountexpires, but I can't figure out how to filter by dates. -eq {get-date}-1 does that sound right?
|
# ? Jul 5, 2017 17:41 |
Can't test right now, but basically something like -Filter "accountExpires -lt '2017-07-05'" should work.
|
|
# ? Jul 5, 2017 18:00 |
|
Avenging_Mikon posted:I'm really sorry to ask this, but there's a jackhammer going on outside my window that's totally destroyed my ability to think. code:
code:
anthonypants fucked around with this message at 18:10 on Jul 5, 2017 |
# ? Jul 5, 2017 18:06 |
|
NYC goons, I'm giving a talk at the PowerShell Meetup tonight. Come by if you're in the area. I'll be talking about a module called Idempotion that I created for using DSC resources in scripts.
|
# ? Jul 10, 2017 14:59 |
|
Wait crap no I can't I swear I'll get to another meetup one of these days! Inspector_666 fucked around with this message at 21:06 on Jul 10, 2017 |
# ? Jul 10, 2017 15:54 |
|
Inspector_666 posted:
|
# ? Jul 11, 2017 21:12 |
|
I have a powershell script that automates some file backup, but the script has become slow as the number of files has grown - it's currently copying the entire working directory into the backup locations with each use, when it'd be better to just copy the new files. IE, with the following files, it currently copies all five files, overwriting files 1, 2, and 3 in the backup directory, where it should be copying only file 4 and 5. (The files themselves don't change, so there's no worry that fileX in the backup directory will fall out of date). code:
code:
Suggestions?
|
# ? Jul 20, 2017 19:02 |
|
Newf posted:I have a powershell script that automates some file backup, but the script has become slow as the number of files has grown - it's currently copying the entire working directory into the backup locations with each use, when it'd be better to just copy the new files.
|
# ? Jul 20, 2017 19:05 |
|
Newf posted:I have a powershell script that automates some file backup, but the script has become slow as the number of files has grown - it's currently copying the entire working directory into the backup locations with each use, when it'd be better to just copy the new files. If you're adamant on using powershell, I think you can take out the -force flag and instead add -erroraction silentlycontinue But the real answer is above my post.
|
# ? Jul 21, 2017 00:39 |
|
|
# ? May 14, 2024 10:52 |
|
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. *Like the only reason I can think of where you might not want to use robocopy is because of its weird exit codes (e.g. inside of a Scheduled Task), but those are fairly well-documented, so you can write a wrapper around those or write them to a log somewhere if you really need to validate them.
|
# ? Jul 21, 2017 01:02 |