|
VBScript related question (Don't shoot me!) I have the following subroutine in a script that uses wbadmin to back up a folder locally, rename it, then transfer the renamed backup folder to a network drive: code:
What would be the simplest way to write a text file with whatever error my script is running into at this point?
|
# ¿ Oct 6, 2011 20:17 |
|
|
# ¿ May 6, 2024 12:00 |
|
What is the correct way to use a variable that is a command line program in a script? I'm kind of new so I'll try to make it clearer: I am trying to run a mysql dump as part of a powershell script. I've defined the following variables: code:
code:
code:
Any tips? Also is this going to behave differently in my script than if I'm running it right from the PowerShell console?
|
# ¿ Dec 20, 2011 17:25 |
|
Aha, that works beautifully. I also decided that adding the C:\Program Files\MySQL\MySQL Server 5.1\bin\ to the script environmental path would be easier to deal with as well:code:
code:
|
# ¿ Dec 20, 2011 22:30 |
|
More loving noobie questions: I am rewriting a vbscript script that we currently use to work around the horrible Windows Server 2008/R2 backup feature. Right now part of the vbscript looks as such: code:
code:
|
# ¿ Dec 21, 2011 16:16 |
|
Okay, thanks for that clarification. The reason the vbscript is run like it is, is because that the results are later send via email, and from what you said regarding functions, you can't actually store the results as a variable that exists outside the function? I was under the impression that Functions functioned () somewhat like subroutes in vbscript. Is that not the case? If I DID want to store the results to call back on, but keep it inside the function, is that even possible?
|
# ¿ Dec 21, 2011 16:43 |
|
Sweet. HOWEVER, I have to be setting my function incorrectly, or something. When I call my function it returns a blank result, but if I comment out the function part of it so I'm left with:code:
Any ideas?
|
# ¿ Dec 21, 2011 16:57 |
|
Yeah, now it works. Thanks a bunch
|
# ¿ Dec 21, 2011 17:05 |
|
So what's the proper way to go about getting folder paths with spaces to parse properly in powershell? Example: code:
code:
code:
|
# ¿ Dec 22, 2011 18:37 |
|
code:
|
# ¿ Dec 22, 2011 19:18 |
|
Okay, so I have this stupidly large function I am using to verify my backup results. A previous function moves/renames the Windowsimagebackup folder to a network share, then this function verifies that that path exists, and if so removes the backup folder from the local drive. Heres the code: code:
What's the right way to debug a function, if you have to load the function into memory before you can even run it later with the function name?
|
# ¿ Dec 27, 2011 15:38 |
|
How would one discover if a file was created on the first weekday in a month? I can find a bunch of examples from years ago that use vbscript, but none do 100% what I need
|
# ¿ Jan 4, 2012 21:50 |
|
Mario posted:What if the 1st is on a Monday? This would match Tuesday and Wednesday as well. Awesome, I was able to make that work with 99% accuracy. Actually all of that Saturday/Sunday stuff I don't even need since the folders are only created on Weekdays. If I wanted to return a list of folders, but exclude any created in the previous month, how could I do that? I know I can filter my results with something like code:
Any ideas? Wicaeed fucked around with this message at 18:12 on Jan 5, 2012 |
# ¿ Jan 5, 2012 17:30 |
|
Hmm good point. Is there any way to format the value of the file/folder CreationTime to match a get-date format of Myyyy (January 2012 would be 12012, November 2011 would be 112011, and so on). I honestly don't really need the date, I'm just filtering out files the current and prior month, the date filtering comes later: http://pastebin.com/WqUp6gxF Edit: Actually I came across a realization. I don't need to filter on the first weekday of the month, but the first Friday of the month, and this makes it much easier simple because The year doesn't matter, because at the point where this script has been running that long I will already have the only backup I want for that time period (the first Friday in the month), and the first Friday will always fall within the first 7 days of the month. code:
Tell me I'm not wrong in my assumption Wicaeed fucked around with this message at 18:21 on Jan 6, 2012 |
# ¿ Jan 6, 2012 17:09 |
|
Quick question, made harder because I don't know what the actual name is for it: I'm using the following script to get the Month number (1 = January, etc) so that I can include/exclude files from backup based on if they are the current are prior months, without having to worry about the date. code:
I'm trying to do something similar for whatever a files creation time was for the week , however I can't find a way get the date/time in that format with the pipeline object $_.CreationTime. I've been reading this Powershell Blog on how the author goes about adding a membertype to the get-date method: http://blogs.technet.com/b/heyscriptingguy/archive/2011/07/08/use-powershell-to-get-the-number-of-the-week-of-the-year.aspx I was wondering if you could do something similar code:
Can you manually add a method to do that type of math? I hope I'm making sense, I'm still pretty new to this and a lot of the terminology isn't there
|
# ¿ Jan 11, 2012 17:57 |
|
What is the most simple way to save the result of each iteration of a Foreach loop? For example I have the following loop: code:
Right now the write-host lines are there simply so I can see what is going on at the command line. I don't quite understand hash tables or arrays yet, which is what I think I need to properly get this working. Any tips?
|
# ¿ Feb 2, 2012 15:05 |
|
Walter_Sobchak posted:So, two stupid things I'd like to learn how to do. Honestly, at this point, I'd like to know if they're even possible. I can (hopefully) figure out the actual mechanics. I've only ever had experience scripting with batch files, so for now, I'd like to just use those. If not, hey, always good to learn something new, right? Yay I finally get to help someone! I'm doing pretty much this exact thing with a backup script You can sort objects oldest to newest by creationtime with the following: code:
code:
Wicaeed fucked around with this message at 16:05 on Feb 2, 2012 |
# ¿ Feb 2, 2012 15:52 |
|
adaz posted:Ridiculously awesome stuff Holy poo poo, so much useful information there Wait, I thought that variables not defined outside of a function can't exist outside it? e.g. the difference between $global:variable and $variable, etc...
|
# ¿ Feb 2, 2012 18:32 |
|
Cool. Another question: In the email I am getting with the results, the formatting is crapping everything out on a single line, like so: code:
code:
|
# ¿ Feb 2, 2012 19:55 |
|
Mmmm, I don't think that's it. I have another script I use to send a separate email, however it uses two variables that only ever output a single line of text. I had to edit the body of the email to add some breaking code:
|
# ¿ Feb 2, 2012 21:31 |
|
What's the easiest way to break out of a scriptblock in Powershell? I have a script that will generate quite a few errors if a variable is not set, which can happen if it is a certain date. Can I add a simple If/Else statement to say something like: code:
I've got two variables, one is a folder path, the other is a filename variable. I would like to combine the two to test the existence of the destination file. Code snippet follows: code:
code:
Wicaeed fucked around with this message at 17:26 on Feb 29, 2012 |
# ¿ Feb 29, 2012 17:03 |
|
So recently I've noticed some strange behavior in Powershell ISE and scheduled tasks. I can load up/edit a script in ISE, and when it comes time to run it, I hit F5. This loads the script but nothing really happens. I have to manually type the function that is calling each scriptblock in to the powershell CLI to get it to run properly. This is affecting scheduled tasks as well. I did install Powershell 3.0 beta on my workstation and have been using it to remote powershell tab to my servers, but I still have 2.0 installed on my servers, however it happens on the servers as well if I am using Powershell ISE in an RDP session. Any ideas, as I'm completely befuddled by this behavior.
|
# ¿ Mar 5, 2012 17:02 |
|
Seriously, I've quite thoroughly enjoyed my time with Powershell thus far, I just wish I had more excuses to use it at work
|
# ¿ Mar 7, 2012 15:50 |
|
Before I spend too much time writing a new script, does anyone know of a pre-made Powershell script that I could use to pull a list of user-created scheduled tasks off of a server and tell me what credential and/or username it is set to run as?
|
# ¿ May 8, 2012 16:09 |
|
So I saw this posted on Reddit, give a really good overview of Powershell for those trying to learn it, and also gives a lot of good tips on script creation: https://www.youtube.com/watch?v=-Ya1dQ1Igkc For example, I didn't even know of the show-command cmdlet. Blew my fuckin' MIND, man.
|
# ¿ Jun 11, 2012 14:50 |
|
The remoting feature looked pretty awesome, but it strikes me that third-party applications that run on the server are going to be negatively impacted by removing the Windows Server gui. Our monitoring system (PRTG) relies on a GUI-based control panel that runs on the server. Is there a way (with ps remoting) to redirect GUI content to another computer?
|
# ¿ Jun 12, 2012 13:39 |
|
So, does anyone know if it's possible to import all of the PowerCLI modules directly into Powershell or Powershell ISE? edit: nm, apparently code:
Wicaeed fucked around with this message at 18:30 on Jun 21, 2012 |
# ¿ Jun 21, 2012 17:59 |
|
:facepalm: So for the long time was trying to get a powershell script that (simply) let me know if the current day was the first weekday of the month. For mailing purposes I send an email based on whether or not that is true code:
|
# ¿ Sep 5, 2012 21:17 |
|
So this is kind of a stupid question: Company has a need to sign executable files with a cert and time stamp from verisign. This is handled by a relatively simple command line command, but it requires the use of a Windows SKD CMD Shell. Ideally, I would like to create a script that I can use to simply drag an executable to be signed over, and have poweshell work it's magic. I'm having a devil of a time finding out how to really DO this, however. Tips/Hints?
|
# ¿ Nov 29, 2012 00:59 |
|
Titan Coeus posted:In that situation, you can make a batch script that accepts the drag and drop, and have that pass the command line argument to the power shell script. I actually read that exact post on Stack Overflow and tried it, but for some reason whenever I drag and drop a file the batch script seems to die as it is passing the entire file contents instead of just the path to the powershell script
|
# ¿ Nov 29, 2012 20:43 |
|
Quick question regarding this script (a friend wrote it and I tweaked it): http://pastebin.com/RRxeK3CF If I wanted to return only servers that match a certain part of the results on the 'logonserver' portion, or the 'NTP Source' result, how could I do that?
|
# ¿ Oct 25, 2013 22:59 |
|
Has anyone used Powershell & racadm to gather system inventory from a local system?
|
# ¿ Jan 16, 2015 02:38 |
|
Kind of a long shot, I recently found this script here Kind of a long shot, I recently found this script here that can be used to clean up folders on a server. I'm going to use it, but I was wondering if there would be an easy way that I might be overlooking to include the name of the server on which it was run, either as the email subject or in the log file anywhere. I'm kind of new with Powershell, but I figure I'd ask before I start trying to edit the script to do something like that.
|
# ¿ Apr 17, 2015 02:18 |
|
Forgot that there was an optional -EmailSubject field that isn't required, but is automatically set to a string with a few variables. Just set $ComputerName = gc env:computername and called the variable in the default subject line. Not really too pretty, but it works. code:
|
# ¿ Apr 17, 2015 20:08 |
|
PowerCLI Time: Trying to count the number of vCPUs that have been configured in a VM resource pool in our vCenter server. Problem is that we have similarly named resource pools across multiple clusters. I wrote something that can get me 90% of what I'm looking for, what I really need is the total count across all resource pool instances: code:
code:
edit: Derp, apparently you can do this in one line on PowerCLI and not even have to worry about duplicate named resource pools. code:
Wicaeed fucked around with this message at 01:49 on Aug 11, 2015 |
# ¿ Aug 11, 2015 01:36 |
|
Is there a way to break up a single line powershell command across multiple lines, allowing for easier readability, but still being able to copy/paste it directly into a Powershell prompt? I've got something like code:
|
# ¿ Dec 29, 2017 22:15 |
|
Has anyone run into issues with VSCode not properly honoring PSBreakpoints while debugging Powershell? I'm used to ISE, in that I add a breakpoint & ISE always honors it, however in VSC I add a breakpoint on something even as simple as a comment and VSC just blows right past it sometimes. The heck?
|
# ¿ Sep 10, 2018 21:50 |
|
|
# ¿ May 6, 2024 12:00 |
|
Anyone used the module here before? https://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb/view/Discussions/4 It's useful (in that it works), but I'm having issues when dling large files (50+GB) over and over as the Get-FTPItem always overwrites the local file, even if they are the same and already present on local disk
|
# ¿ Nov 20, 2018 21:41 |