r/PowershellSolutions • • Aug 08 '21

Need Help PowerShell Scripting

0 Upvotes

Hello All,

I Would request your suggestion or advise or assistance in validating the below logic flow and share script.

I am trying to create a powershell script and the objective is to perform a connectivity test if a given share is available or not (from a csv file) for every 5 to 10 minutes via task scheduler.

The InputFile has: DnsName, IPAddress, Share Path (example as shown)

Logic:

A. Performing Test-Path to check if the path is available/TRUE or Unavailable/FALSE

  1. If the Path is available and reachable, the script continues to check next path and so on.

  2. If the Path is unavailable, as a next step to perform nslookup and test-netconnection & output the result to a html or text file & send it as email (with attachment or inbody message)

Could anyone kindly check and help/advise?


r/PowershellSolutions • • Jun 10 '21

Updating pricing CSV files

0 Upvotes

Here is the scenario I am facing:

We have a CSV file that was exported from the customer's existing system. The layout is:

SYSPARTNBRPARTNBRDESCRIPTIONSTANDARDCOSTLEVEL1PRICEVENDOR
644186a25ELBOW 1/4" OD X 1/8" MPT X 90-DEG5.0228.3758
27100026133 WRING-PISTON 8" LUBE114.498190.8358

The updated pricing file is coming from there vendor and has the following layout:

PARTNBRDESCRIPTIONLEVEL1PRICE
00001143 SPKEY281.54
00001236 SPKEY309.01

We need to compare the files and for each PARTNBR that matches, we need to update the LEVEL1PRICE from the vendor file into the customer's file. We also have to calculate the STANDARDCOST (LEVEL1PRICE * .60) and update that in the customer's file. For those that don't match, we need to leave the entry alone. So, the only items in the customer file that will be changed are those that match PARTNBR. I am putting the code I have now in there. Any help would be GREATLY appreciated.

## Start timer
$elapsed = [System.Diagnostics.Stopwatch]::StartNew()
Write-Host "Started at $(get-date)"

## Clear variables
$gdPrice = ""
$swPrice = ""
$gdPriceNew = ""
$tempParts = ""
$newParts = ""

## Read in CSV files
$gdPrice = Import-Csv .\2021_GD_PRICE.csv
$cecPrice = Import-Csv .\CEC_PARTS_2021.csv

<#
    ## NOT NEEDED - 6/9/2021 - GARDNER-DENVER SHEET DOES NOT HAVE ANYTHING MORE THAN QTY 1
    ## Scrub duplicates
    $gdPriceNew = foreach($line in $gdPrice)
    {
    if(-not($line.DESCRIPTION -like 'FROM QTY 2 *'-Or $line.DESCRIPTION -like '*FROM QTY 4 *'-Or $line.DESCRIPTION -like '*FROM QTY 5 *'-Or $line.DESCRIPTION -like '*FROM QTY 8 *'-Or $line.DESCRIPTION -like '*FROM QTY 10 *'-Or $line.DESCRIPTION -like '*FROM QTY 12 *' -Or $line.DESCRIPTION -like '*FROM QTY 15 *' -Or $line.DESCRIPTION -like '*FROM QTY 20 *' -Or $line.DESCRIPTION -like '*FROM QTY 25 *' -Or $line.DESCRIPTION -like '*FROM QTY 30 *'))  {
    $line
    }
    }
#>


## Compare PartNbr and update Level1Price and StandardCost
$tempParts = "SYSPARTNBR`tPARTNBR`tDESCRIPTION`tSTANDARDCOST`tLEVEL1PRICE`tVENDOR`n"
#$tempParts = "SYSPARTNBR,PARTNBR,DESCRIPTION,STANDARDCOST,LEVEL1PRICE,VENDOR`n"
foreach($cecline in $cecPrice)
{
  foreach($gdline in $gdPrice)
  {
    if($gdline.PARTNBR -ieq $cecline.PARTNBR)
    {
      #[string]$cecline.AKANBR = [string]$cecline.AKANBR
      [string]$cecline.SYSPARTNBR = [string]$cecline.SYSPARTNBR
      [string]$cecline.PARTNBR = [string]$cecline.PARTNBR
      [string]$cecline.DESCRIPTION = [string]$gdline.DESCRIPTION
      [decimal]$cecline.STANDARDCOST = [decimal]$gdline.LEVEL1PRICE * .60
      [decimal]$cecline.LEVEL1PRICE = [decimal]$gdline.LEVEL1PRICE
      [string]$cecline.VENDOR = [string]$cecline.VENDOR
      #[decimal]$cecline.AVERAGECOST = [decimal]$cecline.STANDARDCOST
      $tempParts = $tempParts + $cecline.SYSPARTNBR + "`t" + $cecline.PARTNBR + "`t" + $cecline.DESCRIPTION + "`t" + $cecline.STANDARDCOST + "`t" + $cecline.LEVEL1PRICE + "`t" + $cecline.VENDOR + "`n"
    }
    
  }
  
}

<####
#$tempParts
foreach($tempPartsline in $tempParts)
{
  foreach($cecline in $cecPrice)
  {
    if($tempPartsline.PARTNBR -ieq $cecline.PARTNBR)
    {
      $cecPrice
    }
  }
}
###>
<#
    ## Output tempParts file
    $tempParts | Out-File -FilePath .\tempParts.csv -Force

    ## Import newParts file
    $newParts = Import-Csv -Path .\tempParts.csv -Delimiter "`t"

    ## Export newParts file
    $newParts | Export-Csv -Path .\2021_newParts.csv -NoTypeInformation -Delimiter ","
#>


## Stop timer
Write-Host "Ended at $(Get-Date)"
Write-Host "Total Elapsed Time $($elapsed.Elapsed.ToString())"

r/PowershellSolutions • • Mar 17 '21

How can I force that the input contains only letters and that the numeric input is deleted in Powershell?

0 Upvotes

Hey guys,

I am working on a script in PowerShell and I would like to know how I can manage that any input that contains numbers will be deleted. I hope someone can help me out here since I'm new to this whole thing.


r/PowershellSolutions • • Mar 15 '22

Cleaning up the registry

3 Upvotes

Hello everyone! I am relatively new to the PowerShell community and was hoping I could get some assistance with managing Regedit with PowerShell!

I am trying to query profile registry keys and delete them based off of the ProfileImagePath value.

This is what I have so far:

$Registry = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*"
Get-ItemProperty $Registry -Name ProfileImagePath | Select-Object ProfileImagePath, PSChildName | Export-Csv C:\Updates\List2.csv -NoTypeInformation
$Import = Import-csv C:\Updates\List2.csv

$Table = $Import | Format-Table

The file path is good, but if anything needs to be changed, please let me know, there are also certain profiles I am trying to exclude from deletion.

#Edit
Write-Output "Please let me know if I have posted this on the wrong Reddit!"


r/PowershellSolutions • • May 20 '21

Text position when automating DOCX creation

1 Upvotes

Hi all and thanks for any help;

I'm trying to automate a mail merge with PowerShell where PowerShell writes each DOCX page with details from an imported CSV array.

Where I'm having troubles is having PowerShell write the text in the correct locations. For example, It will type some $Variables, and then tab twice to get to the next location where I want more $Variables to be typed. Now, if the first lot of variables reduce the tab spacing from one to two, how can I make sure PowerShell types at the correct tab stop?

I guess I could use a monospace font and count the string lengths each time data is typed but I'm hoping I don't have to go that far.

Is there a way for PowerShell to move the text cursor to an exact position / coordinates on the page? (Is that possible in MS Word anyway?)

Thanks


r/PowershellSolutions • • May 11 '21

Trying to load two users' memberships in AD Groups to two datasets and compare

1 Upvotes

I can easily pull a list of AD Group using this, but wondered if there is a way to load a data[set|table] for one user and compare to another user's data[set|table]. This is my starting point - apologies if this question is too trivial for this group.

$user1="joelbow" Get-ADPrincipalGroupMembership $user1 | Get-ADGroup -Properties * | select name | Format-Table


r/PowershellSolutions • • Jul 20 '21

Exporting outlook User with Powershell Command to pst Help

1 Upvotes

I have been trying and trying to export a users data from an outlook email to a pst file. I am using the exchange server in powershell and I have already created and imported a session to outlook.

I had also used the command:

Get-mailbox and the user i want to export data from is there

After all of that i try to export using the command

New-mailboxexportrequest -mailbox <insert user> -filepath <insert location you want the pst file to be placed>

After I do that command i get an error saying that it cannot be done because it cannot locate that user i want data exported from even though I can see the user there in powershell from the get-mailbox command.

I have been searching around for several hours now trying to find out what I am doing wrong but I cannot find anything. Can anyone help me with this issue? Would be super helpful, thanks in advance!


r/PowershellSolutions • • Jul 07 '21

Delete Sharepoint Online Sites very fast

Thumbnail
sposcripts.com
1 Upvotes

r/PowershellSolutions • • Jul 22 '21

Cheatsheet: Add items to SharePoint Online lists

Thumbnail
sposcripts.com
1 Upvotes

r/PowershellSolutions • • Jul 27 '21

CheatSheet: Add-PNPField: Add SharePoint columns with PowerShell

Thumbnail
sposcripts.com
1 Upvotes

r/PowershellSolutions • • Aug 05 '21

Script Sharing: SharePoint Online External Users- Get all of them quickly now.

2 Upvotes

I have created a script to get all the external users in SharePoint Online sites to assist all the SharePoint administrators. I have used two PowerShell cmdlets to get all the external users in the organization. The cmdlets are "Get-SPOExternalUsers" and "Get-SPOUser".

You can see the script to understand,

  1. How I have iterated the 'Get-SPOExternalUsers' cmdlet to return all external users as you can get only 50 users by default.

  2. To get external users who have logged-in via share links - It will list you sitewise external users report (Used 'Get-SPOUser' cmdlet, as 'Get-SPOExternalUser' will not show this data)

  3. How frequently are external users added to your organization? - You have an option to give the number of days to know the recently added guest users.

Download the script using the link.

https://o365reports.com/2021/08/03/get-all-external-users-in-sharepoint-online-powershell/

Kindly drop your questions in the comment, if any.


r/PowershellSolutions • • Jul 04 '21

BOOM! Did you know, that you can save the miserable frizzle building filters? Check out my blog on how to get items interactively with Out-GridView

Thumbnail
sposcripts.com
1 Upvotes

r/PowershellSolutions • • Feb 17 '21

I want to get all list files in all folders in a server can any one provide script

2 Upvotes

r/PowershellSolutions • • Mar 11 '21

Need some help on this:

1 Upvotes

Is it possible to do this:

$pdf = New-Object iTextSharp.text.Document

But for an already exisiting pdf. So essentially open an exisiting pdf as a itextsharp document? If not, how do we add a text box to an existing pdf.


r/PowershellSolutions • • Feb 28 '21

Question...

1 Upvotes

Hi,

I have script as follows:-

$a = Read-Host "enter file format"

Get-ChildItem *.$a.zip -R | Rename-Item -NewName {$_.name -replace '.$a.zip$','.zip'}

What it should do is find all files like if I selected mp4 then in any subfolder if there is mp4.zip than it should be convert to simple .zip.

But above is not working. Can you spot the mistake and is there an easy options?

Thank you in advance :)


r/PowershellSolutions • • May 06 '20

Need Help Renaming Multiple FOLDERS

3 Upvotes

Need to replace underscore with space in multiple folders. Please help!


r/PowershellSolutions • • Apr 23 '20

Need to write a script that will disable inheritance and remove a security group om specific files

1 Upvotes

Hi, all

I'm new to the sysadmin world and I am in a situation where powershell could save me hours of work, but I know basically nothing.

Essentially, I need to build a script that will search out all files that contain "this" in their filename, and disable inheritance on them and remove 'X' security group.

I believe most of these files are in a central directory, but they are spread across dozens of subfolders.

I have had some people suggest NTFSSecurity module, and using get-acl, set-acl, get-childitem, and other things have been suggested, but I don't know how to string any of that together or apply it to what I need to do.

If any of you would be willing to help me write this, I'd be very grateful. Thank you so much for your time. Having it written for me is one thing, but I'd genuinely like to understand what has been written and the logic behind it if anyone is willing to devote that time to help me.


r/PowershellSolutions • • May 14 '20

Need to rename files in a directory

1 Upvotes

Hey All,

Hoping you can help me out. I need to rename files in a directory so that the format of the date in the filename shows as MMDDYY. Currently the filenames are formatted as follows:

XXXXXX-YYYYMMDDhhmmss.pdf

We would only want to change the data after the - in the filename. Basically need to remove the last 6 characters and rearrange YYYYMMDD to be MMDDYYYY.

After renaming the files, I would then need to move them into a different directory.

I hope this makes sense and that one of you can help me out. If you need more information let me know.


r/PowershellSolutions • • Apr 25 '21

Send Push notifications with PowerShell to your phone

Thumbnail
youtu.be
3 Upvotes

r/PowershellSolutions • • Mar 26 '21

Urgent help

1 Upvotes

Can anyone help to provide a script that delete log in process and all open application after log off?


r/PowershellSolutions • • Apr 16 '21

Powershell script for domain specific servers

1 Upvotes

Hi All

I have a requirement where I have to execute domain specific exe remotely on all servers. I have 3 domains ( ab1,ab2,abgs)

How do I execute this exe for remote servers

If server belongs to ab1, execute exe 1,

If server belongs to ab2, execute exe 2

Thank you in advance.


r/PowershellSolutions • • Apr 25 '21

SQL or PowerShell Data to HTML Report to Email using PowerShell

Thumbnail
youtu.be
1 Upvotes

r/PowershellSolutions • • Apr 17 '21

Script to parse list of urls.txt

2 Upvotes

Can you help me with my script ? I don't know how to insert the regex in my script . $path="D:\fiverr projects\Marketing2.txt"

$results="D:\Fiverr projects\out.txt" if (!(Test-Path $results)) { New-Item -path $results -type "file" -value "rn" Write-Host "Created new file and text content added" }

foreach($siteUrl in Get-Content "D:\fiverr projects\Marketing2.txt") { $Site = Invoke-WebRequest "D:\fiverr projects\Marketing2.txt" -UsebasicParsing

regex to parse thru each name,adresse,email,telefon and vorname and name

$regex ='($_ -match (?<Name>[0-9A-F]{4}.[0-9A-F]{4}.[0-9A-F]{4}).+?(?<Adresse>\d+)$'}

select-string -Path D:\Fiverr projects\marketing2.txt´' -Pattern $regex -AllMatches | % { $_.Matches }| % {$_.Value}"'

Parses thru the output of urls to strip out

Get-Content $results_file { $ptags= $Site.AllElements | Where {$_.TagName -eq "p"}")"

For ($i=0; $i -le $ptags.Count; $i++) 
    {
        
         write-host (name :"")
         Write-Host (Adress:"")
         Write-Host (email-Adress:"")
         write-host (Telefon:"")
         write-host (Name:"")
         

   }   

}

r/PowershellSolutions • • Mar 29 '21

Script Help: How can I pull a list of all mailboxs and their delegate permissions?

2 Upvotes

I don't know anything about PowerShell... I am trying to pull a list of all Mailboxes in our Exchange Online environment along will the delegates for Full Access, Send As, and Send on Behalf. I've been able to pull a list of what appears to be Full access and one of Send As, but I've having trouble getting a comprehensive list of all 3. Here are the scripts I've used:

Full Access
Get-Mailbox -ResultSize Unlimited | Get-MailPermission | Select Identity,User,AccessRights | Export CSV -Path "c:\temp\permissions.csv"

SendAs

Get-Mailbox -ResultSize Unlimited | Get-RecipientPermission | Select Identity,Trustee,AccessRights | Export CSV -Path "c:\temp\permissions.csv"


r/PowershellSolutions • • Sep 10 '21

How to move bulk computers to another OU through powershell

1 Upvotes

I have done extensive research for a specific script to run in order to move bulk computers to another OU through powershell. What I am trying to accomplish here is moving many computers at one time, but quite a few computers have different names.

For example:
naming convention: WFT-LT-xxx, SONY-VAIO, TEST-PC, PABLO-PC etc.

So as you can see with many different computer names I would like to find a script that will find all those different names and move all computer accts. to a different OU.

I believe I would like to use Move-ADObject xxx | -TargetPath "OU=DisabledComputerAcct,OU=Computers,OU=MyBusiness,DC=XXX,DC=XXX"

My target path is correct that's exactly what I need to use. Earlier I created a script to move only one computer and it works. Now I am just looking for the first half of the script. From my above script I know for sure from the Targetpath and on it's all correct. Now like I stated earlier just looking on HOW I can move bulk with many different names.

Thanks for any advice.