RE: Powershell question
ToString() doesn't work for you? Convert-* don't work for you? I'm a little confused as to what you want to do... From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Thursday, February 14, 2013 7:14 PM To: NT System Admin Issues Subject: Powershell question Hey guys, I have a System.Xml.XmlDocument object I want to convert back to textual representation so I can save it in a variable. The .Save() method allows for a console object, anyone know how to do this for a variable? Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
Ugh, just got schooled by a .net dev:) So the issue is that when I use an xpath to carve up an xml config file locally and ship the System.Xml.XmlDocument object off to a remote computer via remoting, it gets serialized, so its almost useless at the far end. What I plan to do is convert all the configs fanned out to the set hosts to a string object so it does not undergo serialization. [XML]$XML = Get-Content 'C:\Data\config.xml' $StringWriter = New-Object System.IO.StringWriter $XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter $xmlWriter.Formatting = indented $xmlWriter.Indentation = '4' $xml.WriteContentTo($XmlWriter) $XmlWriter.Flush() $StringWriter.Flush() $StringWriter.ToString() A bit much to go through, but it gets what I need. I'll pass this in as an arg to the invoke cmd and convert to an xml object to get the nice parsing/xpath ability... Thanks! jlc From: Michael B. Smith Sent: Thursday, February 14, 2013 5:21 PM To: NT System Admin Issues Subject: RE: Powershell question ToString() doesn't work for you? Convert-* don't work for you? I'm a little confused as to what you want to do... From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Thursday, February 14, 2013 7:14 PM To: NT System Admin Issues Subject: Powershell question Hey guys, I have a System.Xml.XmlDocument object I want to convert back to textual representation so I can save it in a variable. The .Save() method allows for a console object, anyone know how to do this for a variable? Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question - property to determine group vs user, using Quest Get-QADUser
This will get only user type objects Get-QADGroupMember $GroupName -type 'user' This will get only user type objects AND users from any nested groups. Get-QADGroupMember $GroupName -type 'user' -indirect So if the rest of your script currently works that should be the only change you have to make to that part. I will point out that your use of the Select Name is destroying the object data in the pipeline. It looks like you might be able to avoid that extra $Employee = Get-QADUser $User.Name user look up call. I'd have to play with it more but I am trying to actually have an answer to a PoSH question before MBS gets in with the solution for once so I could be wrong. :) Steven Peck http://www.blkmtn.org On Fri, Oct 5, 2012 at 8:36 AM, Michael Leone oozerd...@gmail.com wrote: I'm confused about something. I am writing a Powershell script, using the Quest AD CMDLETs. I have a list of groups that I need to retrieve the membership list for. But I don't want any group members that are themselves groups (i.e., no nested groups); I only want users. And I am not sure how best to accomplish this. At the moment, my script loops thought my list of groups, and I get the list of names who are members: $TheUsers = Get-QADGroupMember $GroupName | Select Name | Sort -property Name I then loop through the returned user list and output individual user accounts that are not disabled into a spreadsheet. ForEach ($User in $TheUsers) { $Employee = Get-QADUser $User.Name $DisabledUser = $Employee.AccountIsDisabled IF ( $DisabledUser -eq $false ) { $Cells.Item($CurrentRow, $CurrentCol) = $GroupCounter (I don't want to make the pipelining too complicated, in case the other guys need to maintain this script in my absence) And so forth. But what I don't know is how to determine that $Employee is a person and not a group. I'm sure it's simple and pretty much staring me in the face, but I'm not seeing it. Groups have no AccountIsDisabled property, apparently, so any groups who are members of the group I am searching are not falling through into the section that formats the spreadsheet. SO: when I do a Get-QADUser someuser, what property should I be looking at to determine that someuser is actually a group? Then I can modify my IF statement appropriately. Thanks, and sorry for being such a n00b at this ... ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question - property to determine group vs user, using Quest Get-QADUser
I think this should work for you: $TheUsers = Get-QADGroupMember $GroupName | where {$_.type -eq 'user'} | Select Name | Sort Name On Fri, Oct 5, 2012 at 11:36 AM, Michael Leone oozerd...@gmail.com wrote: I'm confused about something. I am writing a Powershell script, using the Quest AD CMDLETs. I have a list of groups that I need to retrieve the membership list for. But I don't want any group members that are themselves groups (i.e., no nested groups); I only want users. And I am not sure how best to accomplish this. At the moment, my script loops thought my list of groups, and I get the list of names who are members: $TheUsers = Get-QADGroupMember $GroupName | Select Name | Sort -property Name I then loop through the returned user list and output individual user accounts that are not disabled into a spreadsheet. ForEach ($User in $TheUsers) { $Employee = Get-QADUser $User.Name $DisabledUser = $Employee.AccountIsDisabled IF ( $DisabledUser -eq $false ) { $Cells.Item($CurrentRow, $CurrentCol) = $GroupCounter (I don't want to make the pipelining too complicated, in case the other guys need to maintain this script in my absence) And so forth. But what I don't know is how to determine that $Employee is a person and not a group. I'm sure it's simple and pretty much staring me in the face, but I'm not seeing it. Groups have no AccountIsDisabled property, apparently, so any groups who are members of the group I am searching are not falling through into the section that formats the spreadsheet. SO: when I do a Get-QADUser someuser, what property should I be looking at to determine that someuser is actually a group? Then I can modify my IF statement appropriately. Thanks, and sorry for being such a n00b at this ... ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question - property to determine group vs user, using Quest Get-QADUser
So... $TheUsers = Get-QADGroupMember $GroupName -type 'user' At this moment you have the user objects and their properties so let's try $TheUsers | Get-Member Looking at the Properties field there is a AccountIsDisabled property.. yay. Lot's of other properties as well which is nice since you have already paid the price for lookup. $TheUsers = Get-QADGroupMember $GroupName -type 'user' foreach ($user in $TheUsers) { if ($user.AccountIsdisabled -eq $false) { Write-Output $user.name } } That should work without the extra Get-QADUser lookup which will speed the script up. Steven Peck http://www.blkmtn.org On Fri, Oct 5, 2012 at 8:52 AM, Steven Peck sep...@gmail.com wrote: This will get only user type objects Get-QADGroupMember $GroupName -type 'user' This will get only user type objects AND users from any nested groups. Get-QADGroupMember $GroupName -type 'user' -indirect So if the rest of your script currently works that should be the only change you have to make to that part. I will point out that your use of the Select Name is destroying the object data in the pipeline. It looks like you might be able to avoid that extra $Employee = Get-QADUser $User.Name user look up call. I'd have to play with it more but I am trying to actually have an answer to a PoSH question before MBS gets in with the solution for once so I could be wrong. :) Steven Peck http://www.blkmtn.org On Fri, Oct 5, 2012 at 8:36 AM, Michael Leone oozerd...@gmail.com wrote: I'm confused about something. I am writing a Powershell script, using the Quest AD CMDLETs. I have a list of groups that I need to retrieve the membership list for. But I don't want any group members that are themselves groups (i.e., no nested groups); I only want users. And I am not sure how best to accomplish this. At the moment, my script loops thought my list of groups, and I get the list of names who are members: $TheUsers = Get-QADGroupMember $GroupName | Select Name | Sort -property Name I then loop through the returned user list and output individual user accounts that are not disabled into a spreadsheet. ForEach ($User in $TheUsers) { $Employee = Get-QADUser $User.Name $DisabledUser = $Employee.AccountIsDisabled IF ( $DisabledUser -eq $false ) { $Cells.Item($CurrentRow, $CurrentCol) = $GroupCounter (I don't want to make the pipelining too complicated, in case the other guys need to maintain this script in my absence) And so forth. But what I don't know is how to determine that $Employee is a person and not a group. I'm sure it's simple and pretty much staring me in the face, but I'm not seeing it. Groups have no AccountIsDisabled property, apparently, so any groups who are members of the group I am searching are not falling through into the section that formats the spreadsheet. SO: when I do a Get-QADUser someuser, what property should I be looking at to determine that someuser is actually a group? Then I can modify my IF statement appropriately. Thanks, and sorry for being such a n00b at this ... ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question - property to determine group vs user, using Quest Get-QADUser
On Fri, Oct 5, 2012 at 12:15 PM, Steven Peck sep...@gmail.com wrote: So... $TheUsers = Get-QADGroupMember $GroupName -type 'user' At this moment you have the user objects and their properties so let's try Yes, but that's not all I want. I *do* want to see any groups that are members of $GroupName, but not any disabled users who are members of $GroupName ... The above would filter out the group names. Out of the list of all members of $GroupName, I want to list out only groups (nested groups) and users who are not disabled. The problem with using an IF statement that looks at the AccountIsDisabled property is that a group name will not have that property, and so the IF statement fails, and the nested group is not included in the output. ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question - property to determine group vs user, using Quest Get-QADUser
On Fri, Oct 5, 2012 at 2:14 PM, Michael Leone oozerd...@gmail.com wrote: On Fri, Oct 5, 2012 at 12:15 PM, Steven Peck sep...@gmail.com wrote: So... $TheUsers = Get-QADGroupMember $GroupName -type 'user' At this moment you have the user objects and their properties so let's try Yes, but that's not all I want. I *do* want to see any groups that are members of $GroupName, but not any disabled users who are members of $GroupName ... The above would filter out the group names. I found the ClassName property will help me out. This IF will include all non-disabled users, and all groups IF ( ($Employee.ClassName -eq $null) -or (($Employee.AccountIsDisabled -eq $false) -and ($Employee.ClassName -eq user))) Apparently, groups have a null ClassName, and users have a ClassName of user. Maybe there's a better way to differentiate, but this seems to be working. Thanks for the nudges in the right direction, everyone. ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question - listing groups a user belongs to, and the notes/description of the group
With the Quest CMDLets this works: get-qaduser jdoe -properties memberof|select -expandProperty memberof|get-qadgroup|select name,notes Christopher Bodnar Enterprise Architect I, Corporate Office of Technology:Enterprise Architecture and Engineering Services Tel 610-807-6459 3900 Burgess Place, Bethlehem, PA 18017 christopher_bod...@glic.com The Guardian Life Insurance Company of America www.guardianlife.com From: Michael Leone oozerd...@gmail.com To: NT System Admin Issues ntsysadmin@lyris.sunbelt-software.com Date: 09/26/2012 10:46 AM Subject:Powershell question - listing groups a user belongs to, and the notes/description of the group I have this request to list all the groups a specific set of users belong to. Since we use groups to control ACLs, this can (effectively) be a listing of all the shared folders the user has access to (we list the location of the shared folder in the notes of the group). I'm still new to PS, and could use a bit of a pointer as to how to get to the description. To get the list of groups, I am planning on: import-module ActiveDirectory cd AD: and then loop through a text file of SAMAccountNames: Get-ADUser -Identity LeoneM -Properties memberof | select -ExpandProperty memberof | get-adgroup | select name This would give me the names of the groups (thank you, Google ...), but how do I get to the descriptions of the groups that are returned? I don't seem to see the notes property in the adgroup. How can I list that attribute of the returned group? If someone has a better idea, I'm all ears. :-) ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin - This message, and any attachments to it, may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are notified that any use, dissemination, distribution, copying, or communication of this message is strictly prohibited. If you have received this message in error, please notify the sender immediately by return e-mail and delete the message and any attachments. Thank you. ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadminimage/jpeg
Re: Powershell question - listing groups a user belongs to, and the notes/description of the group
With Quest get-qadmemberof USERNAME | Select name, notes On Wed, Sep 26, 2012 at 10:44 AM, Michael Leone oozerd...@gmail.com wrote: I have this request to list all the groups a specific set of users belong to. Since we use groups to control ACLs, this can (effectively) be a listing of all the shared folders the user has access to (we list the location of the shared folder in the notes of the group). I'm still new to PS, and could use a bit of a pointer as to how to get to the description. To get the list of groups, I am planning on: import-module ActiveDirectory cd AD: and then loop through a text file of SAMAccountNames: Get-ADUser -Identity LeoneM -Properties memberof | select -ExpandProperty memberof | get-adgroup | select name This would give me the names of the groups (thank you, Google ...), but how do I get to the descriptions of the groups that are returned? I don't seem to see the notes property in the adgroup. How can I list that attribute of the returned group? If someone has a better idea, I'm all ears. :-) ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question - listing groups a user belongs to, and the notes/description of the group
On Wed, Sep 26, 2012 at 11:15 AM, KenM kenmli...@gmail.com wrote: With Quest get-qadmemberof USERNAME | Select name, notes Well, THAT was stunningly easy! LOL Thanks. That will make the report a whole lot easier, I think ... I will have to read up on these Quest addins ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
You need to take a look at the operator and the invoke-command and invoke-expression cmdlets. Insofar as push the extra arg into the array list YUCK. Check out Start-Process and Wait-Process. The way you are using Verbose isn't the way it's MEANT to be used (although what you are doing certainly does work). All you need to do is set CmdletBinding as the master attribute on the parameter list. -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Wednesday, May 30, 2012 4:55 PM To: NT System Admin Issues Subject: Powershell question I often have scripts I write that involve passing potentially different sets of commands to cmdlets based on switches I pass to the script. Some provide built in means to make it easy: -Verbose:($PSBoundParameters['Verbose'] -eq $true) In the case where I need to invoke a binary, I push the extra arg into the array list passed to the System.Diagnostics.Process job as the arglist. Works well. If I am simply running a cmdlet: Some-Cmdlet ` -Param1 xxx ` -Param2 xxx If I tack another back tick on param2, what powershell foo allows a conditional 3rd param to be passed? Would be so much tidier than if/else and duplicating the whole thing. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
Actually, you are right about the -verbose, I forgot about that and simply opened up the first script. CmdletBinding enables all cmdlets to produce the output if they provide... I am not following you on the operator for the Some-Cmdlet example. I did try invoke-expression without luck, if its the right way I will revisit it and figure out what I did wrong. As for running a binary, why is my method flawed (brief idea here)? $Args = New-Object System.Collections.ArrayList [void]$Args.Add(--log-file=path) [void]$Args.Add(--recursive) ... If ($PSBoundParameters['Verbose']) { [void]$Args.Add(--verbose) [void]$Args.Add(--stats) } If ($Checksum) { [void]$Args.Add(--checksum) } $Process = New-Object System.Diagnostics.Process $Process.StartInfo.FileName = $BinPath\rsync.exe $Process.StartInfo.Arguments = $Args This works pretty well and takes care of a *myriad* of shell escaping as System.Diagnostics.Process does all the heavy lifting? Thanks! jlc From: Michael B. Smith [mich...@smithcons.com] Sent: Wednesday, May 30, 2012 4:41 PM To: NT System Admin Issues Subject: RE: Powershell question You need to take a look at the operator and the invoke-command and invoke-expression cmdlets. Insofar as push the extra arg into the array list YUCK. Check out Start-Process and Wait-Process. The way you are using Verbose isn't the way it's MEANT to be used (although what you are doing certainly does work). All you need to do is set CmdletBinding as the master attribute on the parameter list. -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Wednesday, May 30, 2012 4:55 PM To: NT System Admin Issues Subject: Powershell question I often have scripts I write that involve passing potentially different sets of commands to cmdlets based on switches I pass to the script. Some provide built in means to make it easy: -Verbose:($PSBoundParameters['Verbose'] -eq $true) In the case where I need to invoke a binary, I push the extra arg into the array list passed to the System.Diagnostics.Process job as the arglist. Works well. If I am simply running a cmdlet: Some-Cmdlet ` -Param1 xxx ` -Param2 xxx If I tack another back tick on param2, what powershell foo allows a conditional 3rd param to be passed? Would be so much tidier than if/else and duplicating the whole thing. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
I didn't say it was flawed. I said YUCK. :-) See below. I didn't use Wait-Process below because I want the exit value. The process below also lets the process object handle shell escape and stuff. I have an entire module I use for process handling, output redirection, etc. etc. It's part of my updated CoreConfigurator rewrite in PowerShell. I'll release it one day. function New-NativeBinary { $filename, $arguments = $args $process = Start-Process -FilePath $filename -Argument $arguments -NoNewWindow ` -RedirectStandardError $script:stderrFile -RedirectStandardOutput $script:stdoutFile -PassThru if( $process ) { $process.WaitForExit() $exit = $process.ExitCode if( $exit -eq $null ) { $exit = 0 } $process.Close() $process.Dispose() } else { Write-Error New-NativeBinary: the process did not start } } -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Wednesday, May 30, 2012 7:06 PM To: NT System Admin Issues Subject: RE: Powershell question Actually, you are right about the -verbose, I forgot about that and simply opened up the first script. CmdletBinding enables all cmdlets to produce the output if they provide... I am not following you on the operator for the Some-Cmdlet example. I did try invoke-expression without luck, if its the right way I will revisit it and figure out what I did wrong. As for running a binary, why is my method flawed (brief idea here)? $Args = New-Object System.Collections.ArrayList [void]$Args.Add(--log-file=path) [void]$Args.Add(--recursive) ... If ($PSBoundParameters['Verbose']) { [void]$Args.Add(--verbose) [void]$Args.Add(--stats) } If ($Checksum) { [void]$Args.Add(--checksum) } $Process = New-Object System.Diagnostics.Process $Process.StartInfo.FileName = $BinPath\rsync.exe $Process.StartInfo.Arguments = $Args This works pretty well and takes care of a *myriad* of shell escaping as System.Diagnostics.Process does all the heavy lifting? Thanks! jlc From: Michael B. Smith [mich...@smithcons.com] Sent: Wednesday, May 30, 2012 4:41 PM To: NT System Admin Issues Subject: RE: Powershell question You need to take a look at the operator and the invoke-command and invoke-expression cmdlets. Insofar as push the extra arg into the array list YUCK. Check out Start-Process and Wait-Process. The way you are using Verbose isn't the way it's MEANT to be used (although what you are doing certainly does work). All you need to do is set CmdletBinding as the master attribute on the parameter list. -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Wednesday, May 30, 2012 4:55 PM To: NT System Admin Issues Subject: Powershell question I often have scripts I write that involve passing potentially different sets of commands to cmdlets based on switches I pass to the script. Some provide built in means to make it easy: -Verbose:($PSBoundParameters['Verbose'] -eq $true) In the case where I need to invoke a binary, I push the extra arg into the array list passed to the System.Diagnostics.Process job as the arglist. Works well. If I am simply running a cmdlet: Some-Cmdlet ` -Param1 xxx ` -Param2 xxx If I tack another back tick on param2, what powershell foo allows a conditional 3rd param to be passed? Would be so much tidier than if/else and duplicating the whole thing. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe
RE: Powershell question
I didn't use Wait-Process below because I want the exit value. Did someone say exit code? $Args = New-Object System.Collections.ArrayList [void]$Args.Add(--Bad-Arg) $Process = New-Object System.Diagnostics.Process $Process.StartInfo.UseShellExecute = $false $Process.StartInfo.RedirectStandardOutput = $true $Process.StartInfo.RedirectStandardError = $true $Process.StartInfo.FileName = C:\Windows\System32\ipconfig.exe $Process.StartInfo.Arguments = $Args [void]$Process.Start() $Process.WaitForExit() $ExitVal = $Process.ExitCode $StdOut = $Process.StandardOutput.ReadToEnd() $StdErr = $Process.StandardError.ReadToEnd() $ExitVal $StdOut -- 1 Error: unrecognized or incomplete command line. /snip ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
Write a function. You can also do this with a filter, but almost no one uses filters. And it wouldn't reduce your line count any more than a function would. -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, April 03, 2012 5:27 PM To: NT System Admin Issues Subject: Powershell question Hey guys, What is the most elegant way to -xor test two paths and keep the one that exists? I have a bunch of cases where I check for the existence of two reg keys (both can not co-exist) and then set a variable based on either one. If ((Test-Path hklm:\... ) -xor (Test-Path hklm:\... )) { $var = value1 or value2 } Else { must exit the script } is the logic I need, but then I need additional code to set a single variable to value1 or value2. Not a big deal once, but I have several and I was just hoping for a slick way to accomplish setting $var to either value based on which side tests true w/o another if block. Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
How about something like this. You can figure out what $value1 and $value2 should look like (could just be your Test-Path calls or maybe the function is registry aware...). [bool]function XorValues($value1, $value2, [ref]$outputVal) { if ($value1 -xor $value2) { If ($value1) { $outputVal = $value1 return $true } If ($value2) { $outputVal = $value2 return $true } } else { return $false } } Thanks, Brian Desmond br...@briandesmond.com w - 312.625.1438 | c - 312.731.3132 -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, April 03, 2012 4:27 PM To: NT System Admin Issues Subject: Powershell question Hey guys, What is the most elegant way to -xor test two paths and keep the one that exists? I have a bunch of cases where I check for the existence of two reg keys (both can not co-exist) and then set a variable based on either one. If ((Test-Path hklm:\... ) -xor (Test-Path hklm:\... )) { $var = value1 or value2 } Else { must exit the script } is the logic I need, but then I need additional code to set a single variable to value1 or value2. Not a big deal once, but I have several and I was just hoping for a slick way to accomplish setting $var to either value based on which side tests true w/o another if block. Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
Thanks guys! From: Brian Desmond [br...@briandesmond.com] Sent: Tuesday, April 03, 2012 4:13 PM To: NT System Admin Issues Subject: RE: Powershell question How about something like this. You can figure out what $value1 and $value2 should look like (could just be your Test-Path calls or maybe the function is registry aware...). [bool]function XorValues($value1, $value2, [ref]$outputVal) { if ($value1 -xor $value2) { If ($value1) { $outputVal = $value1 return $true } If ($value2) { $outputVal = $value2 return $true } } else { return $false } } Thanks, Brian Desmond br...@briandesmond.com w - 312.625.1438 | c - 312.731.3132 -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, April 03, 2012 4:27 PM To: NT System Admin Issues Subject: Powershell question Hey guys, What is the most elegant way to -xor test two paths and keep the one that exists? I have a bunch of cases where I check for the existence of two reg keys (both can not co-exist) and then set a variable based on either one. If ((Test-Path hklm:\... ) -xor (Test-Path hklm:\... )) { $var = value1 or value2 } Else { must exit the script } is the logic I need, but then I need additional code to set a single variable to value1 or value2. Not a big deal once, but I have several and I was just hoping for a slick way to accomplish setting $var to either value based on which side tests true w/o another if block. Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: PowerShell question
Referral means you ask a DC in Domain A for an object in Domain B. Your LDAP client code has to support and be configured to chase referrals. DSIDs provide the file and line number in the AD code that the error occurred at. They will vary by OS version, service pack, and even hotfix or security patch level. If you've got access to source, they're useful, otherwise they're useless. Thanks, Brian Desmond br...@briandesmond.com w - 312.625.1438 | c - 312.731.3132 -Original Message- From: Ben Scott [mailto:mailvor...@gmail.com] Sent: Thursday, January 19, 2012 7:58 PM To: NT System Admin Issues Subject: Re: PowerShell question On Thu, Jan 19, 2012 at 2:26 PM, Christopher Bodnar christopher_bod...@glic.com wrote: I've got a PowerShell script that enumerates a list of groups and their members. Works great in the domain that I run the script from (acme.com). Trying to make the same script work against a trusted domain (Widgets). Get-QADGroupMember : 202B: RefErr: DSID-031006E0 ... I haven't a clue about the Quest stuff, but I looked up 0x202B and got ERROR_DS_REFERRAL, A referral was returned from the server. I can't find any useful documentation on what that error actually *means*, but, if I had to guess, I would guess it means a question was asked of a DC, and the DC said ask this other guy. You say it works for your local domain but not the trusted domain. Perhaps your local DC, when asked for details about the trusted domain, is saying to go ask a DC in that trusted domain (reasonable), and the Quest tools aren't handling that for some reason. I also Googled DSID-031006E0. It appears lot of other people are getting similar symptoms, but answers seem in short supply. Maybe contact Quest for support? -- Ben ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: PowerShell question
DFL and FFL? Is Exchange in the mix? And if so, what version (including SP)? Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Christopher Bodnar [mailto:christopher_bod...@glic.com] Sent: Thursday, January 19, 2012 2:27 PM To: NT System Admin Issues Subject: PowerShell question I've got a PowerShell script that enumerates a list of groups and their members. Works great in the domain that I run the script from (acme.com). Trying to make the same script work against a trusted domain (Widgets). Using Quest CmdLets for this. The get-qadgroup command works fine, it's pulling back the groups, but when it gets to the get-qadgroupmember command I'm getting this error: Get-QADGroupMember : 202B: RefErr: DSID-031006E0, data 0, 1 access points ref 1: 'acme.com' At H:\scripts\PowerShell\Enum_admin_groups_rev1.ps1:23 char:31 + $members = get-qadgroupmember $ParentGroupName.name -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe r' -ConnectionPassword $pw + CategoryInfo : NotSpecified: (:) [Get-QADGroupMember], DirectoryAccessException + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.DirectoryAccessException,Quest.Act iveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetGroupMemberCmdlet Here is the script: ## $pw = Read-Host Enter password -AsSecureString $Group = get-qadgroup 'widgets_admins_*' -SizeLimit 0 -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe' -ConnectionPassword $pw ForEach ($ParentGroupName in $Group) { $members = get-qadgroupmember $ParentGroupName.name -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe' -ConnectionPassword $pw foreach ($GroupMembers in $members) { #Write-Host $ParentGroupName.name `t $GroupMembers.name `t $GroupMembers.samaccountname $($ParentGroupName.name) `t $($GroupMembers.name) `t $($GroupMembers.samaccountname)|Out-File -Append -filepath c:\temp\Admingroups_Widgets_rev1.csv } } ## Christopher Bodnar Technical Support III, Distributed Systems Service Delivery - Intel Services Tel 610-807-6459 3900 Burgess Place, Bethlehem, PA 18017 christopher_bod...@glic.commailto: [cid:image001.jpg@01CCD6BA.33528950] The Guardian Life Insurance Company of America www.guardianlife.comhttp://www.guardianlife.com/ - This message, and any attachments to it, may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are notified that any use, dissemination, distribution, copying, or communication of this message is strictly prohibited. If you have received this message in error, please notify the sender immediately by return e-mail and delete the message and any attachments. Thank you. ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmininline: image001.jpg
RE: PowerShell question
DFL and FFL are both W2K3. No Exchange in the mix. Christopher Bodnar Technical Support III, Distributed Systems Service Delivery - Intel Services Tel 610-807-6459 3900 Burgess Place, Bethlehem, PA 18017 christopher_bod...@glic.com The Guardian Life Insurance Company of America www.guardianlife.com From: Michael B. Smith mich...@smithcons.com To: NT System Admin Issues ntsysadmin@lyris.sunbelt-software.com Date: 01/19/2012 03:07 PM Subject:RE: PowerShell question DFL and FFL? Is Exchange in the mix? And if so, what version (including SP)? Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Christopher Bodnar [mailto:christopher_bod...@glic.com] Sent: Thursday, January 19, 2012 2:27 PM To: NT System Admin Issues Subject: PowerShell question I've got a PowerShell script that enumerates a list of groups and their members. Works great in the domain that I run the script from (acme.com). Trying to make the same script work against a trusted domain (Widgets). Using Quest CmdLets for this. The get-qadgroup command works fine, it's pulling back the groups, but when it gets to the get-qadgroupmember command I'm getting this error: Get-QADGroupMember : 202B: RefErr: DSID-031006E0, data 0, 1 access points ref 1: 'acme.com' At H:\scripts\PowerShell\Enum_admin_groups_rev1.ps1:23 char:31 + $members = get-qadgroupmember $ParentGroupName.name -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe r' -ConnectionPassword $pw + CategoryInfo : NotSpecified: (:) [Get-QADGroupMember], DirectoryAccessException + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.DirectoryAccessException,Quest.Act iveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetGroupMemberCmdlet Here is the script: ## $pw = Read-Host Enter password -AsSecureString $Group = get-qadgroup 'widgets_admins_*' -SizeLimit 0 -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe' -ConnectionPassword $pw ForEach ($ParentGroupName in $Group) { $members = get-qadgroupmember $ParentGroupName.name -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe' -ConnectionPassword $pw foreach ($GroupMembers in $members) { #Write-Host $ParentGroupName.name `t $GroupMembers.name `t $GroupMembers.samaccountname $($ParentGroupName.name) `t $($GroupMembers.name) `t $($GroupMembers.samaccountname)|Out-File -Append -filepath c:\temp\Admingroups_Widgets_rev1.csv } } ## Christopher Bodnar Technical Support III, Distributed Systems Service Delivery - Intel Services Tel 610-807-6459 3900 Burgess Place, Bethlehem, PA 18017 christopher_bod...@glic.com The Guardian Life Insurance Company of America www.guardianlife.com - This message, and any attachments to it, may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are notified that any use, dissemination, distribution, copying, or communication of this message is strictly prohibited. If you have received this message in error, please notify the sender immediately by return e-mail and delete the message and any attachments. Thank you. ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadminimage/jpegimage/jpeg
RE: PowerShell question
In that case, I've got no clue. Sorry... :( Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Christopher Bodnar [mailto:christopher_bod...@glic.com] Sent: Thursday, January 19, 2012 3:30 PM To: NT System Admin Issues Subject: RE: PowerShell question DFL and FFL are both W2K3. No Exchange in the mix. Christopher Bodnar Technical Support III, Distributed Systems Service Delivery - Intel Services Tel 610-807-6459 3900 Burgess Place, Bethlehem, PA 18017 christopher_bod...@glic.commailto: [cid:image001.jpg@01CCD6C6.7DDB8970] The Guardian Life Insurance Company of America www.guardianlife.comhttp://www.guardianlife.com/ From:Michael B. Smith mich...@smithcons.commailto:mich...@smithcons.com To:NT System Admin Issues ntsysadmin@lyris.sunbelt-software.commailto:ntsysadmin@lyris.sunbelt-software.com Date:01/19/2012 03:07 PM Subject:RE: PowerShell question DFL and FFL? Is Exchange in the mix? And if so, what version (including SP)? Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.comhttp://theessentialexchange.com/ From: Christopher Bodnar [mailto:christopher_bod...@glic.com] Sent: Thursday, January 19, 2012 2:27 PM To: NT System Admin Issues Subject: PowerShell question I've got a PowerShell script that enumerates a list of groups and their members. Works great in the domain that I run the script from (acme.com). Trying to make the same script work against a trusted domain (Widgets). Using Quest CmdLets for this. The get-qadgroup command works fine, it's pulling back the groups, but when it gets to the get-qadgroupmember command I'm getting this error: Get-QADGroupMember : 202B: RefErr: DSID-031006E0, data 0, 1 access points ref 1: 'acme.com' At H:\scripts\PowerShell\Enum_admin_groups_rev1.ps1:23 char:31 + $members = get-qadgroupmember $ParentGroupName.name -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe r' -ConnectionPassword $pw + CategoryInfo : NotSpecified: (:) [Get-QADGroupMember], DirectoryAccessException + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.DirectoryAccessException,Quest.Act iveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetGroupMemberCmdlet Here is the script: ## $pw = Read-Host Enter password -AsSecureString $Group = get-qadgroup 'widgets_admins_*' -SizeLimit 0 -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe' -ConnectionPassword $pw ForEach ($ParentGroupName in $Group) { $members = get-qadgroupmember $ParentGroupName.name -Service 'widgetsdc5:389' -ConnectionAccount 'widgets\jdoe' -ConnectionPassword $pw foreach ($GroupMembers in $members) { #Write-Host $ParentGroupName.name `t $GroupMembers.name `t $GroupMembers.samaccountname $($ParentGroupName.name) `t $($GroupMembers.name) `t $($GroupMembers.samaccountname)|Out-File -Append -filepath c:\temp\Admingroups_Widgets_rev1.csv } } ## Christopher Bodnar Technical Support III, Distributed Systems Service Delivery - Intel Services Tel 610-807-6459 3900 Burgess Place, Bethlehem, PA 18017 christopher_bod...@glic.commailto: [cid:image001.jpg@01CCD6C6.7DDB8970] The Guardian Life Insurance Company of America www.guardianlife.comhttp://www.guardianlife.com/ - This message, and any attachments to it, may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are notified that any use, dissemination, distribution, copying, or communication of this message is strictly prohibited. If you have received this message in error, please notify the sender immediately by return e-mail and delete the message and any attachments. Thank you. ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin - This message, and any attachments to it, may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, you are notified that any use, dissemination, distribution, copying
Re: PowerShell question
On Thu, Jan 19, 2012 at 2:26 PM, Christopher Bodnar christopher_bod...@glic.com wrote: I've got a PowerShell script that enumerates a list of groups and their members. Works great in the domain that I run the script from (acme.com). Trying to make the same script work against a trusted domain (Widgets). Get-QADGroupMember : 202B: RefErr: DSID-031006E0 ... I haven't a clue about the Quest stuff, but I looked up 0x202B and got ERROR_DS_REFERRAL, A referral was returned from the server. I can't find any useful documentation on what that error actually *means*, but, if I had to guess, I would guess it means a question was asked of a DC, and the DC said ask this other guy. You say it works for your local domain but not the trusted domain. Perhaps your local DC, when asked for details about the trusted domain, is saying to go ask a DC in that trusted domain (reasonable), and the Quest tools aren't handling that for some reason. I also Googled DSID-031006E0. It appears lot of other people are getting similar symptoms, but answers seem in short supply. Maybe contact Quest for support? -- Ben ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell question
download the Quest AD cmdlets get-qadgroupmember GROUPNAME | Select Name | out-file c:\users.txt On Tue, Jan 4, 2011 at 4:08 PM, Joseph Heaton jhea...@dfg.ca.gov wrote: I found this really simple powershell script that will list all members of a specified AD group. What I'd like to do is then pipe that to a text file. Here's the script: $root=([ADSI]).distinguishedName $Group = [ADSI](LDAP://CN=xxx, CN=Users,+ $root) $Group.member Now, this gives a nice, simple list of users in group xxx, but it is the FQDN of the user. What I'd really like to do is kick out a list of just the user name, without the CN= stuff. Also, once that list is kicked out, I'd like to pipe that list into a text file, so I can e-mail it to a requestor. Anyone know how to do this easily? (Complete scripting noob here, btw) Thanks, Joe ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
Here is your updated script: - start - $root=([ADSI]).distinguishedName $Group = [ADSI](LDAP://CN=Domain Admins,CN=Users,+ $root) $members = $Group.member foreach( $member in $members ) { $ary = $member.Split( , ); $result = $ary[0].Substring(3); $result; } - end - If you put it in zippy.ps1, then to output it to a file: ./zippy c:\temp\filename.txt Which is a shortcut for ./zippy | out-file -force -filepath c:\temp\filename.txt -encoding ascii Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com -Original Message- From: Joseph Heaton [mailto:jhea...@dfg.ca.gov] Sent: Tuesday, January 04, 2011 4:08 PM To: NT System Admin Issues Subject: Powershell question I found this really simple powershell script that will list all members of a specified AD group. What I'd like to do is then pipe that to a text file. Here's the script: $root=([ADSI]).distinguishedName $Group = [ADSI](LDAP://CN=xxx, CN=Users,+ $root) $Group.member Now, this gives a nice, simple list of users in group xxx, but it is the FQDN of the user. What I'd really like to do is kick out a list of just the user name, without the CN= stuff. Also, once that list is kicked out, I'd like to pipe that list into a text file, so I can e-mail it to a requestor. Anyone know how to do this easily? (Complete scripting noob here, btw) Thanks, Joe ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell question
that is awesome. Thanks Michael. Michael B. Smith mich...@smithcons.com 1/4/2011 1:17 PM Here is your updated script: - start - $root=([ADSI]).distinguishedName $Group = [ADSI](LDAP://CN=Domain Admins,CN=Users,+ $root) $members = $Group.member foreach( $member in $members ) { $ary = $member.Split( , ); $result = $ary[0].Substring(3); $result; } - end - If you put it in zippy.ps1, then to output it to a file: ./zippy c:\temp\filename.txt Which is a shortcut for ./zippy | out-file -force -filepath c:\temp\filename.txt -encoding ascii Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com -Original Message- From: Joseph Heaton [mailto:jhea...@dfg.ca.gov] Sent: Tuesday, January 04, 2011 4:08 PM To: NT System Admin Issues Subject: Powershell question I found this really simple powershell script that will list all members of a specified AD group. What I'd like to do is then pipe that to a text file. Here's the script: $root=([ADSI]).distinguishedName $Group = [ADSI](LDAP://CN=xxx, CN=Users,+ $root) $Group.member Now, this gives a nice, simple list of users in group xxx, but it is the FQDN of the user. What I'd really like to do is kick out a list of just the user name, without the CN= stuff. Also, once that list is kicked out, I'd like to pipe that list into a text file, so I can e-mail it to a requestor. Anyone know how to do this easily? (Complete scripting noob here, btw) Thanks, Joe ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell Question
I'd try something like this: $sfDesktop = $env:USERPROFILE + \desktop On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Guys, What’s the most simple and elegant way to trap for the following variable assignment: Eg. $sfDesktop = [Environment]::GetFolderPath(Desktop) Should I assign it like this, and test for a proper value when using (skip otherwise while I cycle through all the ones I need to)? If so, how do you test the value for it having been properly assigned? Sorry, ps noob here… Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell Question
Hey Rubens, I am not too concerned with how I get the value, but more on how to trap if it doesn't enumerate correctly. Once I start looping through all the special folders of interest, I don't want to send something wrong into the routine that follows. Thanks! jlc -Original Message- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 12:46 PM To: NT System Admin Issues Subject: Re: Powershell Question I'd try something like this: $sfDesktop = $env:USERPROFILE + \desktop On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Guys, What's the most simple and elegant way to trap for the following variable assignment: Eg. $sfDesktop = [Environment]::GetFolderPath(Desktop) Should I assign it like this, and test for a proper value when using (skip otherwise while I cycle through all the ones I need to)? If so, how do you test the value for it having been properly assigned? Sorry, ps noob here. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: Powershell Question
I think you can try this: $sfDesktop = [Environment]::GetFolderPath(Desktop) If(!(test-path $sfDesktop)) { write-host Something's wrong } Else { write-host It worked } On Tue, Sep 7, 2010 at 3:50 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Rubens, I am not too concerned with how I get the value, but more on how to trap if it doesn't enumerate correctly. Once I start looping through all the special folders of interest, I don't want to send something wrong into the routine that follows. Thanks! jlc -Original Message- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 12:46 PM To: NT System Admin Issues Subject: Re: Powershell Question I'd try something like this: $sfDesktop = $env:USERPROFILE + \desktop On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Guys, What's the most simple and elegant way to trap for the following variable assignment: Eg. $sfDesktop = [Environment]::GetFolderPath(Desktop) Should I assign it like this, and test for a proper value when using (skip otherwise while I cycle through all the ones I need to)? If so, how do you test the value for it having been properly assigned? Sorry, ps noob here. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell Question
Test-path is probably what you want. I'm not sure what you mean by enumerate correctly. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, September 07, 2010 2:50 PM To: NT System Admin Issues Subject: RE: Powershell Question Hey Rubens, I am not too concerned with how I get the value, but more on how to trap if it doesn't enumerate correctly. Once I start looping through all the special folders of interest, I don't want to send something wrong into the routine that follows. Thanks! jlc -Original Message- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 12:46 PM To: NT System Admin Issues Subject: Re: Powershell Question I'd try something like this: $sfDesktop = $env:USERPROFILE + \desktop On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Guys, What's the most simple and elegant way to trap for the following variable assignment: Eg. $sfDesktop = [Environment]::GetFolderPath(Desktop) Should I assign it like this, and test for a proper value when using (skip otherwise while I cycle through all the ones I need to)? If so, how do you test the value for it having been properly assigned? Sorry, ps noob here. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell Question
Yeah, You have to pardon my lack of ps experience:) I really don't know what happens to that var if the expression bails, so whatever the contents of the var after failure are, I didn't want to push that into the backup function. Thanks Rubens and Michael! jlc -Original Message- From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Tuesday, September 07, 2010 1:46 PM To: NT System Admin Issues Subject: RE: Powershell Question Test-path is probably what you want. I'm not sure what you mean by enumerate correctly. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, September 07, 2010 2:50 PM To: NT System Admin Issues Subject: RE: Powershell Question Hey Rubens, I am not too concerned with how I get the value, but more on how to trap if it doesn't enumerate correctly. Once I start looping through all the special folders of interest, I don't want to send something wrong into the routine that follows. Thanks! jlc -Original Message- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 12:46 PM To: NT System Admin Issues Subject: Re: Powershell Question I'd try something like this: $sfDesktop = $env:USERPROFILE + \desktop On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Guys, What's the most simple and elegant way to trap for the following variable assignment: Eg. $sfDesktop = [Environment]::GetFolderPath(Desktop) Should I assign it like this, and test for a proper value when using (skip otherwise while I cycle through all the ones I need to)? If so, how do you test the value for it having been properly assigned? Sorry, ps noob here. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell Question
So test-path makes most sense to me as well, but the If won't even execute of the path is invalid? How do you work around that? Thanks for all the help... jlc -Original Message- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 1:45 PM To: NT System Admin Issues Subject: Re: Powershell Question I think you can try this: $sfDesktop = [Environment]::GetFolderPath(Desktop) If(!(test-path $sfDesktop)) { write-host Something's wrong } Else { write-host It worked } On Tue, Sep 7, 2010 at 3:50 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Rubens, I am not too concerned with how I get the value, but more on how to trap if it doesn't enumerate correctly. Once I start looping through all the special folders of interest, I don't want to send something wrong into the routine that follows. Thanks! jlc -Original Message- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 12:46 PM To: NT System Admin Issues Subject: Re: Powershell Question I'd try something like this: $sfDesktop = $env:USERPROFILE + \desktop On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Guys, What's the most simple and elegant way to trap for the following variable assignment: Eg. $sfDesktop = [Environment]::GetFolderPath(Desktop) Should I assign it like this, and test for a proper value when using (skip otherwise while I cycle through all the ones I need to)? If so, how do you test the value for it having been properly assigned? Sorry, ps noob here. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell Question
Then don't use it. $sfDesktop = [Environment]::GetFolderPath(Desktop) If( $sfDesktop ) { If( test-path $sfDesktop ) { it's all good, call the function } } Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, September 07, 2010 4:09 PM To: NT System Admin Issues Subject: RE: Powershell Question Yeah, You have to pardon my lack of ps experience:) I really don't know what happens to that var if the expression bails, so whatever the contents of the var after failure are, I didn't want to push that into the backup function. Thanks Rubens and Michael! jlc -Original Message- From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Tuesday, September 07, 2010 1:46 PM To: NT System Admin Issues Subject: RE: Powershell Question Test-path is probably what you want. I'm not sure what you mean by enumerate correctly. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, September 07, 2010 2:50 PM To: NT System Admin Issues Subject: RE: Powershell Question Hey Rubens, I am not too concerned with how I get the value, but more on how to trap if it doesn't enumerate correctly. Once I start looping through all the special folders of interest, I don't want to send something wrong into the routine that follows. Thanks! jlc -Original Message- From: Rubens Almeida [mailto:rubensalme...@gmail.com] Sent: Tuesday, September 07, 2010 12:46 PM To: NT System Admin Issues Subject: Re: Powershell Question I'd try something like this: $sfDesktop = $env:USERPROFILE + \desktop On Tue, Sep 7, 2010 at 3:36 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Guys, What's the most simple and elegant way to trap for the following variable assignment: Eg. $sfDesktop = [Environment]::GetFolderPath(Desktop) Should I assign it like this, and test for a proper value when using (skip otherwise while I cycle through all the ones I need to)? If so, how do you test the value for it having been properly assigned? Sorry, ps noob here. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: Powershell Question
I can't think of a way to EASILY do that without post-processing the input array: $in = gc file.txt $ary = @() for ($i = 0; $i -lt $in.Length; $i += 2) { $ary += $in[$i] } But that isn't very efficient. I'd just process every other line of the input array. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: mck1012 [mailto:mck1...@gmail.com] Sent: Sunday, May 09, 2010 10:48 PM To: NT System Admin Issues Subject: Powershell Question I am trying to read in a text file and putting the odd lines in a array. The text file is a list of names like the example below. So my array would have ServerOne,ServerThree,ServerFive in it. ServerOne ServerTwo ServerThree ServerFour ServerFive ServerSix Thanks for the help ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
Re: Powershell Question
Thanks Michael. That helped out. From: Michael B. Smith mich...@smithcons.com To: NT System Admin Issues ntsysadmin@lyris.sunbelt-software.com Sent: Mon, May 10, 2010 8:17:21 AM Subject: RE: Powershell Question I can’t think of a way to EASILY do that without post-processing the input array: $in = gc file.txt $ary = @() for ($i = 0; $i –lt $in.Length; $i += 2) { $ary += $in[$i] } But that isn’t very efficient. I’d just process every other line of the input array. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From:mck1012 [mailto:mck1...@gmail.com] Sent: Sunday, May 09, 2010 10:48 PM To: NT System Admin Issues Subject: Powershell Question I am trying to read in a text file and putting the odd lines in a array. The text file is a list of names like the example below. So my array would have ServerOne,ServerThree,ServerFive in it. ServerOne ServerTwo ServerThree ServerFour ServerFive ServerSix Thanks for the help ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
I think you may be making this harder than it has to be. Gc the content into an array of [string]. -imatch against SNAPSHOT ID and then +3 from that index is your volume. SO... $lines = gc filename for ($i = 0; $i -lt $lines.Count; $i++) { If ($lines[$i] -imatch ^\* SNAPSHOT ID) { $volline = $lines[$i + 3] ... } } Etc.etc.etc. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 4:48 PM To: NT System Admin Issues Subject: RE: Powershell Question Hey Michael, Here is some of the output of two snapped drives (could be more): * SNAPSHOT ID = {be35a053-2fee-4aa8-aa92-6bd1b2cf5e29} ... - Shadow copy Set: {659a895d-1e31-4ef8-9909-ba8a21a143eb} - Original count of shadow copies = 2 - Original Volume name: \\?\Volume{787bdf7a-ccff-11dd-9866-806e6f6e6963}\file:///\\%3f\Volume%7b787bdf7a-ccff-11dd-9866-806e6f6e6963%7d\ [D:\] - Creation Time: 3/12/2010 2:12:58 PM - Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy13file:///\\%3f\GLOBALROOT\Device\HarddiskVolumeShadowCopy13 - Originating machine: localhost.localdomain - Service machine: localhost.localdomain - Not Exposed - Provider id: {b5946137-7b9f-4925-af80-51abd60b20d5} - Attributes: No_Auto_Release Persistent Differential * SNAPSHOT ID = {e87c8b85-6151-4ba8-bfa1-77b086b28dfc} ... - Shadow copy Set: {659a895d-1e31-4ef8-9909-ba8a21a143eb} - Original count of shadow copies = 2 - Original Volume name: \\?\Volume{787bdf7b-ccff-11dd-9866-806e6f6e6963}\file:///\\%3f\Volume%7b787bdf7b-ccff-11dd-9866-806e6f6e6963%7d\ [E:\] - Creation Time: 3/12/2010 2:12:58 PM - Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy14file:///\\%3f\GLOBALROOT\Device\HarddiskVolumeShadowCopy14 - Originating machine: localhost.localdomain - Service machine: localhost.localdomain - Not Exposed - Provider id: {b5946137-7b9f-4925-af80-51abd60b20d5} - Attributes: No_Auto_Release Persistent Differential I only know what SNAPSHOT ID to reference, and then expose if I grep this for the Volume name +3 lines back. So when I job this, and put its output in a $JobOutput, I want to use $JobOutput for each volume that I expose to a drive letter. That's the part I am unsure how to do. Thanks! jlc From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Friday, March 12, 2010 2:42 PM To: NT System Admin Issues Subject: RE: Powershell Question I'm going to say yes, but I'm still not exactly sure what you are going for there. Look at -match, findstr, and select. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 4:18 PM To: NT System Admin Issues Subject: Powershell Question Hey guys, I am converting a shell script into a ps script and need to parse a variable that holds the output of an executed job. at the cli (using unix tools) I do this: grep -B 3 some_string |grep another_string |cut -f 5 -d So basically, the output has many repetitions that have various fields different, when I find the one I want, I include 3 lines up and filter that 3rd up line to show what I want. Is this possible using built in ps syntax? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
I'm going to say yes, but I'm still not exactly sure what you are going for there. Look at -match, findstr, and select. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 4:18 PM To: NT System Admin Issues Subject: Powershell Question Hey guys, I am converting a shell script into a ps script and need to parse a variable that holds the output of an executed job. at the cli (using unix tools) I do this: grep -B 3 some_string |grep another_string |cut -f 5 -d So basically, the output has many repetitions that have various fields different, when I find the one I want, I include 3 lines up and filter that 3rd up line to show what I want. Is this possible using built in ps syntax? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
I'll go with yes too. ;) -ilike is the other operator I'd look at Thanks, Brian Desmond br...@briandesmond.commailto:br...@briandesmond.com c - 312.731.3132 From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Friday, March 12, 2010 3:42 PM To: NT System Admin Issues Subject: RE: Powershell Question I'm going to say yes, but I'm still not exactly sure what you are going for there. Look at -match, findstr, and select. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 4:18 PM To: NT System Admin Issues Subject: Powershell Question Hey guys, I am converting a shell script into a ps script and need to parse a variable that holds the output of an executed job. at the cli (using unix tools) I do this: grep -B 3 some_string |grep another_string |cut -f 5 -d So basically, the output has many repetitions that have various fields different, when I find the one I want, I include 3 lines up and filter that 3rd up line to show what I want. Is this possible using built in ps syntax? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
Hey Michael, Here is some of the output of two snapped drives (could be more): * SNAPSHOT ID = {be35a053-2fee-4aa8-aa92-6bd1b2cf5e29} ... - Shadow copy Set: {659a895d-1e31-4ef8-9909-ba8a21a143eb} - Original count of shadow copies = 2 - Original Volume name: \\?\Volume{787bdf7a-ccff-11dd-9866-806e6f6e6963}\ [D:\] - Creation Time: 3/12/2010 2:12:58 PM - Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy13 - Originating machine: localhost.localdomain - Service machine: localhost.localdomain - Not Exposed - Provider id: {b5946137-7b9f-4925-af80-51abd60b20d5} - Attributes: No_Auto_Release Persistent Differential * SNAPSHOT ID = {e87c8b85-6151-4ba8-bfa1-77b086b28dfc} ... - Shadow copy Set: {659a895d-1e31-4ef8-9909-ba8a21a143eb} - Original count of shadow copies = 2 - Original Volume name: \\?\Volume{787bdf7b-ccff-11dd-9866-806e6f6e6963}\ [E:\] - Creation Time: 3/12/2010 2:12:58 PM - Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy14 - Originating machine: localhost.localdomain - Service machine: localhost.localdomain - Not Exposed - Provider id: {b5946137-7b9f-4925-af80-51abd60b20d5} - Attributes: No_Auto_Release Persistent Differential I only know what SNAPSHOT ID to reference, and then expose if I grep this for the Volume name +3 lines back. So when I job this, and put its output in a $JobOutput, I want to use $JobOutput for each volume that I expose to a drive letter. That's the part I am unsure how to do. Thanks! jlc From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Friday, March 12, 2010 2:42 PM To: NT System Admin Issues Subject: RE: Powershell Question I'm going to say yes, but I'm still not exactly sure what you are going for there. Look at -match, findstr, and select. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 4:18 PM To: NT System Admin Issues Subject: Powershell Question Hey guys, I am converting a shell script into a ps script and need to parse a variable that holds the output of an executed job. at the cli (using unix tools) I do this: grep -B 3 some_string |grep another_string |cut -f 5 -d So basically, the output has many repetitions that have various fields different, when I find the one I want, I include 3 lines up and filter that 3rd up line to show what I want. Is this possible using built in ps syntax? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
Re: Powershell Question
A nice example of use here: http://www.out-web.net/?p=757 On Fri, Mar 12, 2010 at 1:46 PM, Brian Desmond br...@briandesmond.com wrote: I’ll go with “yes” too. ;) -ilike is the other operator I’d look at Thanks, Brian Desmond br...@briandesmond.com c – 312.731.3132 From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Friday, March 12, 2010 3:42 PM To: NT System Admin Issues Subject: RE: Powershell Question I’m going to say “yes”, but I’m still not exactly sure what you are going for there. Look at “-match”, “findstr”, and “select”. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 4:18 PM To: NT System Admin Issues Subject: Powershell Question Hey guys, I am converting a shell script into a ps script and need to parse a variable that holds the output of an executed job. at the cli (using unix tools) I do this: grep -B 3 some_string |grep another_string |cut -f 5 -d So basically, the output has many repetitions that have various fields different, when I find the one I want, I include 3 lines up and filter that 3rd up line to show what I want. Is this possible using built in ps syntax? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
Re: Powershell Question
so if you search for be35a053-2fee-4aa8-aa92-6bd1b2cf5e29 you want to put $JobOutput = 787bdf7a-ccff-11dd-9866-806e6f6e6963 or $JobOutput = D On Fri, Mar 12, 2010 at 1:47 PM, Joseph L. Casale jcas...@activenetwerx.com wrote: Hey Michael, Here is some of the output of two snapped drives (could be more): * SNAPSHOT ID = {be35a053-2fee-4aa8-aa92-6bd1b2cf5e29} ... - Shadow copy Set: {659a895d-1e31-4ef8-9909-ba8a21a143eb} - Original count of shadow copies = 2 - Original Volume name: \\?\Volume{787bdf7a-ccff-11dd-9866-806e6f6e6963}\ [D:\] - Creation Time: 3/12/2010 2:12:58 PM - Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy13 - Originating machine: localhost.localdomain - Service machine: localhost.localdomain - Not Exposed - Provider id: {b5946137-7b9f-4925-af80-51abd60b20d5} - Attributes: No_Auto_Release Persistent Differential * SNAPSHOT ID = {e87c8b85-6151-4ba8-bfa1-77b086b28dfc} ... - Shadow copy Set: {659a895d-1e31-4ef8-9909-ba8a21a143eb} - Original count of shadow copies = 2 - Original Volume name: \\?\Volume{787bdf7b-ccff-11dd-9866-806e6f6e6963}\ [E:\] - Creation Time: 3/12/2010 2:12:58 PM - Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy14 - Originating machine: localhost.localdomain - Service machine: localhost.localdomain - Not Exposed - Provider id: {b5946137-7b9f-4925-af80-51abd60b20d5} - Attributes: No_Auto_Release Persistent Differential I only know what SNAPSHOT ID to reference, and then expose if I grep this for the Volume name “+3 lines back”. So when I job this, and put its output in a $JobOutput, I want to use $JobOutput for each volume that I expose to a drive letter. That’s the part I am unsure how to do. Thanks! jlc From: Michael B. Smith [mailto:mich...@smithcons.com] Sent: Friday, March 12, 2010 2:42 PM To: NT System Admin Issues Subject: RE: Powershell Question I’m going to say “yes”, but I’m still not exactly sure what you are going for there. Look at “-match”, “findstr”, and “select”. Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 4:18 PM To: NT System Admin Issues Subject: Powershell Question Hey guys, I am converting a shell script into a ps script and need to parse a variable that holds the output of an executed job. at the cli (using unix tools) I do this: grep -B 3 some_string |grep another_string |cut -f 5 -d So basically, the output has many repetitions that have various fields different, when I find the one I want, I include 3 lines up and filter that 3rd up line to show what I want. Is this possible using built in ps syntax? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
so if you search for be35a053-2fee-4aa8-aa92-6bd1b2cf5e29 you want to put $JobOutput = 787bdf7a-ccff-11dd-9866-806e6f6e6963 or $JobOutput = D Neat function in previous email, but I am still not seeing how I do what I need. $JobOutput will contain many blocks all of that format, as an example, I used drives D and E but I refer to by the guid's. This is why I used the -b from grep, while I am parsing through all of this, when I finally hit the drive I am looking for, I can look up three lines and snag the corresponding snapshot id. I guess I have to first find the line number, then go back and re-read it looking at that (number-3). Is that the only way? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
The Select-Object cmdlet is probably what you want. It has -First, -Last, -Skip, -Index, etc which you can use to step in to an array Thanks, Brian Desmond br...@briandesmond.com c - 312.731.3132 -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, March 12, 2010 5:21 PM To: NT System Admin Issues Subject: RE: Powershell Question so if you search for be35a053-2fee-4aa8-aa92-6bd1b2cf5e29 you want to put $JobOutput = 787bdf7a-ccff-11dd-9866-806e6f6e6963 or $JobOutput = D Neat function in previous email, but I am still not seeing how I do what I need. $JobOutput will contain many blocks all of that format, as an example, I used drives D and E but I refer to by the guid's. This is why I used the -b from grep, while I am parsing through all of this, when I finally hit the drive I am looking for, I can look up three lines and snag the corresponding snapshot id. I guess I have to first find the line number, then go back and re-read it looking at that (number-3). Is that the only way? Thanks, jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
The Select-Object cmdlet is probably what you want. It has -First, -Last, -Skip, -Index, etc which you can use to step in to an array Cool, Is there any way to clean this up, I get an error when I consecutively pipe the $SnapOutput_Log and $GUID_Log lines together? $SnapOutput = start-job { vshadow `-wi=`{76fe1ac4-15f7-4bcd-987e-8e1acb462fb7`} -p D: E: } Wait-Job $SnapOutput $SnapOutput_Log = Receive-Job $SnapOutput -Keep |Select-String -SimpleMatch $VolID_Log -Context 4,0 $GUID_Log = ([regex]::Matches($SnapOutput_Log, SNAPSHOT.*\{(.*)\}.*) | %{$_.Groups[1].value}) Write-Host $GUID_Log Obviously I am missing something here, this errors out: $GUID_Log = Receive-Job $SnapOutput -Keep |Select-String -SimpleMatch $VolID_Log -Context 4,0 |([regex]::Matches($_, SNAPSHOT.*\{(.*)\}.*) | %{$_.Groups[1].value}) Thanks guys! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
is there a particular reason you want to use II? And I'm not completely clear about your quoting requirements, but I'd do something like this: $arrayPaths = Dir/1, Dir/2, Dir/3 -- don't need the initializer since you have the comma operator $options = '--verbose --recursive --blah --chmod=D=rwx,F=rw' foreach ($path in $arrayPaths) { $source = /cygdrive/c/Top Level/$path $dest = 10.0.0.13::test + '' + /Top Level/$path + '' cmd.exe /c c:\Program Files\cwRsync\rsync.exe $options $source $dest } Using cmd /c has the distinct advantage of properly setting $LastExitCode for error checking, which II often does not. -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Thursday, January 14, 2010 3:45 PM To: NT System Admin Issues Subject: Powershell Question Guys, I have a backup script to have ready for implementation on Saturday morning. It uses rsync to copy on diffs to a remote Linux server over a vpn through a slow link. I finally finished all the server and vpn setup and I had been avoiding how to handle the huge dataset, which would make a simple dos script of rsyncing the whole tree at once nearly impossible. What I plan to do is iterate over a few known paths (and possibly add in some error handling later). Does this make sense (highly abbreviated): $arrayPaths = @(Dir 1/, Dir 2/, Dir 3/) $Options = '--verbose --recursive --blah --chmod=D=rwx,F=rw' foreach ($i in $arrayPaths) {Invoke-Item C:\Program Files\cwRsync\rsync.exe $Options `/cygdrive/c/Top Level/$i` 10.0.0.13::test`/Top Level/$i`} So what's the most elegant way to make the ii command run this mess? Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
is there a particular reason you want to use II? And I'm not completely clear about your quoting requirements, but I'd do something like this: Nope, I actually don't know any better:) cmd.exe /c c:\Program Files\cwRsync\rsync.exe $options $source $dest Having an issue with this, so I amended it to a local machine and test data: $arrayPaths = administrator/, administrator.WXP000/, All Users/ $Options = '--verbose --recursive --times --partial --progress --compress --human-readable --del --ignore-errors --force --bwlimit=0 --timeout=300 --chmod=D=rwx,F=rw' foreach ($path in $arrayPaths) { $source = /cygdrive/c/Documents and Settings/$path $dest = 192.168.0.10::test + '' + /Documents and Settings/$path + '' cmd.exe /c start /wait c:\Program Files\cwRsync\rsync.exe $options $source $dest } I get a windows error: The system cannot find the file /cygdrive/c/Documents and Settings/administrator/ 192.168.0.13::test/Documents. ... Any idea? Thanks Michael! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
This would be why I said I wasn't clear on your quoting requirements. :-) I know the whole Cygwin thing combined with PowerShell combined with cmd.exe can be a littlestrange. This seems to work, on my system. $arrayPaths = administrator/, administrator.WXP000/, All Users/ $Options = --verbose --recursive --times --partial --progress --compress --human-readable --del --ignore-errors --force --bwlimit=0 --timeout=300 --chmod=D=rwx,F=rw foreach ($path in $arrayPaths) { $source = '' + /cygdrive/c/Documents and Settings/$path + '' $dest = '' + 192.168.0.10::test + /Documents and Settings/$path + '' $prog = rsync.exe pushd c:\program files\cwrsync $param = $options + + $source + + $dest cmd.exe /c $prog $param cmd.exe /c $prog $param popd } -Original Message- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Thursday, January 14, 2010 4:21 PM To: NT System Admin Issues Subject: RE: Powershell Question is there a particular reason you want to use II? And I'm not completely clear about your quoting requirements, but I'd do something like this: Nope, I actually don't know any better:) cmd.exe /c c:\Program Files\cwRsync\rsync.exe $options $source $dest Having an issue with this, so I amended it to a local machine and test data: $arrayPaths = administrator/, administrator.WXP000/, All Users/ $Options = '--verbose --recursive --times --partial --progress --compress --human-readable --del --ignore-errors --force --bwlimit=0 --timeout=300 --chmod=D=rwx,F=rw' foreach ($path in $arrayPaths) { $source = /cygdrive/c/Documents and Settings/$path $dest = 192.168.0.10::test + '' + /Documents and Settings/$path + '' cmd.exe /c start /wait c:\Program Files\cwRsync\rsync.exe $options $source $dest } I get a windows error: The system cannot find the file /cygdrive/c/Documents and Settings/administrator/ 192.168.0.13::test/Documents. ... Any idea? Thanks Michael! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
This would be why I said I wasn't clear on your quoting requirements. :-) I know the whole Cygwin thing combined with PowerShell combined with cmd.exe can be a littlestrange. This seems to work, on my system. The amount of beer debt I amassing in your favor is getting to be rather large:) Thanks Michael! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
RE: Powershell Question
This is a good start, and provides links http://technet.microsoft.com/en-us/magazine/2007.11.powershell.aspx Here is a link to the definitive reference: http://msdn.microsoft.com/en-us/library/hs600312.aspx Regards, Michael B. Smith, MCITP:SA,EMA/MCSE/Exchange MVP My blog: http://TheEssentialExchange.com/blogs/michael I'll be at TEC'2009! http://www.tec2009.com/vegas/index.php From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, January 06, 2009 12:13 PM To: NT System Admin Issues Subject: Powershell Question Anyone know a good resource for powershell regexp's, I am trying to replicate the following regexp ^[[:space:]]+word|^[[:space:]]+[0-9] so I can clean up a log file for viewing. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~
Re: Powershell Question
Also, while I don't use regex much, the few times I have Regex Buddy was invaluable. http://www.regexbuddy.com/ And Micheal beat me to the link I use whenever I need a refresher. (ok, the link I read when I have to use regex) Brandon is evidently going to post more on the subject so you may want to follow his blog for future reading. http://thepowershellguy.com/blogs/posh/archive/2008/12/29/regular-expressions-and-powershell-part-1.aspx http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2008/12/28/regular-expression-webcast-series.aspx Steven On Tue, Jan 6, 2009 at 9:30 AM, Michael B. Smith mich...@theessentialexchange.com wrote: This is a good start, and provides links http://technet.microsoft.com/en-us/magazine/2007.11.powershell.aspx Here is a link to the definitive reference: http://msdn.microsoft.com/en-us/library/hs600312.aspx Regards, Michael B. Smith, MCITP:SA,EMA/MCSE/Exchange MVP My blog: http://TheEssentialExchange.com/blogs/michael I'll be at TEC'2009! http://www.tec2009.com/vegas/index.php From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Tuesday, January 06, 2009 12:13 PM To: NT System Admin Issues Subject: Powershell Question Anyone know a good resource for powershell regexp's, I am trying to replicate the following regexp ^[[:space:]]+word|^[[:space:]]+[0-9] so I can clean up a log file for viewing. Thanks! jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~