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
Irritated Goat
Mar 12, 2005

This post is pathetic.
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.

Adbot
ADBOT LOVES YOU

ElGroucho
Nov 1, 2005

We already - What about sticking our middle fingers up... That was insane
Fun Shoe
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.

The Electronaut
May 10, 2009

ElGroucho posted:

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.

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.

Spazz
Nov 17, 2005

Anybody have experience with the AWS PowerShell cmdlets? Anything I should know before I start using it?

PurdWerfect
Aug 29, 2000


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:
dir "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" | gp "SNMP Enabled" | ?{$_."SNMP Enabled" -eq 1} | %{sp -Path $_.PSPath -Name "SNMP Enabled" -Value 0}
If I shorten it to
code:
dir "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" | %{sp -Path $_.PSPath -Name "SNMP Enabled" -Value 0}
it works, but I'd like to know how to change it only if it needs changing rather than brute force every entry to 0.

CLAM DOWN
Feb 13, 2007




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:
if((Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" -Name "SNMP Enabled") -eq 1)
{
    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" -Name "SNMP Enabled" -Value 0
}

PurdWerfect
Aug 29, 2000


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.

nzspambot
Mar 26, 2010

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

Spazz
Nov 17, 2005

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.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
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
After launching the command to start the VM I'd have the script check the VM's status every 10 seconds and update the Status column accordingly, all without doing another Write-Host to add an additional line to the console. Basically, I'm wondering if Powershell can be used to make text-based interactive UIs, or if I'm better off turning this into a .NET project.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

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.

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
After launching the command to start the VM I'd have the script check the VM's status every 10 seconds and update the Status column accordingly, all without doing another Write-Host to add an additional line to the console. Basically, I'm wondering if Powershell can be used to make text-based interactive UIs, or if I'm better off turning this into a .NET project.

Write-Progress

Dr. Arbitrary
Mar 15, 2006

Bleak Gremlin
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:
$sessions = query session | ?{ $_ -notmatch '^ SESSIONNAME' } | %{
    $item = "" | Select "Active", "SessionName", "Username", "Id", "State", "Type", "Device"
    $item.Active = $_.Substring(0,1) -match '>'
    $item.SessionName = $_.Substring(1,18).Trim()
    $item.Username = $_.Substring(19,20).Trim()
    $item.Id = $_.Substring(39,9).Trim()
    $item.State = $_.Substring(48,8).Trim()
    $item.Type = $_.Substring(56,12).Trim()
    $item.Device = $_.Substring(68).Trim()
    $item
}
code:
$disconnecteds=($sessions | Where-Object { $_.State -eq 'Disc' });
foreach ($Id.Id in $disconnecteds) {logoff $Id.Id};
I'm happy with the first line, it successfully selects only the disconnected users. I tried a lot of methods of piping that input into the command "LOGOFF" but it only worked when I did $Id.Id. I don't know why that works. I would have expected it to be $sessions.Id or $disconnecteds.Id

Is there a better way to do this that makes a little more sense?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
$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.

Dr. Arbitrary
Mar 15, 2006

Bleak Gremlin

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:
$disconnecteds=($sessions | Where-Object { $_.State -eq 'Disc' });
foreach ($disconnected in $disconnecteds) {logoff $disconnected.Id};
or maybe
code:
foreach ($disconnected.id in $disconnecteds) {logoff $disconnected.Id};
It's my loving day off and I'm crazy excited to go back to work and try this out. I'd want to go immediately home afterwards of course but drat.
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?

Spazz
Nov 17, 2005

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:
$target = "localhost"
$sessions = (query session /server:$target |
             ForEach { (($_.trim() -replace “\s+”,”,”))} | 
             ConvertFrom-Csv) | 
             Where-Object {$_.State -eq "Disc"}
Then you can just run this...

code:
ForEach($user in $sessions)
{
    logoff $user.Id /server:$target
}
When you go "ForEach($item in $list)", you are creating a new variable for each item in the list and it will run the commands in the code blocks for each item in the list.

Anyway, to answer your question, this would work with the current code:
code:
ForEach($disconnected in $disconnecteds) {logoff $disconnected.Id}
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.

Dr. Arbitrary
Mar 15, 2006

Bleak Gremlin

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:
$target = "localhost"
$sessions = (query session /server:$target |
             ForEach { (($_.trim() -replace “\s+”,”,”))} | 
             ConvertFrom-Csv) | 
             Where-Object {$_.State -eq "Disc"}
Is a clever block of code. I'm going to test this out tomorrow and if it all works I might be putting it into practice.

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?

Spazz
Nov 17, 2005

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.

...

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?

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 -?).

Swink
Apr 18, 2006
Left Side <--- Many Whelps
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:
Start-Process Winword
start-sleep -x 
Stop-Process -Name Winword

Briantist
Dec 5, 2003

The Professor does not approve of your post.
Lipstick Apathy

Swink posted:

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:
Start-Process Winword
start-sleep -x 
Stop-Process -Name Winword
You can use automation:

code:
$word = New-Object -Com Word.Application
$word.Visible = $false    # This is the default; change it to $true if you want to see the window.
$word.Quit()
In my test with Measure-Command, the time taken for this is 100 - 200ms but I don't have it loading templates, so I can't tell if it's waiting or not.

LiterallyAnything
Jul 11, 2008

by vyelkin
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?

CLAM DOWN
Feb 13, 2007




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?

LiterallyAnything
Jul 11, 2008

by vyelkin

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\*"

Simple Usage :: ROBOCOPY source destination /MIR

source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.

AreWeDrunkYet
Jul 8, 2006

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.

Erwin
Feb 17, 2006

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

12 rats tied together
Sep 7, 2006

Brady posted:

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?

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.

LiterallyAnything
Jul 11, 2008

by vyelkin

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:
+++++
KOPS3106-57-DT
+++++

14.10.31: Moving on to station KOPS3106-57-DT
14.10.34: KOPS3106-57-DT is online.
14.10.34: Attempting to push...

InvalidArgument: (\\KOPS3106-57-DT\C$:String) [Copy-Item], ArgumentException
WriteError: (ocDLL.dll:FileInfo) [Copy-Item], IOException
WriteError: (Summit WOC.exe:FileInfo) [Copy-Item], IOException
WriteError: (wocStarter.vbs:FileInfo) [Copy-Item], IOException
InvalidArgument: (\\KOPS3106-57-DT\C$:String) [Copy-Item], ArgumentException
WriteError: (alarms.dat:FileInfo) [Copy-Item], IOException
WriteError: (BridgeHistory.ini:FileInfo) [Copy-Item], IOException
WriteError: (license:FileInfo) [Copy-Item], IOException
WriteError: (sox.exe:FileInfo) [Copy-Item], IOException
WriteError: (woc.ini:FileInfo) [Copy-Item], IOException
WriteError: (WOCColumnSettings.ini:FileInfo) [Copy-Item], IOException
InvalidArgument: (\\KOPS3106-57-DT\C$:String) [Copy-Item], ArgumentException
WriteError: (ACTIVATE.WAV:FileInfo) [Copy-Item], IOException
WriteError: (ALARM.WAV:FileInfo) [Copy-Item], IOException
WriteError: (FREEPORTS.WAV:FileInfo) [Copy-Item], IOException
WriteError: (IDLE.WAV:FileInfo) [Copy-Item], IOException
WriteError: (RESERVE.WAV:FileInfo) [Copy-Item], IOException
WriteError: (RINGIN.WAV:FileInfo) [Copy-Item], IOException
WriteError: (SIGNAL.WAV:FileInfo) [Copy-Item], IOException
NotSpecified: (:) [Copy-Item], IOException

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.

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.

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

LiterallyAnything
Jul 11, 2008

by vyelkin
Quote != Edit

Swink
Apr 18, 2006
Left Side <--- Many Whelps

Briantist posted:

You can use automation:

code:
$word = New-Object -Com Word.Application
$word.Visible = $false    # This is the default; change it to $true if you want to see the window.
$word.Quit()
In my test with Measure-Command, the time taken for this is 100 - 200ms but I don't have it loading templates, so I can't tell if it's waiting or not.




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:
 $Word = New-Object -ComObject Word.application
 $word.visible = $false
 $Doc = $Word.Documents.Open("C:\template\CLOSE WORD.docm")

Spazz
Nov 17, 2005

This is how I did it a few weeks ago, but in my case the macro was in the Normal.dot template file...

code:
$word = New-Object -ComObject Word.Application
$word.visible = $FALSE
$word.Run("Macro Name")
$word.Quit()
If you have the $word process open your document containing the macros, you could probably put it right before the $word.Run("Macro Name") command.

Swink
Apr 18, 2006
Left Side <--- Many Whelps
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:
$UserDetails = @{}

$UserDetails.add("firstName",  $reader.AcroFields.GetField("FIRST"))
$UserDetails.add("middleName",   $reader.AcroFields.GetField("MIDDLE"))
$UserDetails.add("lastName",  $reader.AcroFields.GetField("SURNAME"))
$UserDetails.add("Position",  $reader.AcroFields.GetField("PositionTitle"))

set-aduser @userDetails

Edit. I think I answered my own question by reading the error message: "The splatting operator '@' cannot be used to reference variables in an expression. '@UserDetails' can be used only as an argument to a command."

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

Briantist
Dec 5, 2003

The Professor does not approve of your post.
Lipstick Apathy

Swink posted:

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:
$UserDetails = @{}

$UserDetails.add("firstName",  $reader.AcroFields.GetField("FIRST"))
$UserDetails.add("middleName",   $reader.AcroFields.GetField("MIDDLE"))
$UserDetails.add("lastName",  $reader.AcroFields.GetField("SURNAME"))
$UserDetails.add("Position",  $reader.AcroFields.GetField("PositionTitle"))

set-aduser @userDetails

Edit. I think I answered my own question by reading the error message: "The splatting operator '@' cannot be used to reference variables in an expression. '@UserDetails' can be used only as an argument to a command."

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.

The keys in the hashtable need to match the parameter names of the cmdlet/function:

code:
$UserDetails = @{}

# You can set with array style notation too
$UserDetails["GivenName"] = $reader.AcroFields.GetField("FIRST"))
$UserDetails["Initials"] = $reader.AcroFields.GetField("MIDDLE"))
$UserDetails["Surname"] = $reader.AcroFields.GetField("SURNAME"))
$UserDetails["Title"] = $reader.AcroFields.GetField("PositionTitle"))
# You can also set using dot notation
$UserDetails.DomainController = "SomeDC"

Set-ADUser @UserDetails -WhatIf
You can still provide named parameters alone with splatting if you like, as I did in the example above with -WhatIf.

LiterallyAnything
Jul 11, 2008

by vyelkin
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?

AreWeDrunkYet
Jul 8, 2006

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.

Pilsner
Nov 23, 2002

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?

Zaepho
Oct 31, 2013

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.

LiterallyAnything
Jul 11, 2008

by vyelkin

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?

AreWeDrunkYet
Jul 8, 2006

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

LiterallyAnything
Jul 11, 2008

by vyelkin

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.

PS DHCP - http://technet.microsoft.com/en-us/library/jj590751.aspx
netsh DHCP - http://technet.microsoft.com/en-us/library/cc787375(v=ws.10).aspx#BKMK_dump

Thanks for the info!

cactuscarpet
Sep 12, 2011

I don't even know what rasta means.
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

Adbot
ADBOT LOVES YOU

TheEffect
Aug 12, 2013
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

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