Quantcast
Channel: PowerShell.org » All Posts
Browsing all 13067 articles
Browse latest View live

Can not get variables populated when in script

All, I see this problem repeatedly in my scripts, I’m trying to output a line of powershell to a variable. When I do it from console the variable populates fine however. Once I put that same line in a...

View Article


FTP Powershell Error Messages

Hello, I am trying to automate some upoads of files with FTPS in Powershell. I am using a script got from Internet, and changed a bit to my needs. But I am getting some errors when trying to test. I...

View Article


Reply To: Can not get variables populated when in script

I think it’s because you’re filtering in your Where-Object clause using Name instead of DisplayName. Since nothing is returned, you never get any results assigned to $Gwmi. Also worth pointing out,...

View Article

Written Time

Looking for a little help and some advise on a possible better way to do what I am trying to accomplish here. I am trying to get this script to write out the current time such as “Seven Fifty Three...

View Article

Reply To: Can not get variables populated when in script

Thanks Posho I will try your method and reply with results. Still I find it odd that the same line in the shell does add content to the $gwmi content. But when done in a script it doesn’t.

View Article


Reply To: Can not get variables populated when in script

I would suggest you confirm that by doing the following: 1. Copy the exact script into the clipboard. 2. Open a new PowerShell console. 3. Invoke a second PowerShell host with -NoProfile (powershell...

View Article

Reply To: Can not get variables populated when in script

It worked! Turning the foreach cmdlet into a variable and using it in the pipeline has opened so many possibilities for me. Thanks for the creative solution Poshoholic.

View Article

Reply To: Can not get variables populated when in script

Excellent, I’m glad it resolved your issue Matthew.

View Article


Passing parameter syntax

I need to execute a program.  The program has a switch that I need to pass to it.  The switch is throwing everything off.  I tried looking through the help and did not notice any options. invoke-item...

View Article


Reply To: Appending text to the beginning of a variable file name

The code looks like it makes sense, but I have a couple of questions. in the $files object, does using the -includes switch cause a problem? I want to avoid affecting other file types in the...

View Article

Reply To: Appending text to the beginning of a variable file name

$files will contain whatever Get-ChildItem returns – so you can use any switch of Get-ChildItem, and that includes -Include. You need to consider how you’re running Get-ChildItem. The error tells me...

View Article

Reply To: Passing parameter syntax

You don’t need Invoke-Item. c:\test\text.exe /I /Q Should work fine. If it doesn’t, and you’re using PowerShell 3, consider using the “stop parsing the rest of this line” operator: c:\test\text.exe %–...

View Article

Reply To: Passing parameter syntax

Don Jones wrote: You don’t need Invoke-Item. <pre class=”d4pbbc-pre”>c:\test\text.exe /I /Q Should work fine. If it doesn’t, and you’re using PowerShell 3, consider using the “stop parsing the...

View Article


Reply To: Passing parameter syntax

When spaces are involved, you need to use the invoke operator (&): & “C:\Program Files\Some.exe” …

View Article

Image may be NSFW.
Clik here to view.

Reply To: Passing parameter syntax

Poshoholic wrote: When spaces are involved, you need to use the invoke operator (&): & “C:\Program Files\Some.exe” … I just had my Ah Ha moment!  Thank you

View Article


Reply To: Written Time

Here are some changes that I think will get you to your goal leveraging the work you have done so far pretty easily: 1. Get the date once and store it in a variable instead of calling Get-Date 3...

View Article

Reply To: Appending text to the beginning of a variable file name

So this is now what I get, I’m stumped as to why the -Includes switch isn’t working as expected. PS C:\test> $file = Get-ChildItem -path “c:\test1″ PS C:\test> write-output $file Directory:...

View Article


Reply To: FTP Powershell Error Messages

It looks like this line $Run = $FTPRequest.GetRequestStream() failed one thing I did notice Is this line correct $FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile is the + sign...

View Article

Drop SQL database using powershell

Hi, I’m trying to check if the database exists, if exists drop the database. Please see the code below and let me know for any changes…code is working but database is not being dropped.   Thanks in...

View Article

Reply To: Drop SQL database using powershell

I’d use SMO import-module sqlps $server = New-Object Microsoft.SqlServer.Management.Smo.Server(“w12scorc”) $server.Databases $server.databases["mydb"] $server.databases["mydb"].Drop() $server.databases

View Article
Browsing all 13067 articles
Browse latest View live