Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

Thursday, April 16, 2015

Active Directory ProxyAddress Email Addresses SMTP Extract with powershell

Bit of fun with extracting SMTP secondary addresses from user account.

$user=get-aduser testuser -prop,proxyAddresses

$user|select samaccountname,@{Name=”AdditionalAddresses”;Expression={($_.proxyAddresses| Foreach-object {$_.split([environment]::NewLine)} | Where-Object {$_ -match “smtp”} | ForEach-Object {$_.substring(5)}) -join "|"}}


so..

#
#Export Detailed AD Membership info
#dump a full member list text file only once per day
#

$outputfile = $savepath + "\" + $dayofweek + "_theuserlist.xlsx"
del $outputfile
$allpandas = get-aduser -filter {extensionattribute5 -eq "Pandas"}  -Properties displayname,title,company,department,lastlogondate,physicalDeliveryOfficeName,proxyAddresses,EmailAddress
$allpandas = $allpandas|select samaccountname,givenname,surname,displayname,title,company,department,UserPrincipalName,physicalDeliveryOfficeName,lastlogondate,EmailAddress,@{Name=”AdditionalAddresses”;Expression={($_.proxyAddresses| Foreach-object {$_.split([environment]::NewLine)} | Where-Object {$_ -match “smtp”} | ForEach-Object {$_.substring(5)}) -join "|"}}
$allpandas | C:\scripts\Export-XLSX.ps1 -Path $outputfile -WorkSheetName 'pandas'

Thursday, February 14, 2013

Powershell and DNS

Was trying to search for static address in a large subnet that I was working on.

start off with reading - http://gallery.technet.microsoft.com/scriptcenter/DNS-Server-PowerShell-afc2142b

retrieve the records with
$records = Get-DnsServerResourceRecord -ZoneName koolkids.internal -computer kcdc

tried
$records| ? recorddata -like "10.10.*"

got nothing returned... :(

then check the types:
$records | get-member
DistinguishedName         Property   string DistinguishedName {get;}
HostName                  Property   string HostName {get;}
PSComputerName            Property   string PSComputerName {get;}
RecordClass               Property   string RecordClass {get;}
RecordData                Property   CimInstance#Instance RecordData {get;set;}
RecordType                Property   string RecordType {get;}
Timestamp                 Property   CimInstance#DateTime Timestamp {get;}
TimeToLive                Property   CimInstance#DateTime TimeToLive {get;set;}

notice that is was CimInstance#Instance for the RecordData
can't remember how to convert it to string on the fly.
so my colleague suggested 
$records | out-gridview

then do the filtering from there, which work nice.

if after a few coffees I remember how to sort this out. I will update.

Friday, August 3, 2012

String Stuff with Powershell UNC

Striping servername from a UNC path
PS> $path = \\chicken\scrambled

PS >$servername=$path.Substring(2,$path.Substring(2).indexof("\"))

PS>$servername
chicken

2,$path.Substring(2).indexof("\")
=
2 # start cut @ position 2
$path.Substring(2) #then search from 2 position
.indexof("\") # search for \ in postion

My regex query to get server name
$path -match "[^/\\\]\[]+"
$matches.Values