Skip to main content
TopMiniSite

Posts (page 25)

  • How to Use -Replace Twice In One Statement In Powershell? preview
    4 min read
    To use -replace twice in one statement in PowerShell, you can simply separate the replacement operations with a semicolon. For example: $text = "Hello world 123" $text -replace "Hello", "Hi" -replace "123", "456" In this example, we are first replacing "Hello" with "Hi" and then replacing "123" with "456" in the variable $text. The semicolon allows you to chain multiple -replace operations in a single statement.

  • How to Iterate Csv File Using Powershell? preview
    5 min read
    To iterate through a CSV file using PowerShell, you can use the Import-Csv cmdlet to read the contents of the file and then loop through each row in the CSV data. Here is an example of how you can achieve this:Use the Import-Csv cmdlet to read the CSV file and store it in a variable: $csvData = Import-Csv -Path "C:\path\to\file.

  • How to Connect to And Populate Sql Database Using Powershell? preview
    5 min read
    To connect to and populate a SQL database using PowerShell, you can use the SqlClient class available in the System.Data.SqlClient namespace. Start by creating a SqlConnection object and specifying the connection string to your SQL database. Open the connection using the Open method.After establishing the connection, you can use SqlCommand objects to execute queries against the database.

  • How to Use Regex Within Powershell? preview
    7 min read
    To use regex within PowerShell, you can use the -match operator along with regular expressions. For example, you can use the following syntax to match a pattern within a string: $string -match 'regex_pattern' You can also use the -replace operator to replace a specific pattern within a string.Keep in mind that PowerShell uses the .NET framework's regular expression engine, so you can use the same syntax as in C# or other .NET languages.

  • How to Check Who Has Access to Folders Using Cmd Or Powershell? preview
    4 min read
    To check who has access to folders using Command Prompt (cmd) or Powershell, you can use the "icacls" command. Open Command Prompt or Powershell and navigate to the folder you want to check the access permissions for. Then, type the command "icacls <folder_path>" and press Enter. This command will display a list of users and their corresponding access permissions for the folder.

  • How to Use Variable In Sql From Powershell Script? preview
    6 min read
    In PowerShell, you can use variables in SQL queries by creating a connection to a database using ADO.NET and then executing SQL commands with the variables embedded in the query string. You can define the variables in your PowerShell script and then pass them into the SQL query using the Parameters.AddWithValue() method. This allows you to dynamically insert values into your SQL queries based on the variables you have defined in your PowerShell script.

  • How to Parse Json Response In Powershell? preview
    6 min read
    To parse a JSON response in PowerShell, you can use the ConvertFrom-Json cmdlet.After making a request to an API and receiving a JSON response, you can store the response in a variable and then use ConvertFrom-Json to convert the JSON string into a PowerShell object that you can work with.

  • How to Associate A File Type With A Powershell Script? preview
    5 min read
    To associate a file type with a PowerShell script, you can use the assoc and ftype commands in the Command Prompt.First, open Command Prompt as an administrator.Next, use the assoc command to associate the file extension with a file type. For example, to associate .txt files with a custom file type called "MyScript", you would run the command assoc .txt=MyScript.Then, use the ftype command to associate the file type with the PowerShell script.

  • How to Move Files From Specific Folders Only Using Powershell? preview
    4 min read
    To move files from specific folders using PowerShell, you can use the Move-Item cmdlet along with the -Path parameter to specify the source folder and the -Destination parameter to specify the destination folder. You can also use the -Recurse parameter to include subdirectories.

  • How to Return an Object In Powershell? preview
    4 min read
    In PowerShell, you can return an object by using the return keyword followed by the object you want to return. This object can be a string, integer, array, or any other data type that you want to return from a function or script.For example, if you have a function that calculates the square of a number and you want to return the square value, you can use the return keyword to specify the return value.

  • How to Send A Colored Excel to Outlook Email Using Powershell? preview
    3 min read
    To send a colored Excel file to an Outlook email using PowerShell, you can use the "Send-MailMessage" cmdlet to attach the Excel file to the email. However, keep in mind that the color formatting of the Excel file itself will not be visible in the email body. The recipient will need to download the attached file to see the colors.You can use the following PowerShell script to send the colored Excel file as an attachment: $smtpServer = "smtp.office365.

  • How to Use Delegates Inside A Static Powershell Class? preview
    3 min read
    To use delegates inside a static PowerShell class, you first need to define the delegate type using the delegate keyword. Then, within the class, you can declare a field of the delegate type and assign a method to it. Static classes in PowerShell do not allow instance members, so you will need to use static members to work with delegates. You can then invoke the delegate by calling the method it is pointing to.