|
Is there a recommended book for learning Powershell? I see the Lunches book but only one I can find is for Powershell 3 which appears to be 2 versions old.
|
# ? Oct 15, 2014 16:14 |
|
|
# ? May 15, 2024 13:17 |
|
Not that much has changed that the lunches book wouldn't be a great resource. In my opinion the best way to learn is to find some common task and create a script or short program that automates it. I wrote a thing for RSA softkeys that really pushed me to look deeper at .net framework stuff.
|
# ? Oct 15, 2014 16:43 |
|
ElGroucho posted:Not that much has changed that the lunches book wouldn't be a great resource. I wrote a thing to pull properties from Enterprise Vault shortcuts in Outlook and then use those properties to restore the real item back into mail stores, a bit of .Net lifting was done there. It gave me a bigger insight into how PoSh behaves.
|
# ? Oct 15, 2014 17:02 |
|
Anybody have experience with the AWS PowerShell cmdlets? Anything I should know before I start using it?
|
# ? Oct 17, 2014 23:33 |
|
This is really rudimentary, but then so am I when it comes to scripting. I want to read a registry key that varies from system to system depending on what printers are attached via TCP/IP ports and then return whether the value is true or false. If True (1) then I want to go ahead and change it to False (0) I found the following online, but it breaks on trying to pipeline to GetProperty code:
code:
|
# ? Oct 21, 2014 18:39 |
|
I really dislike aliases such as % ? etc in Powershell, it makes reading code frustrating and more confusing, not to mention can actually result in some problems if you accidentally shorten your command(s) too much or use the wrong one. It's not like there is a 140 character limit in scripts or commands, type it out, tab complete it. Powershell is way easier to use and read when done in a verbose way. I'd do something like this, for your problem: (this is very rough and probably won't work right away, it's more the logic I'm aiming at here) code:
|
# ? Oct 21, 2014 18:49 |
|
The alias is used because under "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" are varying subkeys such as printerX.ad.bob.com and hp4500.ad.bob.com and each of those keys, which will vary from system to system in both name and number of existing keys, contains a value called SNMP Enabled. So the script needs to iterate through each of the subkeys to get to the value, as it's not present directly under the "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" key.
|
# ? Oct 21, 2014 19:18 |
|
Spazz posted:Anybody have experience with the AWS PowerShell cmdlets? Anything I should know before I start using it? yes; no, they are pretty easy to use, what things are you looking to do? e: good resources here http://docs.aws.amazon.com/powershell/latest/userguide/pstools-using.html Slow to the party as well, have people seen http://www.powertheshell.com/isesteroids/ ? amazing nzspambot fucked around with this message at 06:31 on Oct 27, 2014 |
# ? Oct 27, 2014 06:06 |
|
nzspambot posted:yes; no, they are pretty easy to use, what things are you looking to do? EC2 + ELB provisioning using Launch Configs + AutoScaling Groups, R53 updates, and RDS management. I skimmed the cmdlets and it looks like I should have enough to make it work. nzspambot posted:Slow to the party as well, have people seen http://www.powertheshell.com/isesteroids/ ? amazing Actually no, I'll have to try this.
|
# ? Oct 27, 2014 12:20 |
|
Is it possible to make a text-based UI within Powershell that dynamically updates existing text? I'm playing around with Azure and am trying to make a helper script to automate the manipulation of VMs. Starting a VM takes more than a few seconds, so I want to code something up that starts the VM and then posts its status (via Azure-GetVM) as it updates. Then, once the VM reports as StartedVM I can launch a URL to a site hosted by the VM. I'm thinking something along the lines of, you see the following output in the console just before starting the VM: pre:VM Name Status TestVM1 StoppedVM
|
# ? Nov 11, 2014 22:06 |
|
Karthe posted:Is it possible to make a text-based UI within Powershell that dynamically updates existing text? I'm playing around with Azure and am trying to make a helper script to automate the manipulation of VMs. Starting a VM takes more than a few seconds, so I want to code something up that starts the VM and then posts its status (via Azure-GetVM) as it updates. Then, once the VM reports as StartedVM I can launch a URL to a site hosted by the VM. Write-Progress
|
# ? Nov 11, 2014 22:26 |
|
I wrote a script to log off disconnected RPD users. Windows Server 2008 **Not R2** I found the first part on the internet, it basically arranges the dos command "QUERY SESSION" into something powershell can use. I think it makes sense. The second half is me and I don't know why it works the way it does. code:
code:
Is there a better way to do this that makes a little more sense?
|
# ? Nov 15, 2014 06:41 |
|
$disconnecteds is a collection of records, so $disconnectds.Id doesn't make any sense because $disconnecteds doesn't have an Id, it has records, and those records have Ids.
|
# ? Nov 18, 2014 17:24 |
|
Jethro posted:$disconnecteds is a collection of records, so $disconnectds.Id doesn't make any sense because $disconnecteds doesn't have an Id, it has records, and those records have Ids. I think I'm probably just not understanding the format and need to read the help files a few times. Let me know if I'm off here, but I think I was misunderstanding how foreach works. I thought that the way it worked was that you have a set of records and that they already have a naming scheme. Is what's really going on that $disconnecteds has a bunch of records in it and then when I say "foreach x in y" I'm creating a naming scheme for the subrecords. I'm not at work so I can't test this, but would something like this make more sense? code:
code:
I think I was having a hard time getting -whatif to work in this script as well, where would be the right place to put that?
|
# ? Nov 18, 2014 17:54 |
|
This is how I would do it. Unless you need to have all that information in the first command, it may be faster to build your list of disconnected sessions this way...code:
code:
Anyway, to answer your question, this would work with the current code: code:
|
# ? Nov 19, 2014 23:34 |
|
Spazz posted:I just wouldn't use such similar variables like "disconnecteds", "disconnected", etc. It'll be a lot easier to read and maintain in the long term when you use more specific names. Sounds good, I'm going by the examples I've read in the help files. They have stuff like foreach $tent $tents. I can see how it'd be better to do something like foreach $tent in $campsite. This here: code:
So now I'm starting to worry about code signing and stuff. Is that kind of thing dependent on an already existing signature infrastructure? I've never played with code signing. Is that overkill for a script that's just going to be sitting on a server running as a task every night?
|
# ? Nov 20, 2014 01:26 |
|
Dr. Arbitrary posted:Sounds good, I'm going by the examples I've read in the help files. They have stuff like foreach $tent $tents. I can see how it'd be better to do something like foreach $tent in $campsite. That's just my preference. Sure, you can do ForEach($tent in $tents), but I think ForEach($tent in $campsite) looks cleaner and it's more descriptive of the group/object/list ($campsites) and what you are calling upon ($tent). As for code signing, look into setting the execution policy (Set-ExecutionPolicy -?).
|
# ? Nov 20, 2014 01:53 |
|
I need to open WINWORD.EXE, wait for it to open (it loads some templates from a network share), then close it. Is there a more elegant way than using code:
|
# ? Dec 5, 2014 03:45 |
|
Swink posted:I need to open WINWORD.EXE, wait for it to open (it loads some templates from a network share), then close it. code:
|
# ? Dec 5, 2014 18:22 |
|
Cross-posting from the general programming questions thread: Simple PowerShell question- Using "Copy-Item" to push out files over a network, if the PC doesn't have a valid security certificate or a trust relationship with the domain I get numerous write.IO errors. When that happens the program crashes right afterwards even though I have "-EA" set to "Continue", and even though I have "-EV" set to write out the failure it never gets to that point before it crashes. Any idea on how I can catch this error without my program crashing?
|
# ? Dec 9, 2014 18:30 |
|
This is not a helpful answer and I apologize in advance, but honestly I still use robocopy for network file transfers. Given any thought to that?
|
# ? Dec 9, 2014 18:39 |
|
CLAM DOWN posted:This is not a helpful answer and I apologize in advance, but honestly I still use robocopy for network file transfers. Given any thought to that? Hmm, thanks for the suggestion, but it doesn't appear that robocopy can use local directories without specifying a drive letter, which wouldn't work in my environment. quote:ERROR : Invalid Parameter #1 : "..\PushDirectory\PushRoot\*"
|
# ? Dec 9, 2014 18:54 |
|
Brady posted:Hmm, thanks for the suggestion, but it doesn't appear that robocopy can use local directories without specifying a drive letter, which wouldn't work in my environment. You can call robocopy from Powershell. Build the specific robocopy command you need as a string, then run it.
|
# ? Dec 9, 2014 19:01 |
|
Brady posted:Hmm, thanks for the suggestion, but it doesn't appear that robocopy can use local directories without specifying a drive letter, which wouldn't work in my environment. No, you're getting that error because you're specifying *. Robocopy takes in folder names, not file names. Specify ..\PushDirectory\PushRoot
|
# ? Dec 9, 2014 19:05 |
|
Brady posted:Cross-posting from the general programming questions thread: Simplest solution would probably be to have a valid trust relationship with the domain. It's also kind of odd that you describe it as a "program crashing". Are you running this from a powershell console or from the ISE? Is it compiling to an executable or something? If you run it from the ISE you should definitely get your terminating error output. For your actual question though, I think you've got 2> to redirect stderr, $lastexitcode, $?, and I think if you run a script/program with Start-Process, you have the built-in parameters -RedirectStandardOutput and -RedirectStandardError. But it sounds like you already have your error - you can't copy a file if you don't have permissions. It's strange that you are getting Write.IO errors instead of the standard "Access denied", which has happened to me probably hundreds of times when I forget which context I am running powershell as.
|
# ? Dec 9, 2014 19:09 |
|
Erwin posted:No, you're getting that error because you're specifying *. Robocopy takes in folder names, not file names. Specify ..\PushDirectory\PushRoot Ah, duh. Reiz posted:It's also kind of odd that you describe it as a "program crashing". Are you running this from a powershell console or from the ISE? Is it compiling to an executable or something? If you run it from the ISE you should definitely get your terminating error output. Yeah, it opens a command window and all output gets directed to there as well as two separate log files. I tried it with the ISE and here's the exception I get. The first few lines are my own output, and then you can see the error. I was incorrect before by saying it was a "Write.IO" error. Keep in mind that the PC is checked to see if it's available and online before any copy command is executed. Also, I have SA privileges to all machines on the domain. quote:14.10.31: Pushing to the following stations: That's from the ISE. After that it just stops dead. I'm not sure why it's giving an argument exception for the PC even though when it checks initially it reports that the PC is online. Reiz posted:For your actual question though, I think you've got 2> to redirect stderr, $lastexitcode, $?, and I think if you run a script/program with Start-Process, you have the built-in parameters -RedirectStandardOutput and -RedirectStandardError. But it sounds like you already have your error - you can't copy a file if you don't have permissions. The issue shouldn't be related to permissions as far as I know. I'm gonna try the robocopy thing, but I'm still interested in why I'm getting this error. It's working for most all other computers I use it on, except for a select few that give this error. LiterallyAnything fucked around with this message at 21:24 on Dec 9, 2014 |
# ? Dec 9, 2014 21:21 |
|
Quote != Edit
|
# ? Dec 9, 2014 21:24 |
|
Briantist posted:You can use automation: It doesnt load anything when launching this way. I need Word to run all its "stuff" as if it was launched by a user. I managed to get it to work by opening an actual word doc that contains an "on open" Macro to quit the Word Application. It works well enough. code:
|
# ? Dec 10, 2014 01:20 |
|
This is how I did it a few weeks ago, but in my case the macro was in the Normal.dot template file...code:
|
# ? Dec 11, 2014 00:22 |
|
Thats even better. Thanks. New query: Can I create an empty hashtable, fill it with data and then splat it? I'm reading data from a form, putting it in an array with the intention to use it for Set-ADUser @param This is what I have so far, but i cant call @userDetails. How should I be setting this up? code:
I have to change my hashtable keys to the same name as the command I"m going to use them on. There's no -FirstName command for set-mailbox. Swink fucked around with this message at 04:07 on Dec 11, 2014 |
# ? Dec 11, 2014 00:35 |
|
Swink posted:Thats even better. Thanks. The keys in the hashtable need to match the parameter names of the cmdlet/function: code:
|
# ? Dec 12, 2014 03:55 |
|
Is there a way for PS to send a WOL request to a target PC over a network with just the PC name, WITHOUT requiring the MAC address? Or, if there's no way around requiring a MAC address, a way to get said address and then plug it into a WOL request automatically?
|
# ? Dec 22, 2014 18:16 |
|
Brady posted:Is there a way for PS to send a WOL request to a target PC over a network with just the PC name, WITHOUT requiring the MAC address? Or, if there's no way around requiring a MAC address, a way to get said address and then plug it into a WOL request automatically? Can't answer the first question, but for the second part you can look that up under DHCP leases.
|
# ? Dec 22, 2014 18:26 |
|
I have a super annoying problem that I hope someone can help me with. The situation is this: We have a webservice that fires off various Powershell commands, most of them Exchange related. It's a .NET ASP.NET webservice, and is hosted on IIS on a Windows Server. I recently changed the Powershell logic to use Powershell remoting (the session is now made on our Exchange 2013 server instead of on the webservice-server), although this did no difference with regards to my problem. The service fires off several commands that work fine and return results as they should. Among them are: Get-Mailbox, Enable-DistributionGroup, Add-MailboxPermission, Add-ADPermission, Enable-Mailbox, plus others. Recently I tried to add functionality to add mailbox folder permissions, using these two commands: Get-MailboxFolderStatistics Add-MailboxFolderPermission Neither will work. The first command I'm trying to make work is Get-MailboxFolderStatistics, because I want the localized name of the user's calendar folder. For example, the calendar folder in Danish is called "Kalender", and I need this name in order to be able to add folder permissions with Add-MailboxFolderPermission. What's truly absurd is that if I remote to the server, log in as the user the webservice is running as, and fire off the command in a shell, it works. Through the webservice .NET code however, no results are returned. The user running the webservice is a domain admin and has all the permissions required (I think?) to be able to execute the command, and as said it works when I do it by hand. Run through the service however, I get no errors, just no results, using the same parameters as executed by hand. Add-MailboxFolderPermission is the same - it just does nada (when I hardcode the calendar name). Any ideas?
|
# ? Dec 23, 2014 10:13 |
|
Pilsner posted:Any ideas? This sounds like a Kerberos double hop issue of some form. Make sure all the powershell is being launched by the app pool with no passthrough authentication. Bonux points if you spin up a PS host within the .Net code itself. I believe there are some existing .Net examples of doing this around. This should hopefully keep everything internal to the Application Pool's process and avoid a double hop. Alternately you could configure kerberos delegation for the Web Server.
|
# ? Dec 23, 2014 15:38 |
|
AreWeDrunkYet posted:Can't answer the first question, but for the second part you can look that up under DHCP leases. Do you know if I can query that information from the DC via PS?
|
# ? Dec 23, 2014 16:02 |
|
Brady posted:Do you know if I can query that information from the DC via PS? There are some native PowerShell DHCP cmdlets, but I've never had a chance to fool around with those. I typically just use netsh dhcp commands which PowerShell calls without issue. PS DHCP - http://technet.microsoft.com/en-us/library/jj590751.aspx netsh DHCP - http://technet.microsoft.com/en-us/library/cc787375.aspx
|
# ? Dec 23, 2014 16:14 |
|
AreWeDrunkYet posted:There are some native PowerShell DHCP cmdlets, but I've never had a chance to fool around with those. I typically just use netsh dhcp commands which PowerShell calls without issue. Thanks for the info!
|
# ? Dec 23, 2014 16:22 |
|
I need to crop 200 .txt files down to 500 words each. I am completely new to Powershell, but from what I've found on Google it seems like it should be able to do the job with a simple oneliner. All of the examples I've found on stackoverflow and the like deal with characters, not words. Is there anyone who would be willing to solve this for me? I'm not looking for anything linguistically sophisticated; I'd be happy with something that simply counts up to 500 spaces and/or returns and then splits the file. Thanks in advance for any help. EDIT: Never mind, did it with a regex find/replace in Notepad++. cactuscarpet fucked around with this message at 13:39 on Dec 28, 2014 |
# ? Dec 28, 2014 12:21 |
|
|
# ? May 15, 2024 13:17 |
|
Very simple script here. It works on one machine but not another. On the machine it doesn't work on, a command window comes up for a brief second showing some error that I can't read and then closes. When I run the script via the ISE however it works perfectly so I have no idea how to capture the error. Anyone know what the issue could be? Here's the script- $user = Read-Host "Enter the AD Account you wish to target" $newpwd = Read-Host "Enter the new password" -AsSecureString Set-ADAccountPassword $user -NewPassword $newpwd Reset
|
# ? Dec 29, 2014 20:04 |