[Solved] How to search a string in multiple files and return file name with line number/text in an Excel or csv in Powershell

Try this (don’t know if you only want the filename or the path to the file, just remove the one you dont want): Get-ChildItem -recurse | Select-String -pattern “string” | Select-Object path,line,linenumber,filename | Export-Csv -Path c:\somepath\result.csv 6 solved How to search a string in multiple files and return file name with line number/text in an … Read more

[Solved] Calculate folder size for multiple folders [closed]

You could try this. Use: Get-FileSize “C:\folder1″,”C:\folder2″,”C:\folder3\folder1” Output: Name Value —- —– Total 1456.00 C:\folder1 100.00 C:\folder2 123.00 C:\folder3\folder1 1233.00 Doesn’t throw in MB because of the calculations that SUM does… Function Get-FileSize([string[]]$Array) { $Output = @{} Foreach($String in $Array){ $FolderInfo = Get-ChildItem -Recurse $String $totalSize = “{0:N2}” -f (($FolderInfo | Measure-Object -Property Length -Sum … Read more

[Solved] Prevent auto import of PowerShell modules in Azure Automation Runbook

This behavior, in Powershell, is controlled by one of the preference variables. More specifically, the $PSModuleAutoloadingPreference variable. This variable control the automatic importing of module in the session. By default, it is set to All, which automatically import modules on first-use. Set this to None to disable the automatic importing of modules. You will need … Read more

[Solved] How to get model and serial number of monitor? [closed]

I found some info in link below.solution Using wmi classes we can take info from our monitors, then for each monitor takes values from fields and write it to file. $Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi $LogFile = “d:\monitors.txt” “Manufacturer,Name,Serial” | Out-File $LogFile ForEach ($Monitor in $Monitors) { $Manufacturer = ($Monitor.ManufacturerName|where {$_ -ne 0}|ForEach{[char]$_}) -join … Read more

[Solved] give acess to users in directory StorageV2 (general purpose v2)

You can do this with the Azure CLI which can be run in Powershell. You should be able to do this as a contributor with the az role assignment create command. Keep in mind that permissions with this command are granted at the container scope. Data Lake storage could be used to give folder level … Read more

[Solved] Unable to get data between multiple keyword using powershell

The problem with your script is here : Where-Object {$_ -match ‘(?is)(?<=\bNAME1\b).*?(?=\bNAME2\b|\bNAME3\b|NAME4|NAME5|NAME6\b)’} This doesn’t mean “keep the matches”, but “if there is a match, keep the entire string”. Here is another way to do what you want : $text = Get-Content .\withoutStar.txt $regex = “(?is)(?<=\bNAME1\b).*?(?=\bNAME[2-6]\b)” Set-Content .\AllfunctionGroup.txt -Value “” (Select-String -Pattern $regex -Input $text -AllMatches).Matches … Read more

[Solved] How to get the log of Ping via PowerShell

after that I found from Internet, You only need to add Tee-object -FilePath C:\Users\engsooncheah\Desktop\PS\Aport2_log.txt Sample code $TestResults = Test-Connection -ComputerName 8.8.8.8 -Count 10| Tee-object -FilePath C:\Users\engsooncheah\Desktop\PS\Aport2_log.txt 1 solved How to get the log of Ping via PowerShell

[Solved] Looking for Export two report in one powershell Get-Mailbox | Get-mailboxpermission

Try this: Import-csv c:\test1.csv | ForEach-Object { $MailBox = Get-Mailbox -Identity $_.Name $Permission = ($MailBox | Get-MailboxPermission -User “[email protected]”).AccessRights $Properties = @{ Name = $MailBox.DisplayName Email = $MailBox.PrimarySmtpAddress Permissions = $Permission } New-Object -TypeName PSObject -Property $Properties } 1 solved Looking for Export two report in one powershell Get-Mailbox | Get-mailboxpermission

[Solved] Recheck the URL thrice for web exception cases powershell

You are looking for something like this ? #Remove-Variable * -ErrorAction SilentlyContinue $url = “www.yourtargetsite.com” function try-webrequest($url){ try{ return (Invoke-WebRequest -uri $url -ErrorAction Stop) }catch{ return $_ } } $wr = try-webrequest $url if ($wr.statuscode -ne 200){ If($wr.categoryinfo.reason -eq “webexception”){ $count = 1 while($count -lt 4){ “Retrying…$count” $count++ if ((try-webrequest $url).statuscode -eq 200){break} sleep -seconds … Read more

[Solved] how to get a pc list that have a service running on each pc?

If all computers have powershell installed with remoting enabled, you can try the script below. It also outputs computers that were not reachable so you can retest them later if you want to. If you don’t need it, just remove the content inside the catch-block(or all of try/catch): $out = @() Get-Content “pclist.txt” | foreach … Read more

[Solved] AES. Encrypt array of bytes in powershell [closed]

I am do that i am need. New code: [Reflection.Assembly]::LoadWithPartialName(“System.Security”) $String=$buff #ARRAY OF BYTES TO ENCODE $Passphrase=”Pas” $salt=”My Voice is my P455W0RD!” $init=”Yet another key” $r = new-Object System.Security.Cryptography.AesManaged $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase) $salt = [Text.Encoding]::UTF8.GetBytes($salt) $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, “SHA1″, 5).GetBytes(32) #256/8 $r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15] $r.Padding=”Zeros” $c = $r.CreateEncryptor() $ms … Read more

[Solved] Script for renaming files in a specific way

As commented, it would be a lot simpler if you put the old and new ID values in a CSV file like this: “OldID”,”NewID” “12345”,”98765″ “23456”,”87654″ “34567”,”76543″ Then, something like below should work: # read this CSV to get an array of PSObjects $ids = Import-CSV -Path ‘D:\ReplaceId.csv’ # build a lookup table from the … Read more

[Solved] In Powershell, how to copy files with common file name string (i.e. “ABC*”) last written in a specific date range?

This is a common task, here’s the general approach we take to solving an issue like this in PowerShell. Get a list of files, VMs, Items, ETC Pipe this into the Where-Object cmdlet to filter and apply one or more constraints That’s it! With your requirements, we’ll actually do Step 2 in two separate steps, … Read more

[Solved] power shell script to get drive space ( percentage used and free ) [duplicate]

You can try this: Get-WmiObject -Class win32_Logicaldisk -ComputerName localhost | where {($_.DriveType -eq 3 -or $_.DriveType -eq 2) -and $_.FileSystem -ne $null } | Select -Property @{Name=”Volume”;Expression = {$_.DeviceID -replace “:”,””}}, @{Name=”Free”;Expression = { “{0:N0}%” -f (($_.FreeSpace/$_.Size) * 100) } } solved power shell script to get drive space ( percentage used and free ) … Read more