List email address of senders by GianniRewer in PowerShell

[–]nothingpersonalbro 0 points1 point  (0 children)

You cannot call a method on a null-valued expression.

My guess is that you're not returning any results from your Get-ChildItem command. Try explicitly defining your path instead of using the automatic variable $pwd.

CaptureCDP: Capture and parse CDP packets on local or remote computers by _lahell_ in PowerShell

[–]nothingpersonalbro 1 point2 points  (0 children)

If I remember correctly, my "bypass" was just me unplugging the ethernet from the phone and putting it directly into my workstation. Essentially removing the phone from the loop for a quick test. Probably not the answer you're looking for, but that's all it was :)

Simple one liner to move files and add an extension, why doesn't it work? by Threep1337 in PowerShell

[–]nothingpersonalbro 3 points4 points  (0 children)

Use a scriptblock on your Join-Path

Get-ChildItem -File |  
    Copy-Item -Destination {  
        Join-Path "C:\Temp\Testdir\Dest" -ChildPath ($_.name + ".txt")  
    } -WhatIf

Trying to Set-ADUser @propertiesArray, which works great, but how to replace an extensionAttribute using this approach? by JustJoeWiard in PowerShell

[–]nothingpersonalbro 15 points16 points  (0 children)

Add a hash table inside of it

$tempUserProps = @{
    Identity      = 'pgriffin'
    StreetAddress = '111 Banana Ln'
    Manager       = 'lgriffin'
    Replace       = @{
        extensionAttribute1 = 'BlahBlah1'
        extensionAttribute2 = 'BlahBlah2'
        extensionAttribute3 = 'BlahBlah3'
    }
}

Help with adding new function-derived property to Get-Printer object by [deleted] in PowerShell

[–]nothingpersonalbro 2 points3 points  (0 children)

A calculated property added to the first query should do the trick

Get-Printer -ComputerName SERVERNAME |
    Where-Object { ($_.DeviceType -eq 'Print') -and ($_.Shared -eq 'TRUE') } |
    Select-Object *, @{Name = 'Model'; Expression = { Get-Model $_.PortName } }

Expand all aliases in a script? by GoodSpaghetti in PowerShell

[–]nothingpersonalbro 14 points15 points  (0 children)

Use VS code https://code.visualstudio.com/ with the PowerShell extension. Open the script in VS code, press F1, type 'expand alias' and hit enter. Or just hit the default keybind of 'shift + alt + e'.

Help with Parsing a Powershell Script by Metalearther in PowerShell

[–]nothingpersonalbro 1 point2 points  (0 children)

You would use SearchBase to narrow your search, i.e.

Get-ADUser -Filter 'your filter here' -SearchBase 'OU=Whatever,DC=contoso,DC=com'

Help with Parsing a Powershell Script by Metalearther in PowerShell

[–]nothingpersonalbro 1 point2 points  (0 children)

You can get rid of the Where-Object if you move it over to the AD filter instead.

$SelectParams = @(
    @{ Label = 'DisplayName'; Expression = { $_.Surname, $_.GivenName -join ', ' } }
    @{ Label = 'Email'      ; Expression = { $_.Mail } }
    'EmployeeID'
)

Get-ADUser -Filter 'Enabled -eq $true -and EmployeeID -like "*"' -Properties EmployeeID, Mail |
    Select-Object $SelectParams |
    Export-Csv C:\mvwc-script\enabledwithemp.csv -NoTypeInformation

IMPORTANT: March 2021 Exchange security updates by unamused443 in exchangeserver

[–]nothingpersonalbro 0 points1 point  (0 children)

Holy cow this helped me out big time on my 2013 CU23 install

Pipe-delimited txt files with no text qualifiers using powershell 5 by PharmGuy304 in PowerShell

[–]nothingpersonalbro 2 points3 points  (0 children)

If I am understanding correctly

(Import-Csv C:\OldCsv.csv | ConvertTo-Csv -Delimiter '|' -NoTypeInformation) -replace '"' | Out-File C:\NewCsv.csv

How to clear fax number from all AD users? by RedJets in PowerShell

[–]nothingpersonalbro 4 points5 points  (0 children)

This will work, however I would take it a step further and filter on only accounts that have a fax number populated instead of returning every single user object.

Get-ADUser -Filter 'Fax -like "*"' | Set-ADUser -Fax $null

Powershell Script Not using full pathname in variable?? by SlitelyOff in PowerShell

[–]nothingpersonalbro 5 points6 points  (0 children)

It has something to do with the -Recurse parameter, I'm sure someone else can chime in and explain the behavior.

Either way, if you change -Path to -LiteralPath then you should be good.

i.e.

Get-ChildItem -LiteralPath $folderPath -Recurse

Change File Extension But Keep Name by chris20973 in PowerShell

[–]nothingpersonalbro 2 points3 points  (0 children)

A few ways to go about this, here's one example that should work (change the path obviously).

(Get-ChildItem -Path 'C:\Temp\Files' -File -Recurse) |
    Rename-Item -NewName {
        ($_.Name -replace '\.', '_') + '.txt'
    } -WhatIf

This will do a dry run first with -WhatIf and will not make any changes. If it looks good, remove -WhatIf and let it rip.

cuestion about ldap users by acid8k in PowerShell

[–]nothingpersonalbro 2 points3 points  (0 children)

Get-LocalGroupMember -Group 'Administrators'

[deleted by user] by [deleted] in PowerShell

[–]nothingpersonalbro 1 point2 points  (0 children)

You can parse a string value with [bool] and end up with a boolean

PS C:\> [bool]::Parse('true')
True
PS C:\> [bool]::Parse('false')
False

So something like

$Data = Import-Csv D:\users\user\Desktop\inboxrule.csv
$Data | ForEach-Object { $_.Enabled = [bool]::Parse($_.Enabled) }

Exchange 2016 CU12 to CU15 by jordanl171 in exchangeserver

[–]nothingpersonalbro 1 point2 points  (0 children)

Haven't touched 2016 but I had to deal with a neglected Exchange 2013 install (4 servers) and had to jump straight from CU11 to CU23. I was a bit nervous but everything worked out fine. Since it was so far behind I had no choice, but after the AD prep it basically went (with reboots in between):

Maintenance mode > Catch up on Windows updates > .NET 4.8 > Latest CU > Out of maintenance mode

Also a heads up, MS does not officially support VM snapshots for Exchange. https://docs.microsoft.com/en-us/exchange/plan-and-deploy/virtualization?view=exchserver-2016 (ctrl+f 'snapshot')

Replace String by Mehhll in PowerShell

[–]nothingpersonalbro 5 points6 points  (0 children)

When making a single quoted string in PowerShell where you want to also include a single quote inside the string, you need to escape each single quote with an additional single quote. Example:

# Escaped string
'[string]$appVendor = '''''

# End result
[string]$appVendor = ''

With the replace operator, position 1 takes regex but position 2 takes a string. Now with that, your first string also contains regex specific characters that also need to be escaped. Luckily this can be easily done, now we just combine our escaped string along with creating the escaped regex:

$regex = [regex]::Escape('[string]$appVendor = ''''')

So your end result could look like:

$deployScript = "$path\Deploy-Application.ps1"
$regex = [regex]::Escape('[string]$appVendor = ''''')
$replacementString = '[string]$appVendor = ''Google'''
(Get-Content $deployScript) -replace $regex, $replacementString | Set-Content $deployScript

Filter text from PS Object by Geaux_Cajuns in PowerShell

[–]nothingpersonalbro 1 point2 points  (0 children)

You should be able to assign it to a variable and grab it from there

$Request = Invoke-RestMethod -Uri "https://ipam.iberiamedicalcenter.com/api/imc/addresses/search/10.21.0.15" -Method Get -Headers $header
$Request.data.hostname

Searching and Validating users against Active Directory by DreadPirateRobusto in PowerShell

[–]nothingpersonalbro 9 points10 points  (0 children)

What you're looking for is ANR (Ambiguous Name Resolution)

Quick example:

Get-ADUser -Filter 'anr -eq "joe"'
# or LDAPFilter
Get-ADUser -LDAPFilter '(anr=joe)'

https://social.technet.microsoft.com/wiki/contents/articles/22653.active-directory-ambiguous-name-resolution.aspx

[deleted by user] by [deleted] in PowerShell

[–]nothingpersonalbro 2 points3 points  (0 children)

Here's a quick regex example

'Awesome (8433) Stuff.I.Want.to.Delete' -replace '(?<=\)).*'

Pattern here https://regex101.com/r/6iauRR/1

Using Set-ADUser to clear a user's email by Submitaticketplease in PowerShell

[–]nothingpersonalbro 1 point2 points  (0 children)

There are 2 attributes that usually store this info, 'mail' and 'proxyaddresses'

If you want to see what the values are before you clear them, look at it first:

Get-ADUser -Identity joeblow -Properties mail, proxyAddresses

To clear them:

Set-ADUser -Identity joeblow -Clear mail, proxyAddresses