get-childitem -recurse -name | where {$_.attributes -match "*-0"}
Network_phone\SECVIDEO-01-0
Network_phone\WEBCOMMDEV02-0
Odp\ODPDEVCPRD01-0
Odp\ODPDEVETLRD01-0
The output returns both the both the folder (Key) and the sub-folder. This
sub-folder contains the server name along with an appended -0.
I would like the output to contain just the actual computer name.
SECVIDEO01
WEBCOMMDEV02
ODPDEVCPRD01
ODPDEVETLRD01
Are there any commands I can execute to help strip this out simply? I know
how I would do it with vbscript but I need to move on and start using
Powershell.
--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009
Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.
For your example data set, that means something like this:
get-childitem -recurse -name | where {$_.attributes -match "*-0"} | %{
[Void]($_ -Match "(?<=\\).+(?=-)")
If ($Matches) { $Matches[0] } else { $_ }
}
Double \ to escape the RegEx meaning of \. And [Void] to drop the True /
False it would normally return from Match.
Chris
I'm sure there will be many other, probably far superior ways, but how
about:-
# Start
$comps = gc comps.txt
[array]$comps2 += $comps | foreach { $([regex]::match($_,"(?<=\\).+(?
=-0)").value) }
$comps2 = $comps2 | foreach { $_ -replace "-" }
$comps2
# End
In that example I'm reading
Network_phone\SECVIDEO-01-0
Network_phone\WEBCOMMDEV02-0
Odp\ODPDEVCPRD01-0
Odp\ODPDEVETLRD01-0
in from a file and sticking them into the $comps array.
The fixed computer names go into $comps2 and I get back:-
SECVIDEO01
WEBCOMMDEV02
ODPDEVCPRD01
ODPDEVETLRD01
Hope it helps,
Stuart
$HKLM = 2147483650
$RemoteComputer = "remoteServer"
$RegObject = Get-WmiObject -List -Namespace root\default -ComputerName
$RemoteComputer | Where-Object {$_.Name -eq "StdRegProv"}
$RegPath =
"Software\trendmicro\serverprotect\currentversion\informationserver\"
$RegKeys = $RegObject.EnumKey($HKLM, $RegPath)
$RegKeys|foreach {
$NewPath = $RegPath + $_.sNames
write-output $NewPath }
--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009
Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.
"Chris Dent" <ch...@noreply.null> wrote in message
news:%230vP%23sSbK...@TK2MSFTNGP02.phx.gbl...
$HKLM = 2147483650
$RemoteComputer = "remoteServer"
$RegObject = Get-WmiObject -List -Namespace root\default -ComputerName
$RemoteComputer | Where-Object {$_.Name -eq "StdRegProv"}
$RegPath =
"Software\trendmicro\serverprotect\currentversion\informationserver\"
$RegKeys = $RegObject.EnumKey($HKLM, $RegPath)
$RegKeys|foreach {
$NewPath = $RegPath + $_.sNames
write-output $NewPath }
--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009
Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.
"Kryten" <kryt...@googlemail.com> wrote in message
news:584897ad-ab7e-4237...@1g2000vbm.googlegroups.com...
Hard to say without seeing what some of those variables contain.
Might be worth trying explicitly casting $NewPath
as an array.
So the last bit would look more like:-
$RegKeys|foreach {
[array]$NewPath += $RegPath + $_.sNames
write-output $NewPath }
Good luck,
Stuart