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

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
PuTTY riot
Nov 16, 2002
One of the steps in our server build guide is to enable auditing for the C:\ drive. I'd like to script this out but I can't for the life of me find any relevant resources. Oh and while I'm asking, when doing this manually we tend to see a lot of access denied errors on subfulders, anyone know what that's about?

quote:

h) Enable Auditing for System Drive
i) Right-Click on System Drive, Select Properties
ii) Select Security Tab, Click Advanced
iii) Select Auditing Tab, Click Add
iv) Click Select Principal, Enter “Everyone”
v) Type: Fail
vi) Click Show Advanced Permissions
vii) Select All Check Boxes Except “Delete Subfolders and Files”

Adbot
ADBOT LOVES YOU

brosmike
Jun 26, 2009
http://blogs.technet.com/b/bulentoz...ll-scripti.aspx

PuTTY riot
Nov 16, 2002

thank you thank you thank you. I modified it to suit my needs... here's what I came up with to make it match the above screenshot in case anyone else sees this.

code:
$computer = gc env:computername
$path = "C:\New Folder"
$user = "everyone"
$path = $path.replace("\", "\\")
$SD = ([WMIClass] "Win32_SecurityDescriptor").CreateInstance()
$ace = ([WMIClass] "Win32_ace").CreateInstance()
$Trustee = ([WMIClass] "Win32_Trustee").CreateInstance()
$SID = (new-object security.principal.ntaccount $user).translate([security.principal.securityidentifier])
[byte[]] $SIDArray = ,0 * $SID.BinaryLength
$SID.GetBinaryForm($SIDArray,0)
$Trustee.Name = $user
$Trustee.SID = $SIDArray
$ace.AccessMask = [System.Security.AccessControl.FileSystemRights]"Modify,ChangePermissions,TakeOwnership"
$ace.AceFlags = 131
$ace.AceType = 2
$ace.Trustee = $trustee
$SD.SACL = $ace
$SD.ControlFlags="0x10"
$wPrivilege = gwmi Win32_LogicalFileSecuritySetting -computername $computer -filter "path='$path'"
$wPrivilege.psbase.Scope.Options.EnablePrivileges = $true
$wPrivilege.setsecuritydescriptor($SD)

Virigoth
Apr 28, 2009

Corona rules everything around me
C.R.E.A.M. get the virus
In the ICU y'all......



When you use invoke-command to drop a script block on a remote Hyper-V server with credential variables. Does PS leave anything on the remote computer by way of a temp file, memory blocks, etc or does it clean up after itself as it finishes up the command?

Scenario:

We're using invoke-command to automate deployment of servers that need specific credentials for setup, we send over the script, do all the goodies, and it ends.

Nothing should be left behind from that script hopefully.

AreWeDrunkYet
Jul 8, 2006

I'm not having any luck googling this, does anyone know how to use a substring in a get-adcomputer filter? So, for example, let's say a naming convention is STATECITY00006, and I want all of the computers in Utah, I would assume the command would be

code:
get-adcomputer -filter {name.substring(0,4) -eq "UTAH"}
Doing this returns

code:
Error parsing query ... 'Operator not supported' at position
where it is trying to use the substring function, so it appears that is not supported. Is this a syntax error on my end, or is there some sort of workaround to use substrings in these queries?

wwb
Aug 17, 2004

So they aliased wget in powershell 3. Any idea why it is horribly slow compared to any other http download client? Sub 100mb speeds on a gigabit network with nothing happening slow FWIW.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

AreWeDrunkYet posted:

I'm not having any luck googling this, does anyone know how to use a substring in a get-adcomputer filter? So, for example, let's say a naming convention is STATECITY00006, and I want all of the computers in Utah, I would assume the command would be

code:
get-adcomputer -filter {name.substring(0,4) -eq "UTAH"}
Doing this returns

code:
Error parsing query ... 'Operator not supported' at position
where it is trying to use the substring function, so it appears that is not supported. Is this a syntax error on my end, or is there some sort of workaround to use substrings in these queries?

code:
get-adcomputer -filter {name -like "UTAH*"}
?

AreWeDrunkYet
Jul 8, 2006

Jethro posted:

code:
get-adcomputer -filter {name -like "UTAH*"}
?

Unfortunately, it has to be in the exact position I am looking for it (and not always at the beginning or end of the string).

So, to run with the existing example, XXUTAHXXXX would be a match but I would not want to return XXXUTAHXXX. It appears the only wildcard -like accepts is *, and

code:
name -like "*UTAH*"
would return both computers.

I was able to work around it, but my solution is pretty inefficient. A solution that would let me use the filter in get-adcomputer would probably run much faster.

code:
(not exactly, but the general gist is:)

$list = get-adcomputer -filter *

foreach ($computer in $list){
if ($computer.name.substring(#,#) -eq "WHATEVER"){
[code to add computer to table] 
}}

$table | export-csv

The Gripper
Sep 14, 2004
i am winner
I don't know if this has better performance, but you can pipe to a filter:
code:
Get-ADComputer -filter * | ?{$_.name.substring(0,4) -eq "UTAH"}

EAT THE EGGS RICOLA
May 29, 2008

You can also just use regular expressions.

The Gripper
Sep 14, 2004
i am winner
It'd be nice if -filter on most of the AD cmdlets was better, I think it's just a basic wrapper for LDAP query stuff so it's fairly limited.

12 rats tied together
Sep 7, 2006

AreWeDrunkYet posted:

Unfortunately, it has to be in the exact position I am looking for it (and not always at the beginning or end of the string).

So, to run with the existing example, XXUTAHXXXX would be a match but I would not want to return XXXUTAHXXX. It appears the only wildcard -like accepts is *, and
Yeah you can probably do this with a regex. \w\wUTAH would (probably) match a case for any two letters followed by UTAH. I've found this page pretty helpful in the past, and (depending on the pattern) it can be as specific as you want to be.

If you don't want to bother with regex (you probably should, though), I would suggest that you should use the filter on Get-ADComputer to get a broad list of stuff that probably contains what you want, instead of using * to get absolutely everything. Then your foreach loop will (probably) run a lot faster, because it'll only be parsing through anything that contains utah instead of everything else, too.

Something I found out recently too was that if (like me) your company's AD is poo poo and full of stuff that doesn't even exist anymore, you can pipe Get-ADComputer into Test-Connection -quiet -count 1 to get only computers that you can actually ping (which it will try once instead of the default four times).

And a quick question I have: I'm doing the powershell software inventory thing myself as busy work. My script works, and it returns things that I personally can count and say "We have X installations of Product", but it returns poo poo like "Adobe Soundbooth" "Adobe Soundbooth Codecs" "Adobe Soundbooth Scores" "Adobe Soundbooth other bullshit". Is there any easy way that I just can't think of to only grab the installation for a real product, instead of all the dumb poo poo that comes with it? This is particularly frustrating for things like Microsoft SQL Server which, by itself, returns about 180 different versions of different plugins/tools/etc for Microsoft SQL Server.

e: The only thing I've come up with so far is "use the one with the biggest count and, given a tie, the one with the shortest name", but even that isn't particularly graceful.

12 rats tied together fucked around with this message at 22:06 on Mar 1, 2014

Deranged Milkman
Jan 8, 2012
I have used powershell before for simple scripts and have a decent grasps of the concepts but what I thought would be a relatively easy script is turning into a real pain.

What I'm trying to do: Create a script that moves files that have been modified in a date range to a new location. Some of the folders in the main folder have many levels of nested subfolders beneath it. Preferably it would keep the same folder structure but this is not required. The files total up to a couple TB so it has to be a move, copying will take hours to process.

Here is what I currently have:
code:
$source = "C:\Source"
$dest = "C:\Destination"
 
Get-childItem -Path $source -Recurse |
    where-object {$_.LastWriteTime -lt ("03/13/2014") -and $_.LastWriteTime -gt ("01/13/2014")}|
    move-item -destination $dest -force
This only works for the folders directly under the root, it doesn't go below that. I.E. if there is a file in Root ->Subfolder ->2ndSubfolder with a modify date outside that range it will still copy it since SubFolder meets the criteria.

I tried running "robocopy $source $dest /e /xf *.*" beforehand to recreate the folder structure but then the move-item errors because the folders already exist.

Is there a way to accomplish this?

CLAM DOWN
Feb 13, 2007




Deranged Milkman posted:

I have used powershell before for simple scripts and have a decent grasps of the concepts but what I thought would be a relatively easy script is turning into a real pain.

What I'm trying to do: Create a script that moves files that have been modified in a date range to a new location. Some of the folders in the main folder have many levels of nested subfolders beneath it. Preferably it would keep the same folder structure but this is not required. The files total up to a couple TB so it has to be a move, copying will take hours to process.

Here is what I currently have:
code:
$source = "C:\Source"
$dest = "C:\Destination"
 
Get-childItem -Path $source -Recurse |
    where-object {$_.LastWriteTime -lt ("03/13/2014") -and $_.LastWriteTime -gt ("01/13/2014")}|
    move-item -destination $dest -force
This only works for the folders directly under the root, it doesn't go below that. I.E. if there is a file in Root ->Subfolder ->2ndSubfolder with a modify date outside that range it will still copy it since SubFolder meets the criteria.

I tried running "robocopy $source $dest /e /xf *.*" beforehand to recreate the folder structure but then the move-item errors because the folders already exist.

Is there a way to accomplish this?

I had a problem with this once on PS 2.0, Move-Item seems to not be able to overwrite existing folders. Instead, I did Copy-Item, then ran Remove-Item on the source once I copied. Same result, dumb workaround way of doing it because I did have that same behaviour. Haven't retried these methods on PS 3 or 4.

AreWeDrunkYet
Jul 8, 2006

Reiz posted:

And a quick question I have: I'm doing the powershell software inventory thing myself as busy work. My script works, and it returns things that I personally can count and say "We have X installations of Product", but it returns poo poo like "Adobe Soundbooth" "Adobe Soundbooth Codecs" "Adobe Soundbooth Scores" "Adobe Soundbooth other bullshit". Is there any easy way that I just can't think of to only grab the installation for a real product, instead of all the dumb poo poo that comes with it? This is particularly frustrating for things like Microsoft SQL Server which, by itself, returns about 180 different versions of different plugins/tools/etc for Microsoft SQL Server.

e: The only thing I've come up with so far is "use the one with the biggest count and, given a tie, the one with the shortest name", but even that isn't particularly graceful.

The only reliable workaround I've found is maintaining a master list of software we might be looking for, and matching those strings against the report from what's installed on the workstation. Even filtering out everything that's an update or a duplicate will leave you with a very bloated list.

Deranged Milkman
Jan 8, 2012

CLAM DOWN posted:

I had a problem with this once on PS 2.0, Move-Item seems to not be able to overwrite existing folders. Instead, I did Copy-Item, then ran Remove-Item on the source once I copied. Same result, dumb workaround way of doing it because I did have that same behaviour. Haven't retried these methods on PS 3 or 4.

This would take a few hours to process due to the files size but if I can't find anything else that might be an option. My other problem is it checking the modify date on the folders and not the files within it. Is there a way to have it look at the contents and not the modify date on the folder?

RICHUNCLEPENNYBAGS
Dec 21, 2010

Reiz posted:

Yeah you can probably do this with a regex. \w\wUTAH would (probably) match a case for any two letters followed by UTAH. I've found this page pretty helpful in the past, and (depending on the pattern) it can be as specific as you want to be.

If you don't want to bother with regex (you probably should, though), I would suggest that you should use the filter on Get-ADComputer to get a broad list of stuff that probably contains what you want, instead of using * to get absolutely everything. Then your foreach loop will (probably) run a lot faster, because it'll only be parsing through anything that contains utah instead of everything else, too.

Something I found out recently too was that if (like me) your company's AD is poo poo and full of stuff that doesn't even exist anymore, you can pipe Get-ADComputer into Test-Connection -quiet -count 1 to get only computers that you can actually ping (which it will try once instead of the default four times).

And a quick question I have: I'm doing the powershell software inventory thing myself as busy work. My script works, and it returns things that I personally can count and say "We have X installations of Product", but it returns poo poo like "Adobe Soundbooth" "Adobe Soundbooth Codecs" "Adobe Soundbooth Scores" "Adobe Soundbooth other bullshit". Is there any easy way that I just can't think of to only grab the installation for a real product, instead of all the dumb poo poo that comes with it? This is particularly frustrating for things like Microsoft SQL Server which, by itself, returns about 180 different versions of different plugins/tools/etc for Microsoft SQL Server.

e: The only thing I've come up with so far is "use the one with the biggest count and, given a tie, the one with the shortest name", but even that isn't particularly graceful.

I think \w{2} is a little clearer than \w\w although they're semantically equivalent. You can try regexpal.com for some help interactively composing regexes, by the way.

CLAM DOWN
Feb 13, 2007




Deranged Milkman posted:

This would take a few hours to process due to the files size but if I can't find anything else that might be an option. My other problem is it checking the modify date on the folders and not the files within it. Is there a way to have it look at the contents and not the modify date on the folder?

Yeah I get that it would take a while, but I think it's a lovely limitation of move-item and you might not have a choice.

As for your other thing, I honestly would just use robocopy at this point.

SniperWoreConverse
Mar 20, 2010



Gun Saliva
Hey, so I'm not sure if anything like this has been asked in the thread, but does anyone know how to interact with USB devices via powershell?

I have a human interface device, and according to some basic googling, I was able to get a list of all the attached devices. I know what one I want to deal with, but I don't know how to do anything with it. Shouldn't I be able to query the device itself somehow? Get methods or something?

The things I've been able to find are more along the lines of "List all the attached USB devices" or "Enable or Disable attached devices, just like Device Manager." I'd like to try and open the device and actually do stuff with it.

wwb
Aug 17, 2004

One note on finding __UTAH____ -- you can pass a function to a filter -- see http://stackoverflow.com/questions/15536611/how-to-pass-custom-filter-function-to-where-object for an example. So you don't need a 2 stage filter.

Personally I would skip the regex here but that is probably because I hate regexes.

kiwid
Sep 30, 2013

Is there anyway to send a foreach format-list to a csv with each property as a new column?

For example, I want to run this:

code:
$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox | Select-Object name
foreach ($r in $rooms) {
    Get-CalendarProcessing -Identity "$($r.name)" | fl >> C:\rooms.txt
}
It outputs a bunch of entries like this:

pre:
RunspaceId                          : [redacted]
AutomateProcessing                  : AutoAccept
AllowConflicts                      : False
BookingWindowInDays                 : 180
MaximumDurationInMinutes            : 43200
AllowRecurringMeetings              : True
EnforceSchedulingHorizon            : True
ScheduleOnlyDuringWorkHours         : False
ConflictPercentageAllowed           : 0
MaximumConflictInstances            : 0
ForwardRequestsToDelegates          : True
DeleteAttachments                   : True
DeleteComments                      : False
RemovePrivateProperty               : True
DeleteSubject                       : False
AddOrganizerToSubject               : True
DeleteNonCalendarItems              : True
TentativePendingApproval            : True
EnableResponseDetails               : True
OrganizerInfo                       : True
ResourceDelegates                   : {}
RequestOutOfPolicy                  : {}
AllRequestOutOfPolicy               : False
BookInPolicy                        : {}
AllBookInPolicy                     : True
RequestInPolicy                     : {}
AllRequestInPolicy                  : False
AddAdditionalResponse               : False
AdditionalResponse                  :
RemoveOldMeetingMessages            : True
AddNewRequestsTentatively           : True
ProcessExternalMeetingMessages      : False
RemoveForwardedMeetingNotifications : False
MailboxOwnerId                      : [redacted]
Identity                            : [redacted]
IsValid                             : True
ObjectState                         : Changed
Is there any way to get each one of the rooms as a new row in a csv with each of the above properties as a column?

edit: Never mind, I think I got it working with this:

code:
Get-Mailbox -RecipientTypeDetails RoomMailbox | Get-CalendarProcessing | Export-Csv C:\export.csv
However, is there anyway to combine these two commands into one?

code:
Get-Mailbox -RecipientTypeDetails RoomMailbox | Get-CalendarProcessing | Export-Csv C:\export.csv
Get-Mailbox -RecipientTypeDetails EquipmentMailbox | Get-CalendarProcessing | Export-Csv C:\export2.csv
edit 2:

Figured it out:
code:
Get-Mailbox | Where {$_.RecipientTypeDetails -eq "RoomMailbox"
	-or $_.RecipientTypeDetails -eq "EquipmentMailbox"} | Get-CalendarProcessing | Export-Csv C:\export.csv

kiwid fucked around with this message at 16:51 on Apr 4, 2014

AreWeDrunkYet
Jul 8, 2006

wwb posted:

One note on finding __UTAH____ -- you can pass a function to a filter -- see http://stackoverflow.com/questions/15536611/how-to-pass-custom-filter-function-to-where-object for an example. So you don't need a 2 stage filter.

Thanks, just ended up just dropping the filter and instead dealing with the strings once the list of computers was a PowerShell object. It takes a little while longer to run, but not unreasonably so considering I am trying identify a couple thousand objects from a list of 50k+.

Mr. Clark2
Sep 17, 2003

Rocco sez: Oh man, what a bummer. Woof.

On my home PC (windows 8 pro), I've got a powershell script which runs every day and I need it to email me the results of the run. How can I accomplish this? I know that I can use the Send-MailMessage cmdlet to do the sending but I'm stumped as to what to use as the smtp server since I dont have one on my home network. Is there some way that I can use gmail's smtp servers to do this? Is there some other easy way? Thanks.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Mr. Clark2 posted:

On my home PC (windows 8 pro), I've got a powershell script which runs every day and I need it to email me the results of the run. How can I accomplish this? I know that I can use the Send-MailMessage cmdlet to do the sending but I'm stumped as to what to use as the smtp server since I dont have one on my home network. Is there some way that I can use gmail's smtp servers to do this? Is there some other easy way? Thanks.

Seriously?

http://lmgtfy.com/?q=gmail+smtp&l=1

Mr. Clark2
Sep 17, 2003

Rocco sez: Oh man, what a bummer. Woof.


Thanks but I'm really asking more about how to pass along my gmail address/credentials to the send-mailmessage, I'm well aware of the actual smtp settings ;)
I did find this: http://www.powershellmagazine.com/2012/10/25/pstip-sending-emails-using-your-gmail-account/ but it still prompts the user to enter the password so wont work for what I'm trying to do.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Mr. Clark2 posted:

Thanks but I'm really asking more about how to pass along my gmail address/credentials to the send-mailmessage, I'm well aware of the actual smtp settings ;)
I did find this: http://www.powershellmagazine.com/2012/10/25/pstip-sending-emails-using-your-gmail-account/ but it still prompts the user to enter the password so wont work for what I'm trying to do.

Did you try any of the solutions from this SO thread?

Basically, use System.Net.Mail.SMTPClient instead.

Mr Shiny Pants
Nov 12, 2012
I have a quick question about Invoke-RestMethod. I tried to use this to post some multipart/formdata to my application in the following way:

code:
Invoke-RestMethod -Method Post -InFile "C:\tools\report.pdf" -Uri ($url + "report.pdf") -ContentType "multipart/form-data"
The problem is that the CMD-let does not include a boundary in the inputstream making it an invalid multipart/form-data and so my application can't figure what the file is in the request.

Anyone know if i am doing something wrong? Curl works fine because it creates a valid request.

Mr. Clark2
Sep 17, 2003

Rocco sez: Oh man, what a bummer. Woof.

Ithaqua posted:

Did you try any of the solutions from this SO thread?

Basically, use System.Net.Mail.SMTPClient instead.

Thanks, thats what I ended up doing.

Mr Shiny Pants
Nov 12, 2012

Mr Shiny Pants posted:

I have a quick question about Invoke-RestMethod. I tried to use this to post some multipart/formdata to my application in the following way:

code:
Invoke-RestMethod -Method Post -InFile "C:\tools\report.pdf" -Uri ($url + "report.pdf") -ContentType "multipart/form-data"
The problem is that the CMD-let does not include a boundary in the inputstream making it an invalid multipart/form-data and so my application can't figure what the file is in the request.

Anyone know if i am doing something wrong? Curl works fine because it creates a valid request.

To answer my own question. It seems that creating the form to post multipart data is left to the user. :( Creating form data is a PITA.

kiwid
Sep 30, 2013

So, we've recently changed our policy for our help desk to start filling in all the fields in an Active Directory user that we never really cared about before, such as organization information, addresses, phone numbers, etc. We've also moved to Office 365 which requires manually editing the proxyAddresses attribute for alias email addresses. They aren't very consistent with filling this information out and often forget to connect home drives and poo poo. I want to create a dummy proof PowerShell script that goes through the process of creating a new user but my experience with PowerShell is running one off commands. If you guys had to choose one book (maybe two), to learn PowerShell (especially syntax), what would it be?

Virigoth
Apr 28, 2009

Corona rules everything around me
C.R.E.A.M. get the virus
In the ICU y'all......



Is there a WMI equivalent to this code block:
code:
get-dnsclient | ? {._InterfaceAlias -like "YourMom""} | Set-DnsClient RegisterThisConnectionsAddress:$false
This works great on 2012 machines, but I'm setting up a script to deploy 128 2K8 enterprise machines that are Powershell 2 and am looking to script that out as well and that cmdlet isn't part of Powershell 2.

the littlest prince
Sep 23, 2006


I've got this one-off powershell script that 1) changes the proxy settings, 2) downloads a file, and 3) puts the proxy settings back. Steps 1 and 2 go just fine, but step 3 never works.

Powershell is not really my forte, so I'm probably doing something really dumb.

code:
$regKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$proxyEnabled = $true
$proxyServer = $null
$proxyServerToDefine = "<my_proxy_url>:80"
$autoConfigUrl = $null

Function GetInternetSettings
{
  $proxyServer   = Get-ItemProperty -path $regKey -name ProxyServer   -ErrorAction SilentlyContinue
  $autoConfigUrl = Get-ItemProperty -path $regKey -name AutoConfigURL -ErrorAction SilentlyContinue
  $proxyEnabled  = Get-ItemProperty -path $regKey -name ProxyEnable   -ErrorAction SilentlyContinue
  
  Set-ItemProperty -path $regKey -name ProxyEnable -value 1
  Set-ItemProperty -path $regKey -name ProxyServer -value $proxyServerToDefine
  #Set-ItemProperty -path $regKey -name AutoConfigURL -value ""
  if ($TEST)
  {
    "current proxy server: $proxyServer"
    "current autoproxy: $autoConfigUrl"
    "Proxy was enabled? $proxyEnabled"
  }
}

Function RestoreInternetSettings
{
  Set-ItemProperty -path $regKey -name ProxyEnable   -value $proxyEnabled
  # this doesn't work?
  Set-ItemProperty -path $regKey -name ProxyServer   -value $proxyServer
  Set-ItemProperty -path $regKey -name AutoConfigURL -value $autoConfigUrl
  
  if ($TEST)
  {
    $a = Get-ItemProperty -path $regKey -name ProxyEnable   -ErrorAction SilentlyContinue
    "Proxy is now enabled? $proxyEnabled"
    $a = Get-ItemProperty -path $regKey -name ProxyServer   -ErrorAction SilentlyContinue
    "printing proxy server: $a"
    $a = Get-ItemProperty -path $regKey -name AutoConfigURL -ErrorAction SilentlyContinue
    "printing autoconfig script: $a"
  }
}

the littlest prince
Sep 23, 2006


And of course, soon after I post that, I realize that it's a scope issue. Problem solved.

CLAM DOWN
Feb 13, 2007




Virigoth posted:

Is there a WMI equivalent to this code block:
code:
get-dnsclient | ? {._InterfaceAlias -like "YourMom""} | Set-DnsClient RegisterThisConnectionsAddress:$false
This works great on 2012 machines, but I'm setting up a script to deploy 128 2K8 enterprise machines that are Powershell 2 and am looking to script that out as well and that cmdlet isn't part of Powershell 2.

Just fooling around with this myself now, if you go:

code:
Get-WmiObject Win32_NetworkAdapterConfiguration | where { $_.index -eq "1" } | format-list *
(sub in index number or description of specific adapter)

You can see a property called "FullDNSRegistrationEnabled". If you set that to false, it should have the same effect as your above DNS cmdlets for v3+.

Clanpot Shake
Aug 10, 2006
shake shake!

I'm writing a pre-commit git hook in powershell that checks the syntax of Ruby files. The command I'd like to run is:
code:
  ($file is loop variable)
$erb = "C:\opscode\chef\embedded\bin\erb.bat -P -x -T '-'"
$ruby_exe = "C:\opscode\chef\embedded\bin\ruby.exe"
& $erb $file | $ruby_exe -c
I get this error:

quote:

The term 'C:\opscode\chef\embedded\bin\erb.bat -P -x -T '-' <file path> | C:\opscode\chef\embedded\bin\ruby.exe -c' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I'm clearly not doing this right. How do I run a command and pipe the output to another command?

SniperWoreConverse
Mar 20, 2010



Gun Saliva
Try dropping the quotes, that way your variables will be the files you want instead of a string that happens to be the path to the file. (I think, dunno about the -P -x -T stuff)

e:
code:
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS C:\> .\b.bat

C:\>echo butts
butts
PS C:\> C:\b.bat

C:\>echo butts
butts
PS C:\> $b = ".\b.bat"
PS C:\> $b
.\b.bat
PS C:\> $b = .\b.bat
PS C:\> $b

C:\>echo butts
butts

SniperWoreConverse fucked around with this message at 19:06 on Apr 15, 2014

Virigoth
Apr 28, 2009

Corona rules everything around me
C.R.E.A.M. get the virus
In the ICU y'all......



Thanks CLAM DOWN, that was what I was looking for, getting ready to try and implement it in now.

Clanpot Shake
Aug 10, 2006
shake shake!

SniperWoreConverse posted:

Try dropping the quotes, that way your variables will be the files you want instead of a string that happens to be the path to the file. (I think, dunno about the -P -x -T stuff)

e:
code:
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS C:\> .\b.bat

C:\>echo butts
butts
PS C:\> C:\b.bat

C:\>echo butts
butts
PS C:\> $b = ".\b.bat"
PS C:\> $b
.\b.bat
PS C:\> $b = .\b.bat
PS C:\> $b

C:\>echo butts
butts
$erb = C:\opscode\chef\embedded\bin\erb.bat -P -x

C:\chef-repo>powershell.exe -ExecutionPolicy RemoteSigned -File .git\hooks\pre-commit-hook.ps1
You must provide a value expression on the right-hand side of the '-' operator.
At C:\chef-repo\.git\hooks\pre-commit-hook.ps1:58 char:48
+ $errors = & $erb $file | $php_bin - <<<< c $file
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : ExpectedValueExpression

SniperWoreConverse
Mar 20, 2010



Gun Saliva
drat, getting out of depth for me... maybe you need --%? I think it's just getting parsed wrong I don't know.
When you figure it out post what the deal is, this is interesting to me.

Adbot
ADBOT LOVES YOU

Clanpot Shake
Aug 10, 2006
shake shake!

I changed it to
code:
$errors = & C:\opscode\chef\embedded\bin\erb.bat -P -x $file | C:\opscode\chef\embedded\bin\ruby.exe -c
and it works. I don't fully understand it, but playing around with it told me it wasn't necessarily the -c it had a problem with.

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