|
So I borrowed Spudman's script that scrapes computer name/model stuff by subnet. I am now trying to modify it to bring back much more than that. I am having a slight problem though getting memory to come back through the script. To get back memory, I am using this. (Get-WmiObject Win32_PhysicalMemory | measure-object Capacity -sum).sum/1mb How do I throw that in my loop so I can assign it to a variable I have tried a few different things, but here is the error I am getting code:
|
# ¿ Aug 18, 2011 22:49 |
|
|
# ¿ May 2, 2024 14:15 |
|
The <<<< Computer part was added in once it errored out. For the code, I need the | measure-object Capacity -sum as if I just do Get-WmiObject Win32_PhysicalMemory, it brings back a table of stuff that I am not interested in. I feel like this is getting close, I am just missing something stupid. $mem = (Get-WmiObject Win32_PhysicalMemory | measure-object Capacity -sum).sum/1mb -Computer $ip -Credential $creds -ErrorAction SilentlyContinue | ForEach-Object {$_.Capacity}
|
# ¿ Aug 19, 2011 15:21 |
|
Mully Clown posted:
Yup, you were correct, I am an idiot. I think I missed a chunk of that line you wrote when I copied it. Thanks. Now time to figure out all the other cool things I can add in to this. Also, suggestions on a good PS book from anyone? I actually found this book in my office, it's almost 5 years old though. http://www.amazon.com/Microsoft-PowerShell-Programming-Absolute-Beginner/dp/1598633546/ref=sr_1_1?ie=UTF8&qid=1314050807&sr=8-1
|
# ¿ Aug 22, 2011 23:07 |
|
Clanpot Shake posted:I'm not sure if this is the best place to ask, but I've got a question for people who know Windows scripting. We have an AD setup where about half of the users are missing a piece of required software. Rather than installing this one by one, we want to run a logon script to install and configure it using elevated privileges. We're a newly setup department so we don't have SCCM or similar to push out software yet, so this will be a one-time thing. What software are you installing? The GPO megathread in SH/SC is a good place to start for things like this. You will probably need to turn that exe into an msi, so look into something like http://www.advancedinstaller.com/ It works, but can break some installers. You can then use that with a script to check to see if it is installed, then decide if it needs to be installed or not. I have not gotten that far along with this (my environment still has users manually updating flash/java/ff, and I hate it), but that seems to be the route to go.
|
# ¿ Sep 2, 2011 09:16 |
|
adaz posted:Honestly I never trust Export-CSV anymore and just use my own custom objects added to a list then export that. I've run into more cases where it doesn't work than where it does. This is awesome. I will probably work towards doing this for some of the things I am setting up. I finally have some free time so I started getting into my PS book. We have alot of user accounts in AD that are missing phone numbers, so I wrote/modified a little script to give me the names of these accounts. I figure next step is let it take arguments (or build it a little gui) so I can search for other empty attributes and allow it to select which OU to search instead of just the root of our users OU.
|
# ¿ Nov 24, 2011 02:01 |
|
Looking for a quick pointer in the right direction. Had some success last night using powershell to do some bulk file renaming at home. Get into work today, now I actually get to try and use some of that! I would like to try and hack through alot of this on my own, but currently I am trying to take a directory with some files in it, then go through and create a folder in that directory with the name of each file name. Example would be I currently have c:\ps which contains a.txt b.txt c.txt I need to then create 3 folders, c:\ps\a, c:\ps\b, c:\ps\d Once that is created, I need to move the respective txt files into the respective folders. Currently hung on creating the folders by the file names. I was trying something along the lines of code:
|
# ¿ Dec 21, 2011 16:07 |
|
adaz posted:You were very close -- just need the basename (which omits the file extension) and to put the piepline input in quotes so powershell expands it before attempting to pass it to the parameter - which results in a null being passed and the new-item trying to create the root directory over again Didn't know that name would grab the extension as well. I am still having a problem as $_ isn't pulling files from that directory. This script will just create a folder called .basement, then error out for the rest of the items.
|
# ¿ Dec 21, 2011 16:53 |
|
Thanks guys, that worked perfect. Now I am stuck on moving the files into the newly created folders. I am trying to do something like this, but it is clearly wrong. code:
Edit If I add in the full path, it will just renames the files without moving them. Both the lines below dont move anything, but rename both the files and the folders (appends a .basename to the end). Don't know why powershell is so difficult for me to grasp. code:
Moey fucked around with this message at 21:29 on Dec 21, 2011 |
# ¿ Dec 21, 2011 21:24 |
|
adaz posted:You are formatting the destination part wrong at first glance. Should be something like this Makes sense and works! It spits out errors but still moves the files. I think it is trying to move the folders as well. If I run it on a directory with 1 file, I get 1 error. 3 files, 3 errors. Don't think it matters, not sure though.
|
# ¿ Dec 22, 2011 02:30 |
|
Woop woop. Ran it today on the production data and everything worked. Could not get the moving to ignore folders, so when it hit that line, I had 1350 errors scrolling across my PS window, but it all worked out.code:
Edit: Just out of curiosity sake, how would I add "where-object {$_.psiscontainer -eq false}" to my last line of code there? Everything I try breaks it. Moey fucked around with this message at 17:26 on Dec 23, 2011 |
# ¿ Dec 23, 2011 16:52 |
|
|
# ¿ May 2, 2024 14:15 |
|
Jethro posted:Note that it's $false not false Thanks for that. Outside the $ I was pretty close just by trial and error. I had the same thing, but I had the conditional statement (psiscontainer) after move-item.
|
# ¿ Jan 4, 2012 15:48 |