Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Phone
Jul 30, 2005

親子丼をほしい。
Background: To kill some time at work and "increase my worth" (read: kill time) I've read up on some Powershell tutorials. I'm new to IT so tricks aren't popping out of my rear end all of the time and I'm really loving horrid at programming, but today was a day where I knew I could have streamlined a lot of stuff just if I knew a bit more; I know how batch files work and I know that PS can do all sorts of fun things. I decided to make a batch file to silently install a dozen Windows Updates, it took me a few tries but I figured out the syntax. I did it the long way and just copied the whole path and filename into notepad to do it. I know that there's a super easy way to get this done with less ctrl+c/v action.

The meat: I can get PS to just dump all of the files with the
code:
get-childitem -Filter *.msu -Name | out-file yourmom.txt
but I want to get it where I can put a string before and after so I can make a batch file without the ctrl+c/v action.

Basically I want to go from
code:
KB1.msu
KB2.msu
KB3.msu
To
code:
fancy.exe $directory-path/KB1.msu /flag1 /flag2
fancy.exe $directory-path/KB2.msu /flag1 /flag2
fancy.exe $directory-path/KB3.msu /flag1 /flag2
But I'm horrible at programming.

Adbot
ADBOT LOVES YOU

Phone
Jul 30, 2005

親子丼をほしい。
That will execute the command though, not output it to a batch/text file, correct? I think that might be another gotcha. I'm looking to do it this backward rear end way because I'm updating thin clients with Windows 7 Embedded.

Phone
Jul 30, 2005

親子丼をほしい。
Did you submit your issue to Hey, Scripting Guy!? If not... uh... :tinfoil:

That said, I'm totally stealing the hell out this so I can audit the PCs at my work easily.

Phone
Jul 30, 2005

親子丼をほしい。
I'm trying to either run a Get-Process or start a PS Session on a remote computer/server at work and everything I throw at it has it's own special error related to which method I try:

Enter-PSSession -ComputerName ComputerName = hangs for a bit then spits out that it can't resolve
Enter-PSSession -ComputerName ComputerName.domain.com = instantly spits out that it can't resolve
Enter-PSSession -ComputerName IP = NOPE, your authentication won't allow it
Enter-PSSession -ComputerName IP -Credential domain\my.user = NOPE, your authentication won't allow it

All of these are Win7 boxes with names and IPs associated with them, but PS won't resolve to the hostname and bitches at me when trying to do it via IP.

Halp. :<

Phone
Jul 30, 2005

親子丼をほしい。

adaz posted:

If you just do a blame nslookup do the computer names resolve? Are the computers not joined to the same domain/forest?

The computers are all on the same domain/in the same OU in AD.

Phone
Jul 30, 2005

親子丼をほしい。

adaz posted:

Can you resolve them with nslookup? What exact authentication error are you getting? I've only ever seen the authentication errors/token errors if the shell isn't running as an admin (assuming domain authentication is correct & you are in the local admin groups on the remote machine)

Logged in today at work and got it to work as soon as I ran WinRM on the target computer. I'm going to chalk it up to 1 part "our DNS loving sucks" and 2 parts of "hot drat does our RDSFARM eat a bag of dicks." I saw the Technet blog about and it is simple, but WinRM seems to be a gaping security hole if I'm interpreting the quickconfig correctly: "allows listening on [url]http://*[/url]". :tinfoil:

I'll be back in this thread soon enough, I'm trying modify a goon-made script to report back OS caption and version (yay computers that still don't have W7 SP1).

Thanks guys.

Phone
Jul 30, 2005

親子丼をほしい。

Jelmylicious posted:

e: Aparently Get-Eventlog System should work too, so your second line should work as intended. Apart from it not showing the full info in your text file. So, at least use the export-csv.

And then cry when the formatting is all messed up.

Phone
Jul 30, 2005

親子丼をほしい。
Export-CSV is awesome and works most of the time, but when you get on one of those edge cases where whatever list of data you're trying to enumerate and get into a readable format it sucks.

Luckily Technet has a ton of stuff about PS and a decent # of articles about piping stuff to Export-CSV.

Phone
Jul 30, 2005

親子丼をほしい。
Is there a way to delete a row out of a CSV and then be able to export it out?

I know that $null will kill the row if you do something like $var[$i]=$null, but then Export-Csv throws an error about null values in a row when trying to export it out.

Phone
Jul 30, 2005

親子丼をほしい。
So I've been tasked with automating some auditing because the previous method was some lengthy and involved process that included Access databases. I'm pretty much done with all of this due to Powershell.

God drat I loving love the Import-Csv cmdlet.

I'm horrible at programming, but I am apparently a programming god to my coworkers because I know about for loops and know about objects/arrays.

Phone
Jul 30, 2005

親子丼をほしい。
Ugh, this is gonna hurt: 800k+ files in 7 directories; delete all files older than 60 days. I know I saw something about Powershell performance tapering off before, but I can't remember where I saw it.

I just hope that my gci -recurse works. :toot:

Phone
Jul 30, 2005

親子丼をほしい。
Looks like I barely got by, haha. It was 7 folders in a share that has close to 30 folders total, so each folder had it's own gci call. It went surprisingly fast and created a 110MB log file (while eating up 2.3GB of RAM :catstare: ). The largest folder had about 315k files in it; so bullet = dodged.

Thanks for that link!!

Adbot
ADBOT LOVES YOU

Phone
Jul 30, 2005

親子丼をほしい。
LastWriteTime and LastModifiedTime work a lot better.

e: i think lastwritetime = modified time

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply