Trying to delete files through power shell based on CSV column input

I am trying to delete files using PowerShell script and taking files in put details from CSV file. CSV File- Below is PowerShell code. $files = Get-Content "C:\DeleteFiles\FilesPresent1.csv" foreach ($file in $files) { Remove-Item -Path $file.ServerRelativeUrl.Trim() -Force } Write-Host -foregroundcolor yellow "Delete action complete" But still i am not able achieve this, can any one… Read More Trying to delete files through power shell based on CSV column input

Formatting Powershell command line in Excel VBA

I can’t seem to get this correct. Maybe fresh eyes? This command works in a non-elevated Powershell window to change the last modified date of a file: (get-item "C:\users\ron\nwfundpositions.csv").lastwritetime=("16 Jun 2023 18:00:00") I am trying to run the same command from VBA: strCommand = "powershell " & PSline Set WshShell = CreateObject("WScript.Shell") Set WshShellExec =… Read More Formatting Powershell command line in Excel VBA

File is being updated even logic returns false

I want to add new lines after the <seq> tag only if $mp3File.FullName is not equal to $currentFileInPlaylist. However, when the script logic returns false (echoing "nothing to add"), file 1.wpl is still updating. Below is the complete code: $folderPath = "C:\Users\user\Downloads\" $playList = "C:\Users\user\Music\Playlists\1.wpl" # If File with datetime when script was executed exists,… Read More File is being updated even logic returns false

How to pass a specific xml filter in Powershell to request events?

# Define the remote server name $remoteServer = "SERVER_NAME" # Define the credentials for authentication $username = "USERNAME" $password = "PASSWORD" $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $securePassword # Define the time range for the last half hour $startTime = (Get-Date).AddMinutes(-30) $endTime = Get-Date # Define the… Read More How to pass a specific xml filter in Powershell to request events?

Avoid Select-Object output on screen

I am having a bit of trouble with Select-Object. With the following piece of (truncated) code: $totalData=(Get-Content $Env:TEMP\FBIUtemp2.txt) ….. $data="" …. …. $data =($totalData | Select-Object -Index ($s..$limit)) $data.Replace("`r`n"," ") $data.Replace("`n"," ") I get a String (list of String separated with newline termination) from a file and get lines between $s and $limit into another… Read More Avoid Select-Object output on screen

How to store variable and use it as a -Pattern from Get-Content?

Trying to check if few software are installed, when I use this code, it works fine: $Pattern = "Winr","adobe";$software = get-package | Select-Object Name; $array = @($software.name) | Set-Content C:\temp\installed.txt; $SEL = Select-String -Path C:\temp\installed.txt -Pattern $Pattern; if ($SEL -ne $null) {write-host Found => $SEL.Line} else {write-host Nothing Found} This code works without issues, but… Read More How to store variable and use it as a -Pattern from Get-Content?

Issue with retrieving data from Graph API to PowerShell

I’m starting to work with PowerShell scripts and I’m having an issue with user.accountEnabled. I found out that I need to use the appropriate select statement when retrieving data, so I’m using https://graph.microsoft.com/v1.0/users/?$select=displayname,accountEnabled,userPrincipalName I’m using the app ID and app secret, and I confirmed in Postman (using the same credentials) that I’m getting correct responses… Read More Issue with retrieving data from Graph API to PowerShell