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
Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
We just upgraded our Exchange testing environment from 2008 to 2008 R2, and none of the NLB/MSCS cmdlets seem to be installed. Any ideas?

Adbot
ADBOT LOVES YOU

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

FISHMANPET posted:

Nevermind what a loving task it was to get powershell to even search. And nevermind how impossible Microsoft has made it to actually get the AD cmdlets. Why in the hell would I have to run a special instance of Powershell (Active Directory Module for Windows PowerShell) to actually be able to query AD. Shouldn't running Powershell on the DC be enough?
Import-Module ActiveDirectory

FISHMANPET posted:

So I say to myself, this sounds perfect for Powershell! Except Powershell can't read the profile paths out of most of my accounts, they just show up as null. dsget works just fine, and looking at them in AD Users & Computers I see the bad profile path, but get-aduser shows nothing.
Get-ADUser -Filter * -Properties profilePath | Where-Object { $_.ProfilePath -match '\\server2' }

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Wicaeed posted:

: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:
$currentday = get-date
$weekdays = "Monday","Tuesday","Wednesday","Thursday","Friday"
$months = 1..12
$firstofmonth = foreach ($month in $months) {1..7| %{get-date -month $month -day $_} | ?{$weekdays -contains $_.dayofweek}|select -first 1}

Function Firstday {
    If ($firstofmonth -contains $currentday)
        {write-host "First weekday of the month"}
    Else
        {Write-Host "Not the first weekday of the month"}
    }

Firstday
FINALLY I was able to do it. I love/hate Powershell
You don't really need to do any date manipulation besides getting the day of the week and the day of the month. If you stop to consider what you're actually trying to find out, there are only two conditions that satisfy the test for "this is the first weekday of the month":

  • It's the 1st of the month and it's a weekday
  • It's the 2nd or 3rd of the month and it's Monday

So you can cut it down to this:

code:
$date = Get-Date
$day = $date.Day
$dow = $date.DayOfWeek
if (($day -eq 1 -and $dow -ne "Saturday" -and $dow -ne "Sunday") -or (($day -eq 2 -or $day -eq 3) -and $dow -eq "Monday")) {
    Write-Host "First weekday of month"
} else {
    Write-Host "Not first weekday of month"
}

Vulture Culture fucked around with this message at 00:15 on Sep 6, 2012

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Swink posted:

How easy is it to create a web frontend for powershell scripts? For instance a user creation script with a dropdown box to select department.
Work on the basics before getting too far ahead of yourself or you're gonna have a bad time. (Also, whoever has to maintain this poo poo once you leave is gonna hate you beyond belief.)

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Dr. Arbitrary posted:

I'm incredibly new at IT but I want to be a badass one day and in all the IT threads people say Powershell is the way to go. I've got a VMware and a powershell book on order but until then I'd love a little feedback.

I wrote my first thingy that actually might do something useful and I have a few questions:
code:

$TIME = get-date; $TIME2 = (get-date).addhours(-24);
get-eventlog -computername 127.0.0.1 -log security -after $TIME2 -Before $TIME -message "*JohnDoe80*"

Basically it's supposed to check the specified server, in this case it's doing a loopback but I'd like to aim it at the active directory server.
It goes through the security logs and returns every message containing a specific username and gives me a big list. If I wanted to get details I could stick on a "| format-list"

My concern is that from the way I'm reading the help files, what it's really doing is grabbing the entire security log and then applying some filters. That's great on a normal computer but on a big server there could be a zillion entries and I'm really worried about crashing something important while running some idiot script. I don't want to get fired in my first month.
It's always a good idea to run things past your superiors when you're the new guy. That said, performance is typically more of a concern than availability with these things - services were designed to actually be used - and what you're doing is great. :)

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

RICHUNCLEPENNYBAGS posted:

I love PowerShell. It took me a while to wrap my head around it (as opposed to a more traditional scripting language), but now that I have I think it's about my favorite scripting language. It's also really nice to have an interactive .NET environment when you're writing C# or something and want to test something out.

That said, a lot of PowerShell stuff talks about how great it is because you can start out with a simple script and expand it into a full-blown thing without having to switch languages. Where are all these big PowerShell projects? I'm curious to see something that goes beyond a single script into being a real, full-scale PowerShell project, if they're out there.

http://chocolatey.org/

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
Has anyone tried out the idempotent Desired State Configuration stuff in PS 4.0 yet? If the given types do enough things, it seems like a really plausible alternative to Puppet/Chef/SCCM for Windows systems management.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

TheEffect posted:

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
Guesswork is sloppy debugging. Instead of double-clicking the script, start a persistent powershell.exe or cmd.exe window, then run the script from there so you can see the error it's kicking back.

That said, it's probably the execution policy.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Briantist posted:

It's unlikely you'll be able to directly use the \\?\ prefix within PowerShell since PowerShell relies on the .Net objects behind the scenes.

There's a janky workaround that might work but you would have to run the script on the file server itself (you can't use UNC paths for this).

Basically, you could create directory junctions that are short, but lead into the deep paths. It would be a bit of a pain in the rear end, since you would constantly have to be using the junction path to traverse the share, and create new junction paths deeper inside as needed.

To create the junctions, you can use mklink, which does support the \\?\ prefix:

code:
mklink /J "C:\mnt\Test" "\\?\Z:\v\e\r\y\long\path\name\here\to\folder"
To call that from powershell:
code:
cmd.exe /c mklink /J "C:\mnt\Test" "\\?\Z:\v\e\r\y\long\path\name\here\to\folder"
Since the junctioning happens at the filesystem level, the Win32 APIs (the source of the problem) should not be able to tell that the shortened path is not the real path (their normalization techniques won't resolve this type of link).

It's really just the logistics of creating and deleting the junctions as needed that will be really annoying.

To delete, use rmdir (or rd):
code:
cmd.exe /c rd "C:\mnt\Test"
One other option I absolutely have not tested, but should at least work locally, would be to handle your own recursion and change into each enumerated child directory using Push-Location and Pop-Location instead of bookkeeping junctions. Since you're dealing with relative paths instead of absolute paths at that point, you're very unlikely to hit PATH_MAX issues.

Vulture Culture fucked around with this message at 00:06 on Feb 26, 2015

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
If you need better performance than background jobs can give you for tasks that are embarrassingly parallel, you can also consider runspaces, or workflows if you need more control over the way results are aggregated and returned. Workflows might be really helpful here just for the built-in checkpointing capabilities.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
Treat parallelism in PowerShell the same way that you would in most other scripting languages: it will help you with asynchronous I/O-bound operations, but it will almost never improve the performance of a calculation.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

orange sky posted:

This is a reaaaaally niche request, so I'm not really hoping to strike gold, but you never know.

So, we're performing a Domino to Exchange migration and the migration product doesn't migrate permissions on anything (bit of a nightmare, really). As such, we're better off building a script that gets all the permissions on Domino and then another script that puts those permissions onto exchange automatically. Most of the stuff we'll probably be able to do, but I'm no expert at working with Domino and Powershell.

Do any of you guys have script that might get a list of the permissions/delegations on Domino?
Oddly, the first thing I found Googling "powershell domino" to see how remotely possible this even is covers ACLs specifically:

http://baldwin-ps.blogspot.com/2013/08/lotus-notes-and-powershell-retrieve-acl.html

You'll need to use their COM objects for basically all the automation.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Ithaqua posted:

Use VSO + Git. That way, you have a local repo and you can make sure if your PC explodes you're still covered by source control.
Bitbucket is another free option with unlimited private repositories.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Walked posted:

Followup on the git question:

Spent part of today reading up, and fairly comfortable with the basic concepts.

However; my use case is that:

I have my local repo; makes sense
Which I'll push to VSO for changes I'm happy with.

How would I go about also getting the VSO repo synced up with a DFS namespace/fileshare at work? Basically I'd like to have a share at work that is only (and autmatically) updated with changes that are pushed to the server.

Any suggestions there? I'd like as much automation as possible so the repo and share are as in-sync as possible without human intervention.
Create a repository on a shared drive. Create a scheduled task to automatically git pull your wanted branch(es) from VSO. Ensure it's read-only (i.e. only the user running that pull script can write to it).

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Danith posted:

In one of my 'make my day easier' scripts it looks like I may need to figure out how to SFTP something from powershell (Well.. i guess I could use a command-line SFTP client but everything from powershell would be better). Has anyone done this/know of sites I can look at?

Is there a .net class I can use? I'm guessing not :(

Fenrisulfr posted:

I've not used it myself but you might be able to use WinSCP to do it: https://winscp.net/eng/docs/guide_dotnet. It's not exactly from Powershell but it's the closest I was able to find. I was going to dive into it to automate an SFTP task but since the only manual steps are opening WinSCP, dragging the file over, and closing WinSCP I haven't bothered.
http://dotps1.github.io/WinSCP/

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There's an awful lot of DSC resources for managing NTFS ACLs lying around. Anyone have a favorite?

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Swink posted:

I'm interested in what you're using DSC for? I am just picking it up again after a year and the community isn't anything compared to Chef, which is a bit disappointing.
Nothing fancy, just automating the creation of some desktop VMs for our developers to make it easier to onboard people.

The community is definitely tiny next to Chef, and all of the documentation is terrible. But it's good enough, I guess?

Adbot
ADBOT LOVES YOU

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Dr. Arbitrary posted:

No, this is a one time thing, so say we've got 100 servers that need significant configuration changes, and they all go through similar steps, some of which may fail, need to be remediated, and then move on.

I've been thinking of making some custom objects that have name, sequence number, succeed/fail, scriptblock.

Then for each of the servers I can have it start task 1 as a job, periodically check to see if it finished, proceed to 2 on the ones that are done, and so on.

If Server 45 fails on step 9, I want to be able to tell someone to manually fix the problem, and then continue to step 10.
Are you able to make these changes idempotent? Might be easier to just use something like DSC resources and not worry about the workflow angle at all -- it will just pick up whatever needs to be changed.

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