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 ArticleFTP 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 ArticleReply 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 ArticleWritten 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 ArticleReply 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 ArticleReply 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 ArticleReply 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 ArticleReply To: Can not get variables populated when in script
Excellent, I’m glad it resolved your issue Matthew.
View ArticlePassing 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 ArticleReply 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 ArticleReply 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 ArticleReply 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 ArticleReply 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 ArticleReply To: Passing parameter syntax
When spaces are involved, you need to use the invoke operator (&): & “C:\Program Files\Some.exe” …
View ArticleReply 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 ArticleReply 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 ArticleReply 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 ArticleReply 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 ArticleDrop 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 ArticleReply 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