logo
down
shadow

POWERSHELL QUESTIONS

What are your favorite Powershell Cmdlets?
What are your favorite Powershell Cmdlets?
This might help you As a programmer/hacker, Get-Member and Get-Command are the ones I use more than any others, but the ones I use to show off are Select-Control and Send-Keys from WASP, the PowerGadgets, and some of my own stuff written in WPF again
TAG : powershell
Date : January 22 2021, 02:12 PM , By : xguru
Substring in powershell
Substring in powershell
around this issue I usually use: , You can simplify this:
TAG : powershell
Date : January 12 2021, 08:33 AM , By : Gerhard Miller
Return file path and context text line after recursive search
Return file path and context text line after recursive search
To fix the issue you can do Trying to do a recursive search through all .txt files for a specific word and return the path of the file where the text was found and the context text line. , If you're on PowerShell version 3.0 or better, you can do thi
TAG : powershell
Date : January 12 2021, 01:40 AM , By : vferman
Split a large csv file into multiple csv files according to the size in powershell
Split a large csv file into multiple csv files according to the size in powershell
around this issue this takes a slightly different path to a solution. [grin] it ...
TAG : powershell
Date : January 11 2021, 05:14 PM , By : Frank
How to compare integer literals?
How to compare integer literals?
hop of those help? Use same units for comparison You probably want to use the same units when you compare $newSize.Size and $threshold. If $threshold is in GB and you want to convert to Bytes for example, you can do this: ($threshold * 1GB)
TAG : powershell
Date : January 11 2021, 03:34 PM , By : Laques
How to set encoding for a herestring/heredoc in powershell?
How to set encoding for a herestring/heredoc in powershell?
wish helps you A here-string is just a special form of a PowerShell string literal, and like all strings in PowerShell and .NET (System.String), their in-memory encoding is always UTF-16. As an aside: For a string literal to be read into memory corre
TAG : powershell
Date : January 11 2021, 03:32 PM , By : amy
How to Uninstall-Module of older version
How to Uninstall-Module of older version
hope this fix your issue Short answer:You can't that uninstall something with PowerShellGet if it wasn't installed with PowerShellGet.
TAG : powershell
Date : January 11 2021, 03:32 PM , By : BinaryBoy
How to ignore letters/words?
How to ignore letters/words?
I think the issue was by ths following , If you insist on working with a string and keeping with the -replace operator, you can use the following:
TAG : powershell
Date : January 11 2021, 03:28 PM , By : Harry Truman
How to convert value to KB, MB, or GB depending on digit placeholders?
How to convert value to KB, MB, or GB depending on digit placeholders?
around this issue Here's two more ways of formatting a size in bytes:1) Using a switch()
TAG : powershell
Date : January 11 2021, 03:28 PM , By : Vodkat
How to copy files based on last modified date to network drive?
How to copy files based on last modified date to network drive?
Any of those help If your users have permission to write/delete files in the remote destination path, this should do it:
TAG : powershell
Date : January 10 2021, 02:06 PM , By : zac
Remove-PSDrive doesn't remove Mapped Drives
Remove-PSDrive doesn't remove Mapped Drives
With these it helps What you are after is the WScript.Network Com Object.
TAG : powershell
Date : January 10 2021, 02:04 PM , By : LinnheCreative
Wait for Active Directory Authentication URL list to update within a Powershell Azure Function
Wait for Active Directory Authentication URL list to update within a Powershell Azure Function
To fix the issue you can do This is not an answer with a solution. But I think I'm reading something that I have experienced on several occasions.I've been using python and Hashicorp vault to try and manage tokens/RBAC on applications. But very often
TAG : powershell
Date : January 10 2021, 02:04 PM , By : Eniac
Automating Telnet with PowerShell
Automating Telnet with PowerShell
wish help you to fix your issue Ok this isn't the most elegant solution, and it does rely on shudder VBscript but here it goes...Create a VBScript to actually expedite the telnet session, this is an example
TAG : powershell
Date : January 10 2021, 01:49 PM , By : Lunis Neko
How to suppress quotes in PowerShell commands to executables
How to suppress quotes in PowerShell commands to executables
help you fix your problem Is there a way to suppress the enclosing quotation marks around each command-line argument that PowerShell likes to generate and then pass to external executables for command-line arguments that have spaces in them? , Escape
TAG : powershell
Date : January 10 2021, 01:47 PM , By : Jimmy
Trying to move AD user and disable the account running some PowerShell
Trying to move AD user and disable the account running some PowerShell
hope this fix your issue I have managed to get it working. I think it was only missing the Values. I'm sure I tried with them in a few times. for those that helped :)
TAG : powershell
Date : January 09 2021, 02:14 PM , By : Feroz
How to run a local powershell script into remote machine via ansible?
How to run a local powershell script into remote machine via ansible?
hop of those help? Copy the script first to the target node, then execute it. https://docs.ansible.com/ansible/latest/modules/win_copy_module.html
TAG : powershell
Date : January 08 2021, 03:18 AM , By : user187301
Set ACL System.Security.AccessControl.FileSystemAccessRule to multiple users?
Set ACL System.Security.AccessControl.FileSystemAccessRule to multiple users?
I wish this help you Is it possible to specify more than 1 user directly in some kind of array when setting permissions with System.Security.AccessControl.FileSystemAccessRule? , Use a loop to add multiple ACEs to an ACL:
TAG : powershell
Date : January 07 2021, 03:08 PM , By : Alex
Replace Part of Filename if Filename Already Exists
Replace Part of Filename if Filename Already Exists
this will help As per this question and answer: rename-item and override if filename existsUse Move-Item and -Destination, and also swap $_.Name for $_.FullName (if you don't do that it will throw everything into your current directory, because Name
TAG : powershell
Date : January 07 2021, 07:50 AM , By : user179938
Using a function in a calculated field in Powershell?
Using a function in a calculated field in Powershell?
hop of those help? since you didn't show how you were calling the modified function i mentioned in my comment, i presume you were not using it correctly. [grin] your function is ... rather peculiar, so i rewrote it to work in a more normal manner.
TAG : powershell
Date : January 06 2021, 03:17 PM , By : Cosmin
How to download a file accepting license using powershell
How to download a file accepting license using powershell
this one helps. There's a GET query string parameter that indicates acceptance.Simply add i_agree_to_tenable_license_agreement=true to your query string parameters.
TAG : powershell
Date : January 06 2021, 03:27 AM , By : alexandruz
Using Powershell, how to add a task sequence for installing an SCCM package
Using Powershell, how to add a task sequence for installing an SCCM package
should help you out firstly we need to create "install software" step using New-CMTSStepInstallSoftware, then add the step into TS using Add-CMTaskSequenceStep. This is an example.
TAG : powershell
Date : January 03 2021, 08:18 AM , By : NeedOptic
Powershell Azure function times out on processing queue
Powershell Azure function times out on processing queue
I wish did fix the issue. Powershell Azure Functions by default are not scaling well on consumption plan and poorely scale on dedicated plan due to default settings. If you function is not CPU bound and expected to scale well due to high number of qu
TAG : powershell
Date : January 03 2021, 08:18 AM , By : Ashaea
How to get a last 15 minutes of a formatted log using a powershell script
How to get a last 15 minutes of a formatted log using a powershell script
this will help The problem I see is that not all lines start with a datetime stamp. So you'd have to read the log in raw, then split it so each record starts with a datetime stamp. Then you could filter easily enough.
TAG : powershell
Date : January 03 2021, 08:18 AM , By : Jay Crockett
Using both desktop Powershell 5.1 and Powershell Core 6.1
Using both desktop Powershell 5.1 and Powershell Core 6.1
it should still fix some issue I think the issue might be setting PowerShell Core 6.1 as your default shell.If I launch PowerShell 5.1 (powershell.exe) from cmd prompt:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : 小和尚
What does mean % , $_ and @ in Powershell?
What does mean % , $_ and @ in Powershell?
To fix the issue you can do % In your case, it is the modulus operator. It will return the remainder of dividing the left-hand side value by the right-hand side value. It defaults as a PowerShell alias for Foreach-Object. You can execute the Get-Alia
TAG : powershell
Date : January 02 2021, 06:48 AM , By : todor
Teams: Invoke-Webrequest sending base64 string (png) to Teams
Teams: Invoke-Webrequest sending base64 string (png) to Teams
wish helps you Webhook support Office 365 connector card. Please send following message card JSON and let us know if you facing any issues.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Sonal
How can I replicate New-SmbGlobalMapping in C# code?
How can I replicate New-SmbGlobalMapping in C# code?
I think the issue was by ths following , I can't find source for the PowerShell New-SmbGlobalMapping command (is there a way to see it?) and I can't find a suitable API to call. I hope someone knows the magic incantation I can put in my .NET code.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : John R
How do I output the files being copied in console?
How do I output the files being copied in console?
I wish this help you You can use the parameter -PassThru for Copy-Item. But it will not show you the file size.I would recommend you to use robocopy.exe for any copy jobs in powershell. It is more reilable and in your case it will show you the filesi
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Ed.
Powershell: How to stop start-job?
Powershell: How to stop start-job?
around this issue Remove-Job. Here's an example. If the job completes, you don't have to run stop-job. Although invoke-expression is almost always the wrong answer, and you have to watch user input to it. I'm in osx.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : CM.
Formatting output from PowerShell to a csv file
Formatting output from PowerShell to a csv file
hop of those help? I'm assuming your variable $groupfile is the result of a Import-Csv command.If I understand the question properly, you could do this:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : potix2
How to check if a PowerShell switch parameter is absent or false
How to check if a PowerShell switch parameter is absent or false
it helps some times To check whether a parameter was either passed in by the caller or not, inspect the $PSBoundParameters automatic variable:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : delphiace
How do I force a function to return a single element array instead of the contained object?
How do I force a function to return a single element array instead of the contained object?
hop of those help? If I understand your question, you can use the , operator when returning the value; e.g.:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Genipro
compressed file syntax can be supported across all powershell version
compressed file syntax can be supported across all powershell version
I hope this helps . As i mentioned in the comment, Powershell v5 supports using v1 commands in it. So this is a v1 code:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : alexandruz
Is there a way in Powershell for a boolean parameter to automatically be true if not specified when the function is call
Is there a way in Powershell for a boolean parameter to automatically be true if not specified when the function is call
seems to work fine As the others have stated, the Switch parameter type is probably what you want. Typically, though, the switch is used to specify non-default behavior (so the default value is $false if the switch parameter is not provided). So you
TAG : powershell
Date : January 02 2021, 06:48 AM , By : nabbed
New-Partition -DriveLetter Option
New-Partition -DriveLetter Option
I wish did fix the issue. How do I create a single char variable in PowerShell? , The answer was two fold:Create the char variable like this:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Janne Laine
How to add SAMAccountName to output?
How to add SAMAccountName to output?
I wish this help you SamAccountName is not available through Get-Mailbox or Get-MailboxPermission but you can get it with Get-User with calculated property, see example:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Ir0nh1de
How to do looping to rename and read a file using PowerShell?
How to do looping to rename and read a file using PowerShell?
wish help you to fix your issue With the Get-ChildItem cmdlet, you can iterate the results easily by directly piping them through to a Foreach-Object. Inside that loop, every file found is a FileInfo object, represented by the automatic variable $_.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : s8k
Read CSV file then split the values and create a global variable
Read CSV file then split the values and create a global variable
Hope this helps Trying to read a file that having comma delimited rows. I want to read each row and split into array and make a global variables with the array values. , Do it like this:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : ChrisMe
(Get-Date).ToUniversalTime() convert to string but not change format
(Get-Date).ToUniversalTime() convert to string but not change format
should help you out Using the Universal Full format specifier (U) with the ToString() method, you can return the Universal Time as a string.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Steve Jones
Adding Extra Headers in CSV
Adding Extra Headers in CSV
wish of those help What you're trying to create there is not actually a CSV, at least not in a way that the *-Csv cmdlets could handle. You can manually create it like this, though:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Matt Leacock
New-Mailbox command does not accept the -Equipment argument
New-Mailbox command does not accept the -Equipment argument
fixed the issue. Will look into that further PowerShell interprets -$($Type) as a string argument rather than a parameter name. Use splatting to conditionally pass parameters like this:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : James Dio
How do I remove IIS 'server' header from http response using Powershell?
How do I remove IIS 'server' header from http response using Powershell?
Hope this helps Accoding to your description, I suggest you could try to use below powershell command to remove the IIS http response server header:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Kilimanjaro
Creating Subdirectory With Date As Today(mm-dd-yyyy) in Network Drive
Creating Subdirectory With Date As Today(mm-dd-yyyy) in Network Drive
This might help you By default network drives are not available in an elevated process. You can find more information here: https://support.microsoft.com/en-gb/help/3035277/mapped-drives-are-not-available-from-an-elevated-prompt-when-uac-is-coI would
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Gazza
My first parameter is not being passed to my function
My first parameter is not being passed to my function
Hope this helps Reference items in the $args array directly. You don't need that param($args) statement at top of the script.Simplified example...
TAG : powershell
Date : January 02 2021, 06:48 AM , By : user161314
How can I overwrite an existing zip file?
How can I overwrite an existing zip file?
To fix the issue you can do When in doubt, read the documentation.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Frank
How to use double if statement using powershell?
How to use double if statement using powershell?
To fix this issue The original Powershell code contains a bug. Chaining conditions with -and like so,
TAG : powershell
Date : January 02 2021, 06:48 AM , By : liquidx
Command using either or both -Path parameter and $input?
Command using either or both -Path parameter and $input?
I wish this helpful for you An obvious problem I see here is that you are passing in the name of a file in the 1st case and the in 2nd, you are passing in the content of the file. If you send it both to the same variable, you are going to have a prob
TAG : powershell
Date : January 02 2021, 06:48 AM , By : kiirpi
How can I return multiple values from a powershell script to the batch file that is calling it?
How can I return multiple values from a powershell script to the batch file that is calling it?
will be helpful for those in need In the exact same way you get several values from any application: one per line...
TAG : powershell
Date : January 02 2021, 06:48 AM , By : francisco santos
Sensitive word search with powershell
Sensitive word search with powershell
it helps some times You've got the right idea. The -Pattern tack in powershell can usually be called on to work with regular expressions. If you've never worked with regular expressions, take a look at this beginner's guide to using regex pattern mat
TAG : powershell
Date : January 02 2021, 06:48 AM , By : 22.
Copy files located in multiple subfolder, using a mildmatch search
Copy files located in multiple subfolder, using a mildmatch search
Hope this helps Your code will only give you files that are named exactly as the example in your variable, which is:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Roel
Replace the text for all files in a Directory
Replace the text for all files in a Directory
I think the issue was by ths following , I have written the below conditional script to go through the files in the directory and replace the one text in all files only if file contains the word as 'Health' , Can you try with this
TAG : powershell
Date : January 02 2021, 06:48 AM , By : uxn
How to write a PowerShell script which auto increments a number by 1 every time it's run?
How to write a PowerShell script which auto increments a number by 1 every time it's run?
it helps some times here is some example to create a file and format the numbers. Remember that leading zeros are only possible in a string. (place $counter = $counter++ at will)
TAG : powershell
Date : January 02 2021, 06:48 AM , By : John Miller
new user powershell get-service
new user powershell get-service
should help you out There is so much wrong with your code block so I just re-wrote 90% of it with what I believe you are trying to accomplish.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : KL.
Removing Parts of a File Name based on a Delimiter
Removing Parts of a File Name based on a Delimiter
hop of those help? You could do something like the following. Feel free to tweak the -Filter on the Get-ChildItem command.
TAG : powershell
Date : January 02 2021, 06:48 AM , By : tommy
How can we transform Date in CSV file using PowerShell scripts
How can we transform Date in CSV file using PowerShell scripts
wish of those help One way to do this is to cast as [DateTime] and then output in the format you want. Example:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : rajiv
How to replace multiple characters (<3) of all the filenames in a folder (and subfolder) using PowerShell
How to replace multiple characters (<3) of all the filenames in a folder (and subfolder) using PowerShell
it helps some times Use a regex character class/set ([...]) to match all characters of interest:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : oiyto
Powershell environment variable
Powershell environment variable
fixed the issue. Will look into that further To run a PowerShell script from cmd.exe invariably requires a (powershell.exe / pwsh.exe) child process, and child processes fundamentally cannot set environment variables for their parent process[1].Your
TAG : powershell
Date : January 02 2021, 06:48 AM , By : pepper
Removing spaces from a string using Powershell
Removing spaces from a string using Powershell
wish help you to fix your issue You should think about the logic of what you want to do, and whether or not it's programmatically possible to determine if you can teach your script where it is or is not appropriate to put spaces. As it is, this is on
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Chris Lomax
List Filename and current date of all files in a directory
List Filename and current date of all files in a directory
I hope this helps . I am using the below command to get filename and current date
TAG : powershell
Date : January 02 2021, 06:48 AM , By : iyogee
PowerShell calling environment variable with another variable
PowerShell calling environment variable with another variable
this will help PowerShell makes the environment available as a PSDrive env:, so you can use Get-Item to get an environment variable by a name stored in another variable:
TAG : powershell
Date : January 02 2021, 06:48 AM , By : Nic Doye

shadow
Privacy Policy - Terms - Contact Us © scrbit.com