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
Z-Bo
Jul 2, 2005
more like z-butt
This might help. Most Microsoft products have a customized version of PowerShell. Exchange's is called Exchange Management Shell

You can also use:

get-command *queue*
get-command *message*
in PowerShell to search for Exchange Message Queue-related or Message-related CMDlets.

Then, having realized I hit jackpot, I would take get-queue and type it into Google Books.

http://www.google.com/search?tbs=bks%3A1&tbo=1&q=get-queue&btnG=Search+Books

The first link, Mastering Microsoft Exchange Server 2007 - Page 733, probably gets you as far as I can get you.

Note: I am not an Exchange Admin, and figured this all out in 10 mins. What I am teaching you is how to get information on how to do tasks in PowerShell.

Adbot
ADBOT LOVES YOU

Z-Bo
Jul 2, 2005
more like z-butt
I need some goon help.

Mobsync.exe is pegging my CPU at 100% every 5 seconds. I have done just about everything I could find on the Internet to disable this:

1) I've disabled offline files
2) I've tried deleting the USB Device Stack and rebooting so that Vista automatically rebuilds it to fix any device ordering issues
3) I've stopped the Portable Device Enumerator Service and set it to Disabled.
4) I've changed the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WINEVT\Publishers\{b44aec44-38f4-4b59-8 df3-10306abf19b2} property 'Enabled' to 0.
5) I've read that you can disable Execute/Traverse permissions for Everyone on C:\Windows\System\mobsync.exe but am not sure how to do it using PowerShell, and do not want to try a non-PowerShell solution (if I am going to fix this problem, then I refuse to rely on strange Windows programs I have never heard of like xcacl.exe -- it is just one more piece of crap I don't need installed on my computer, and I don't want to install that guys tool either).

How do I use set-acl to get rid of mobsync.exe's TrustedInstaller ownership and revoke traverse/execute from Everyone?

The Diddler
Jun 22, 2006


What's going on with my script? I have a directory with about 200 files. There's 8 different extensions, making it: file.ex1, file.ex2, file.ex3, file2.ex1, file2.ex2, file2.ex3... I only care about 4 of the extensions, and I need all 4 of them. My thought is to count the number of files with the extensions I care about and put the numbers in an excel document. That part works:
code:
$fim00 = Get-ChildItem "c:\folder\*.fim"
$sheet00.Cells.Item(2,2) = $fim00.Count
$rim00 = Get-ChildItem "c:\folder\*.rim"
$sheet00.Cells.Item(2,3) = $rim00.Count
$idx00 = Get-ChildItem "c:\folder\*.idx"
$sheet00.Cells.Item(2,4) = $idx00.Count
$dir00 = Get-ChildItem "c:\folder\*.dir"
$sheet00.Cells.Item(2,5) = $dir00.Count

$WorkBook00 = $sheet00.UsedRange
$WorkBook00.Interior.ColorIndex = 8
$WorkBook00.Font.ColorIndex = 11
$WorkBook00.Font.Bold = $True
If I'm missing a file, I need to create it. I can do that by hand, since I just need to copy an existing file and rename it. To make that part easier, if my numbers don't match, I want a list of each one. That part also works, except my if statement doesn't work. I tried all 3 I have here, and they always return the result I have commented at the end of the line.

code:
if ($fim00 = $rim00 = $idx00 = $dir00) {"00 correct"} else { #always true

if (($Sheet00.Cells.Item(2,2))-eq($Sheet00.Cells.Item(2,3))-eq($Sheet00.Cells.Item(2,4))-eq($Sheet00.Cells.Item(2,5))) {"00 correct"} else { #always false

if (($fim00.Count) = ($rim00.Count) = ($idx00.Count) = ($dir00.Count)) {"00 correct"} else { #errors out
What's going on here? I spent most of today banging away at this, and everything else pretty much works right, just not this. I could have it list everything every time, but it's over the network and kind slow since it happens ~20 times by the time it's finished.

On a slightly related note, how do I create an excel document with 5 worksheets? This thing is done to 5 different directories, and my script starts making GBS threads all over when I need sheet 4.

dalin
Nov 6, 2005

The equality operator is "-eq", not "=". Also I don't think you can string them together like that (x -eq y -eq z). Try this:

code:
$counts = @($fim00.Count,$rim00.Count,$idx00.Count,$dir00.Count)
$allEqual = ($counts | ? { $_ -ne $fim00.Count } | Measure-Object).Count -eq 0
if ($allEqual) { ... }
Can't help you with the Excel bit.

The Diddler
Jun 22, 2006


dalin posted:

The equality operator is "-eq", not "=". Also I don't think you can string them together like that (x -eq y -eq z). Try this:

code:
$counts = @($fim00.Count,$rim00.Count,$idx00.Count,$dir00.Count)
$allEqual = ($counts | ? { $_ -ne $fim00.Count } | Measure-Object).Count -eq 0
if ($allEqual) { ... }
Can't help you with the Excel bit.

Hey, that worked, thanks! If anyone else is curious about adding worksheets to excel, I found this today:
code:
 
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

$ws = $Excel.Worksheets.Item(1) 
for ($i = 0; $i -le 1; $i++) {
$ws = $Excel.Sheets.Add() }
With this snippet you can add as many pages as you need. Since the loop is "less than or equal to" it adds 2 in this instance, giving you 5 sheets. I'm guessing it wouldn't be too much work to create a workbook with 4 sheets. Since the sheets seem to be added sorta haphazardly, you probably want to rename them using $Excel.Worksheets.item(2).name = "whatever", where (2) is the sheet number you want to rename.

Another question: any resources on how to format the output of select-string? I have a 2-liner that produces pretty decent output if I paste it into my session, but if I run the .ps1, the output changes.

adaz
Mar 7, 2009

Z-Bo posted:

How do I use set-acl to get rid of mobsync.exe's TrustedInstaller ownership and revoke traverse/execute from Everyone?

Easy solution found it while searching on how to take owernship of a file in powershell. Create something called test.txt and set whatever permissions you want on it (that will be mirror'd on mobsync.exe) then do this:

code:
$objUser = New-Object System.Security.Principal.NTAccount("fabrikam", "kenmyer")
$objFile = Get-Acl C:\Scripts\Test.txt
$objFile.SetOwner($objUser)
Set-Acl -aclobject $objFile -path C:\Scripts\Test.txt
Here is the scripting guys article on it:

http://blogs.technet.com/b/heyscriptingguy/archive/2008/04/15/how-can-i-use-windows-powershell-to-determine-the-owner-of-a-file.aspx

Bob Cthulhu posted:


Another question: any resources on how to format the output of select-string? I have a 2-liner that produces pretty decent output if I paste it into my session, but if I run the .ps1, the output changes.

Can you give us the example? I mean, select-string outputs whatever it finds as a string, not sure what you want to do with it.

adaz fucked around with this message at 18:37 on Jun 21, 2010

reverend cowboy
Jan 11, 2006
The best defense against the atom bomb is not to be there when it goes off.

Walked posted:

Anyone know how to query an Exchange 2007 server and check the number of messages in specific queues?

Working on automating my staff's on-call checks for them; finding iffy documentation on Exchange queries. (To be fair; half the internet is blocked at this office too)

Is this what you want to do?
This will list the details of the submission queue on the specified server
code:
get-queue -server <servername> |? {$_.identity -like "*submission"}
If you append | select messagecount will show you just the count and not the other details.

The Diddler
Jun 22, 2006


adaz posted:

Can you give us the example? I mean, select-string outputs whatever it finds as a string, not sure what you want to do with it.

I'll have to look when I get to work. I just tried it at home and it worked like I wanted it to.

adaz
Mar 7, 2009

Bob Cthulhu posted:

I'll have to look when I get to work. I just tried it at home and it worked like I wanted it to.

Powershell v1 versus v2 maybe? Also keep in mind that if powershell is returning some really stupid formatting or type for whatever reason the [string] type accelerator can be golden. Works fantastic for a lot of things, especially ADSI type searches that output fine until you try to work with them.

Still, select-string should always return a string as far as I'm aware.

The Diddler
Jun 22, 2006


adaz posted:

Powershell v1 versus v2 maybe? Also keep in mind that if powershell is returning some really stupid formatting or type for whatever reason the [string] type accelerator can be golden. Works fantastic for a lot of things, especially ADSI type searches that output fine until you try to work with them.

Still, select-string should always return a string as far as I'm aware.

I'm running Win7 on both machines. That comes with v2 out of the box, right?

The differences were something like:
code:
c:\file.txt:2:nacho
c:\file2.txt:2:nacho
c:\file3.txt:2:nacho
c:\file4.txt:2:nacho
and
code:
***********
c:\file.txt
2
true
match
nacho
***********
c:\file2.txt
2
true
match
nacho
***********
The first one is what I want, and the second one is the one that just shows up.

Spudman
Feb 5, 2004

Post nudes plz
Don't worry, it's perfectly rational!
Just posting here to share my Powershell success story, and to post something I wrote that might help other people. It's a script that scans an entire range of IP addresses, and if it is able to ping the IP, it attempts a couple of WMI queries to get the name and model of the machine. It also includes the option to scan the machine further and retrieve errors that it has in its logs from the last 24 hours. Then it writes all that stuff to (a) file(s). You need to provide sufficient domain credentials, so obviously you have to run it again for the other domain if you have more than one domain in the same IP range, like I do. I suppress the WMI access denied errors because I get a lot of them because I have an untrusted domain coexisting in the same IP range as my main domain. Warning: It sets the global error action preference to silent so you need to set it back to normal after you're done or write it into the script or else you won't see errors in Powershell until you turn it back to normal. Please tell me if you see anything that I could have done more efficiently, or better, or have an idea or suggestion that would make it even more awesome. Thanks.

code:
$erroractionpreference = "SilentlyContinue"
$domainuser = Read-Host "Enter authorized domain\username for scan"
$pass = Read-Host "Enter password" -AsSecureString
$creds = New-Object -Typename System.Management.Automation.PSCredential -argumentlist $domainuser,$pass
$network = Read-Host "Enter the first 3 octets of the IP range with periods, e.g. xxx.xxx.xx."
$filename = Read-Host "Enter the filename to output results to"
$errorReports = Read-Host "Do you also want to get error events from the last 24 hours?(y/n)" 
Write-Host " "
Write-Host "Basic results will be written to $filename" -ForegroundColor "Green"
if(($errorReports -eq 'Y') -or ($errorReports -eq 'y'))
{
 Write-Host "Error reports will be written to hostname.Errors.txt. (This takes longer.)" -ForegroundColor "Green"
 $systemsWithErrors = 0
}
Write-Host "Scanning $network 1 to $network 255..." -ForegroundColor "Green"
Write-Host " "
function ping-ip 
{
 param( $ip )
 trap
 {
  $false; continue
 }
 $object = New-Object system.Net.NetworkInformation.Ping
 (($object.Send($ip, 1000)).Status -eq 'Success') # 1000ms is the ping timeout
}

Get-Date | Out-File -FilePath $filename -Encoding "ASCII" | Wait-Job
echo "Domain\User: $domainuser" | Out-File -FilePath $filename -Encoding "ASCII" -Append | Wait-Job

1..255 | % { $ip = "$network$_"; "$ip = $(ping-ip $ip)" 
 if($(ping-ip $ip) -eq "True")
 {
  $name = Get-WmiObject -query "SELECT Name FROM Win32_ComputerSystem" -Computer $ip -Credential $creds -ErrorAction SilentlyContinue | ForEach-Object{$_.Name}
  $model = Get-WmiObject -query "SELECT Model FROM Win32_ComputerSystem" -Computer $ip -Credential $creds -ErrorAction SilentlyContinue | ForEach-Object{$_.Model}
  Wait-Job -State "Running"
  if($name -and $model)
  {
   echo "$ip $name $model" | Out-File -FilePath $filename -Encoding "ASCII" -Append | Wait-Job
   if(($errorReports -eq 'Y') -or ($errorReports -eq 'y'))
   {
    $time = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime((Get-Date).AddHours(-24))
    $errorWmi = Get-WmiObject win32_NTLogEvent -computerName $ip -Credential $creds -Filter "EventType=1 AND TimeGenerated>='$time'"
    if($errorWmi)
    {
     echo "Error events from $name within the last 24 hours:" | Out-File -FilePath "$name.Errors.txt" | Wait-Job
     Out-File -FilePath "$name.Errors.txt" -InputObject $errorWmi -Append | Wait-Job
     $systemsWithErrors = $systemsWithErrors + 1
    }
   }
  }
 }
}
Write-Host " "
Write-Host "All Done." -ForegroundColor "Green"
if(($errorReports -eq 'Y') -or ($errorReports -eq 'y'))
{
 Write-Host "Number of systems with errors: $systemsWithErrors" -ForegroundColor "Green"
}

Spudman fucked around with this message at 22:24 on Jun 22, 2010

adaz
Mar 7, 2009

Bob Cthulhu posted:

I'm running Win7 on both machines. That comes with v2 out of the box, right?

The differences were something like:


The first one is what I want, and the second one is the one that just shows up.

What is the full code though that's generating all this? I'm not sure.. what are you piping to select string (or inputting)?

Spudman posted:

Just posting here to share my Powershell success story, and to post something I wrote that might help other people. It's a script that scans an entire range of IP addresses, and if it is able to ping the IP, it attempts a couple of WMI queries to get the name and model of the machine. It also includes the option to scan the machine further and retrieve errors that it has in its logs from the last 24 hours. Then it writes all that stuff to (a) file(s). You need to provide sufficient domain credentials, so obviously you have to run it again for the other domain if you have more than one domain in the same IP range, like I do. I suppress the WMI access denied errors because I get a lot of them because I have an untrusted domain coexisting in the same IP range as my main domain. Warning: It sets the global error action preference to silent so you need to set it back to normal after you're done or write it into the script or else you won't see errors in Powershell until you turn it back to normal. Please tell me if you see anything that I could have done more efficiently, or better, or have an idea or suggestion that would make it even more awesome. Thanks.



That's a cool script and I like the use of Jobs which I've hardly touched but really should, especially when dealing with the usually incredibly slow WMI. I would suggest checking out the Get-EventLog cmdlets instead of using WMI to retrieve the event log, they're usually much faster and have good granular control over what it's outputting/how it's outputting.

adaz fucked around with this message at 22:59 on Jun 22, 2010

Spudman
Feb 5, 2004

Post nudes plz
Don't worry, it's perfectly rational!
The thing that got me to start using Wait-Job on stuff, especially file-writes, is that I think the multithreaded nature of Powershell was causing my scripts to try to write the same file simultaneously when I had the Output-File running in an endless loop, resulting in a blank file. Piping it to Wait-Job cured that for me.

Spudman fucked around with this message at 23:45 on Jun 22, 2010

The Diddler
Jun 22, 2006


adaz posted:

What is the full code though that's generating all this? I'm not sure.. what are you piping to select string (or inputting)?

This is the script:
code:
Get-ChildItem C:\users\user\desktop\pim
grep -pattern "EXCEPTIONS" -path "C:\users\user\desktop\pim\*.*"
Grep is defined in my profile as an alias for select-string. I tried it using select-string instead of grep, and it did the same thing. When I paste it into powershell, it does this:
code:
   Directory: C:\users\user\desktop\pim


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         6/16/2010   5:45 PM        645 I00F1.DOC
-a---         6/16/2010   5:45 PM        645 I00F2.DOC
-a---         6/16/2010   5:45 PM        645 I00F3.DOC

C:\users\user\desktop\pim\I00F1.DOC:7:*** NO EXCEPTIONS TO REPORT ***
C:\users\user\desktop\pim\I00F2.DOC:7:*** NO EXCEPTIONS TO REPORT ***
C:\users\user\desktop\pim\I00F3.DOC:7:*** NO EXCEPTIONS TO REPORT ***
When it's run as a ps1, it does this:
code:
   Directory: C:\users\user\desktop\pim


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         6/16/2010   5:45 PM        645 I00F1.DOC
-a---         6/16/2010   5:45 PM        645 I00F2.DOC
-a---         6/16/2010   5:45 PM        645 I00F3.DOC
-a---         6/16/2010   5:45 PM        645 I00F4.DOC
-a---         6/16/2010   5:45 PM        645 I00F5.DOC
-a---         6/16/2010   5:45 PM        645 I00F6.DOC
-a---         6/16/2010   5:45 PM        645 I00F7.DOC
-a---         6/16/2010   5:45 PM        645 I00F8.DOC
-a---         6/16/2010   5:45 PM        645 I00F9.DOC
-a---         6/16/2010   5:45 PM        645 I04F10.DOC
-a---         6/18/2010   7:12 PM        637 I06F11.DOC

IgnoreCase : True
LineNumber : 7
Line       : *** NO EXCEPTIONS TO REPORT ***
Filename   : I00F1.DOC
Path      : C:\users\user\desktop\pim\I00F1.DOC
Pattern    : EXCEPTIONS
Context    :
Matches    : {EXCEPTIONS}


IgnoreCase : True
LineNumber : 7
Line       : *** NO EXCEPTIONS TO REPORT ***
Filename   : I00F2.DOC
Path      : C:\users\user\desktop\pim\I00F2.DOC
Pattern    : EXCEPTIONS
Context    :
Matches    : {EXCEPTIONS}


IgnoreCase : True
LineNumber : 7
Line       : *** NO EXCEPTIONS TO REPORT ***
Filename   : I00F3.DOC
Path      : C:\users\user\desktop\pim\I00F3.DOC
Pattern    : EXCEPTIONS
Context    :
Matches    : {EXCEPTIONS}
This is generally going to be run against a directory of 7 to 30 files, which is going to make it really hard to read. Any ideas?

adaz
Mar 7, 2009

Bob Cthulhu posted:

This is the script:
code:
Get-ChildItem C:\users\user\desktop\pim
grep -pattern "EXCEPTIONS" -path "C:\users\user\desktop\pim\*.*"
Grep is defined in my profile as an alias for select-string. I tried it using select-string instead of grep, and it did the same thing. When I paste it into powershell, it does this:


This is generally going to be run against a directory of 7 to 30 files, which is going to make it really hard to read. Any ideas?

That is really bizarre and I don't know why it is doing that to you. I tried quite a few things to get your original code to work executed as a ps1 but nothing would, sorry. I did, however, find a way around that output problem and it that works just fine.


code:
$dir = Get-Childitem C:\users\user\desktop\pim
$dir  
$dir | select-string "EXCEPTIONS"

The Diddler
Jun 22, 2006


adaz posted:

That is really bizarre and I don't know why it is doing that to you. I tried quite a few things to get your original code to work executed as a ps1 but nothing would, sorry. I did, however, find a way around that output problem and it that works just fine.


code:
$dir = Get-Childitem C:\users\user\desktop\pim
$dir  
$dir | select-string "EXCEPTIONS"

I'll give that a shot tomorrow. Some other things I came up with today were creating a batch file with the powershell commands in it or some crazy thing that I found on Technet that will sort and filter the results. I don't really understand it, so I was having issues making it work.

The Diddler
Jun 22, 2006


Bob Cthulhu posted:

I'll give that a shot tomorrow. Some other things I came up with today were creating a batch file with the powershell commands in it or some crazy thing that I found on Technet that will sort and filter the results. I don't really understand it, so I was having issues making it work.

I got it working today. Did a Get-Childitem with a format-table and the second line was a select-string, I believe a sort to get what I needed, and a format-table. I found something interesting today: if you use a format-table in your script, you have to format-table every line that has output. You can't mix implied and explicit formatting.

adaz
Mar 7, 2009

Bumping this thread in case there are any more questions and the scripting guys have been running a great series on powershell & active directory this week that everyone should check out:

http://www.games-workshop.com/gws/catalog/productDetail.jsp?catId=cat440342a&prodId=prod840005a

(although I still think the [adsisearcher] accelerator is retarded)

Sharkface
Apr 20, 2002

Z-Bo posted:

Been hacking in Powershell lately to automate some bullshit garbage that I can now pass off to somebody who can just click the script and monitor it to make sure nothing failed.

See http://z-bo.tumblr.com/post/657962194/optimizing-vba where I have been dabbling in using Powershell to mess with CSV files, using the Excel COM API. It was rough getting used to the API and what idioms worked best, but now that I have done a bit I like it. A cheat sheet for Powershell and Excel would be a nice addition to the Powershell community.

I'll bump this thread in the future with some neat Powershell idioms Victor and I came up with about a year and a half ago that have proven rock solid and seriously cut down on lines of code.

Thanks for this. I really needed a good way to control excel outside of excel. Powershell is going to save the day.

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?

Z-Bo
Jul 2, 2005
more like z-butt
Can you provide a more detailed problem report?

For example, can you print out the commands you are using to search your PowerShell environment? What is your path variable? Does it include Exchange? What is the ExecutionPolicy for that path? etc.

Walked
Apr 14, 2003

Anyone help? :(

Getting the error:
out-lineoutput : Object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not legal or not in
the correct sequence. This is likely caused by a user-specified "format-list" command which is conflicting with the def
ault formatting.


When running this program. However, only on the second function call. Whichever function (queues or stores) I run first; everything runs PERFECT. Once I run the second, error city.

If I remove the ft on the stores function, all is happy again, but the output is not readable.

Anyone help?

code:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin;

function mainMenu()
{
	Clear Host;
	Write-Host "============";
	Write-Host "= MAINMENU =";
	Write-Host "============";
	Write-Host "1. Press 1 for Exchange Queue Status";
	Write-Host "2. Press 2 for Information Store Status";
}

function queues()
{
	Get-ExchangeServer | where{$_.ServerRole -eq "HubTransport"} | Get-Queue | Sort $_.Messagecount -descending ;
}

function stores()
{
	Get-ExchangeServer | where {$_.IsMailboxServer -eq "$True" }  | Get-MailboxDatabase -status  | ft servername,storagegroup,mounted;

}



do
{
	mainMenu;
	$input = Read-Host "Enter Choice";
	
	switch($input)
	{
		"1"
		{
			queues;
			Write-Host "Press Any Key to Continue";
			$host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown");
			mainMenu;
		}
		
		"2"
		{
			stores;
			Write-Host "Press Any Key to Continue";
			$host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown");
			mainMenu;

		}
		
		default
		{
			Clear Host;
			Write-Host "Invalid option";
			$host.UI.RawUI.ReadKey("NoExcho, IncludeKeyDown");
			mainMenu;
		}
	} 
	
}until ($input -eq "q");


#Get-TransportServer | Foreach-object {Get-Queue -Server $_ | Sort-Object NextHopDomain, MessageCount, Status}


Write-Host "Press any key to exit";

$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown");

adaz
Mar 7, 2009

I don't have an exchange environment handy to test this on, but my experience with powershell formatting and type conversions wackiness leads me to believe something like this would work to fix it (although I'm sure someone with more knowledge would know a better way).

code:
[array]$arrStores = Get-ExchangeServer | where {$_.IsMailboxServer -eq "$True" }  | Get-MailboxDatabase -status

$arrstores |ft servername,storagegroup,mounted;
You force it convert the data to an array instead of relying on the built in type filters, that usually works for silly problems like this

Walked
Apr 14, 2003

adaz posted:

I don't have an exchange environment handy to test this on, but my experience with powershell formatting and type conversions wackiness leads me to believe something like this would work to fix it (although I'm sure someone with more knowledge would know a better way).

code:
[array]$arrStores = Get-ExchangeServer | where {$_.IsMailboxServer -eq "$True" }  | Get-MailboxDatabase -status

$arrstores |ft servername,storagegroup,mounted;
You force it convert the data to an array instead of relying on the built in type filters, that usually works for silly problems like this

Unfortunately same error; got me excited too :(

Victor
Jun 18, 2004
Someone earlier in this thread said you have to Format-Table nothing or everything, but not half-and-half.

adaz
Mar 7, 2009

Walked posted:

Unfortunately same error; got me excited too :(

well, if Victor is correct you can try putting in a

code:
| select-Object servername,storagegroup,mounted | ft
and see if that works

Walked
Apr 14, 2003

No good on that one adaz; but feels close. Got a few things I'm going to try; this is annoying as anything though.

adaz
Mar 7, 2009

Walked posted:

No good on that one adaz; but feels close. Got a few things I'm going to try; this is annoying as anything though.

A random google search says this - what happens if you remove the ; (actually I don't even know why you included it, it's strictly speaking not necessary

quote:

It's because the ; character doesn't terminate the pipeline, but does terminate the expression. The first expression has filled the success pipeline with objects that PowerShell "wants" to format as a table... then you're calling a second expression. The ; character isn't meant to be used in a pipeline like that - it's primarily for use within a script or subexpression where the success pipeline isn't becoming involved. Keep in mind that the pipeline ends in Out-Default, which doesn't deal with unformatted data; it's made an invisible call to a Format cmdlet, which generates formatting objects.

Walked
Apr 14, 2003

adaz posted:

A random google search says this - what happens if you remove the ; (actually I don't even know why you included it, it's strictly speaking not necessary

I'll give that a whirl when I'm back in my exchange environment tomorrow. I'm a C# guy; the semicolon is habitual. :(

Orbis Tertius
Feb 13, 2007

I'm working on an Intranet-only site (running Apache/PHP/MySQL) and I recently implemented some automation stuff involving Word 2003. I did this by having the shell_exec PHP function run a console program I wrote in C#, which handles all the automated .doc parsing stuff I needed to do. This project was a non-starter for awhile; I couldn't seem to get anything to work, but I stumbled across an archived Microsoft article that walked me through configuring the user for Word to be Interactive User (in Word's DCOM Config properties), and lo a behold that did the trick. However, as far as I comprehend windows security, this is a very poor solution. This project was a crash course on a number of things, windows security being one of them, so I'm kind of flailing around here. System admin stuff is not my area of expertise.

I'd like to return Word to its default User settings, and work out some other way of executing my console program that still keeps Word from crapping out behind the scenes. Can Powershell help? I ran across this Hey Scripting Guy article that looks like it could be adapted to my purposes. Here's what I was thinking: In my php code, I'd have the shell_exec function start powershell with the path to a script (Working from the syntax used here, to start with), and for the script I'd modify the Hey Scripting Guy example to have it just run the console program instead of doing the scheduling stuff with the .vbs script.

I'd appreciate any help figuring out how to make the Powershell script, but mainly I'm wondering if this is a) feasible, and b) a more secure solution than what I've currently got going.

Orbis Tertius fucked around with this message at 10:17 on Oct 15, 2010

Walked
Apr 14, 2003

Walked posted:

I'll give that a whirl when I'm back in my exchange environment tomorrow. I'm a C# guy; the semicolon is habitual. :(

Stripping every single semicolon out of this didnt do poo poo. ARRRRRR I am gonna quit life. Who needs to monitor exchange anyways?

Walked
Apr 14, 2003

So piping the queues and stores functions to |Out-Default sorted it. Weird.

I still dont totally understand the pipeline. Its like learning OOP all over again. :gonk:

adaz
Mar 7, 2009

^^^
I still don't get that, it really doesn't make any sense =/. But then again the format returned/accepted by some cmd-lets is completely retarded, and what they will accept can boggle the mind (see Export-Csv for a perfect example of an awfully designed cmdlet as far as what input it'll accept).

Orbis Tertius posted:

I'm working on an Intranet-only site (running Apache/PHP/MySQL) and I recently implemented some automation stuff involving Word 2003. I did this by having the shell_exec PHP function run a console program I wrote in C#, which handles all the automated .doc parsing stuff I needed to do. This project was a non-starter for awhile; I couldn't seem to get anything to work, but I stumbled across an archived Microsoft article that walked me through configuring the user for Word to be Interactive User (in Word's DCOM Config properties), and lo a behold that did the trick. However, as far as I comprehend windows security, this is a very poor solution. This project was a crash course on a number of things, windows security being one of them, so I'm kind of flailing around here. System admin stuff is not my area of expertise.

I'd like to return Word to its default User settings, and work out some other way of executing my console program that still keeps Word from crapping out behind the scenes. Can Powershell help? I ran across this Hey Scripting Guy article that looks like it could be adapted to my purposes. Here's what I was thinking: In my php code, I'd have the shell_exec function start powershell with the path to a script (Working from the syntax used here, to start with), and for the script I'd modify the Hey Scripting Guy example to have it just run the console program instead of doing the scheduling stuff with the .vbs script.

I'd appreciate any help figuring out how to make the Powershell script, but mainly I'm wondering if this is a) feasible, and b) a more secure solution than what I've currently got going.

So, from your example, you want your php webpage to invoke a remote powershell script that will read/do some stuff with word values and then.. return a result? or just ~do some things~ with word? What exactly are you doing with word? Powershell can do tons with word, and quite easily, but it really depends on what exactly you want done for anyone to say if powershell is your best bet or not.

adaz fucked around with this message at 18:54 on Oct 15, 2010

Walked
Apr 14, 2003

This is a simple one.

Reading the Windows Powershell Cookbook (and gently caress me this book rules).

A lot of their scipts call on others that were written.
Generally in all my readings its always "and you can use your own PS scripts as if they were cmdlets, call them like: PS> yourscripthere.ps1 - see isnt that awesome?!"

But the cookbook has you calling them sans extension. Is there a default search location for your own cmdlets or do I just need to use an alias or what?

Building up my script library at work to make life easier here. Want to streamline it best possible.

adaz
Mar 7, 2009

Walked posted:

This is a simple one.

Reading the Windows Powershell Cookbook (and gently caress me this book rules).

A lot of their scipts call on others that were written.
Generally in all my readings its always "and you can use your own PS scripts as if they were cmdlets, call them like: PS> yourscripthere.ps1 - see isnt that awesome?!"

But the cookbook has you calling them sans extension. Is there a default search location for your own cmdlets or do I just need to use an alias or what?

Building up my script library at work to make life easier here. Want to streamline it best possible.

It's called Dot Sourcing and got a bit easier in V2. The scripting guys have an article up on it a few weeks old that probably do a better job explaining it than I would:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/07/reuse-powershell-code-to-simplify-script-creation.aspx

What I usually end up doing is tossing every function I think might be reused into like common.ps1 and all my scripts just dot source that on load. You can also just load them into your powershell profile if you mainly run the scripts as yourself, then you really don't have to worry about dot-sourcing - they are in your profile and can be run natively without any of the ps1 stuff.

Walked
Apr 14, 2003

adaz posted:

It's called Dot Sourcing and got a bit easier in V2. The scripting guys have an article up on it a few weeks old that probably do a better job explaining it than I would:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/07/reuse-powershell-code-to-simplify-script-creation.aspx

What I usually end up doing is tossing every function I think might be reused into like common.ps1 and all my scripts just dot source that on load. You can also just load them into your powershell profile if you mainly run the scripts as yourself, then you really don't have to worry about dot-sourcing - they are in your profile and can be run natively without any of the ps1 stuff.

Perfect. Powershell is loving killing it over here though. I am loving it; even if I'm a bit slow on picking a few things up. :)

Walked
Apr 14, 2003

WELP back again. This should be stupid loving easy but it is not. Arrgh.

Out-file and Out-default both eat the pipeline up.

Great. Except I want to output the same item to the console as to a text file (this is for health reports on the network).

Is there any way to do this other than assigning each item generated to the report a variable name and then running Out-File and Out-Default on each? Bleh

Victor
Jun 18, 2004
Walked: Tee-Object

Victor fucked around with this message at 00:14 on Oct 19, 2010

Walked
Apr 14, 2003

gently caress. Thank you.

:)

edit: Nopee; that had a complete lack of an append option. Meh.
Start-Transaction / Stop-Transaction covered my exact goals, which was just to pull all the results of a script run. It fucks up the carriage returns in Notepad; but thats minor really. It mostly looks aaaaa-ok.

No worry though :)

Walked fucked around with this message at 03:28 on Oct 19, 2010

Adbot
ADBOT LOVES YOU

adaz
Mar 7, 2009

Walked posted:

gently caress. Thank you.

:)

edit: Nopee; that had a complete lack of an append option. Meh.
Start-Transaction / Stop-Transaction covered my exact goals, which was just to pull all the results of a script run. It fucks up the carriage returns in Notepad; but thats minor really. It mostly looks aaaaa-ok.

No worry though :)

Write-Host should also work as it doesn't consume the pipeline

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