Quantcast
Channel: Windows PowerShell Forum
Viewing all 2562 articles
Browse latest View live

Ignore HTTP Return Code for parsing a HTML Site

$
0
0
Hello

for our customers we are providing some ACS-Sites. Those sites are just accessable through our security-client. Behind those ACS-Sites our customers run their own webapplications. We don't have access on those application.

We like to monitor those ACS-sites, that we can detect failures/errors before they do. I thought that I could parse the HTML, write it to a textfile and monitore a specific string with our monitoring-tool.

Unfortunately, some applications give back an HTTP 40x error or 50x and the parsing fails. Is there a way, to ignore the returncode and download the website anyway?
We just provide the access to the site and not the application itself. This means if the site shows an application-error, the ACS is accessible

Regards

Get-IPAddress PowerShell cmdlet is not Functioning?

$
0
0

Hello everyone!

I am new to Windows PowerShell and I am having difficulty with a particular cmdlet (Get-IPAddress). At the moment my PowerShell prompt does not even recognize the cmdlet. Please see the output below:

PS C:\> get-help get-ipaddress
Get-Help : Cannot find Help for topic "get-ipaddress".
At line:1 char:9
+ get-help <<<<  get-ipaddress
    + CategoryInfo          : ResourceUnavailable: (:) [Get-Help], HelpNotFoundException
    + FullyQualifiedErrorId : HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand

Furthermore, I believe I ran this command yesterday (Get-IPAddress google.com) but today if I issue the command I get the following output:

PS C:\> Get-IPAddress google.com
The term 'Get-IPAddress' is not recognized as the name of a cmdlet, function, script file, or operabl
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14
+ Get-IPAddress <<<<  google.com
    + CategoryInfo          : ObjectNotFound: (Get-IPAddress:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

May someone please provide insight on this? Does this cmdlet exist? If so, how is my syntax incorrect? I would like to use this cmdlet to resolve hostnames to IP addresses. I know that the commandnslookup also provides hostname to IP address resolution but I would like to learn the Get-IPAddresscommand so that I may create PowerShell scripts.

Thank you in advance for any assistance!



Powershell nslookup -

$
0
0

I found the following powershell using ping and nslookup from the following webpage:  http://blog.securitywhole.com/2009/09/23/powershell-nslookup-brute-force.aspx

for (/L %i in (1,1,255) do @echo 10.10.10.%i: & @nslookup 10.10.10.%i 2>nul | find "Name")

But I'm receiving an error with regards to the &:

Ampersand not allowed. The & operator is reserved for future use; use "&" to pass ampersand as a string.

At line:1 char:48

Missing statement body in for loop.
At line:1 char:93

But if I wrap the & in "&" I receive an error:

Missing statement body in for loop.
At line:1 char:95
What have I done wrong with regards to the &?

Help Please: Need script to search shares for files/dir with non-inherited permissions using Local Groups...

$
0
0

Hey Guys... :)

We are trying to migrate some data from file server that has a Local Group entry defined on it.  I am looking for a way to search the files/folders in a share, for any object that may have it in it's ACLs...  Our intention is to locate and replace the Local Group permission with a new AD Group permission.

i.e.  would be search for a file/folder with a {SERVER}\{GROUP} permission as opposed to a {DOMAIN}\{GROUP} permission...

Can anyone help please???


NAS Engineer

Supply values for the following parameters:

$
0
0

PS C:\fso> .\Get-EventsByWmi.ps1 -computer c:\fso\myservers.txt -log system -eventID 21
cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:
Process[0]:

Can anyone please help me understand what this error means and not sure where I would change it?

How to keep blank lines from being used as input?

$
0
0

I’m trying to write a simple script to clean up some directories.  However, I don’t want to delete all directories, only the ones in my text file.

Problem- if my text file has a blank line, then I am basically telling my script to delete everything under the parent.  Any way to keep this from happening? (it's easy to have an extra return at the end, or just a blank line somewhere, and I want to safeguard against that).

 

Example- I want to delete users/jdoe but not users/tgun

 

However, if there is a blank line, everything under the users folder gets deleted including tgun. L

 

Current script-

 

 

foreach ($folder in get-content c:\script\deletefolders.txt)

{

               get-childitem c:\users\$folder -recurse |remove-item -recurse -confirm:$false

              "Deleted folder $folder"

 

}

Search a .mdb Database file and outputing info

$
0
0

The code below output the data from the .mdb table Perfectly.  but i need to output the info base on a particular pattern

output data if -pattern " error" is found within the Logtext column . also i want to search by a particular date .

the column date gives the date  of the of the info in the Logtext field

can i output the data for a particular date??

*** the code below is what i have so far.***

$adOpenStatic = 3
$adLockOptimistic = 3

$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset

$objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\admin.ittech\Desktop\integration db\Converted_Converted_IM.mdb")
$objRecordset.Open("Select * from logdocumentActivity", $objConnection,$adOpenStatic,$adLockOptimistic)

$objRecordset.MoveFirst()

do {$objRecordset.Fields.Item("logtext").Value;  $objRecordset.MoveNext()    } until 
    ($objRecordset.EOF -eq $True)

$objRecordset.Close()
$objConnection.Close()


FTP not working in powershell

$
0
0

I'm running the following:

$File = "c:\temp\test.txt"
$ftp = "ftp://username:password@servername.com/folders/test.txt"
"ftp url: $ftp"
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)
"Downloading $File..."
$webclient.DownloadFile($uri, $File)

I get the following error:

Exception calling "DownloadFile" with "2" argument(s): "Unable to connect to the remote server"
At \\path\test.ps1:11 char:1
+ $webclient.DownloadFile($uri, $File)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

I can manually type the credintials in CMD using the FTP command and it works without issues. 

C:\Users\user123>ftp
ftp> o servername
Connected to servername.com.
220 servername FTP server (Version 4.1 Mon May 26 21:40:36 CDT 2003) ready.
User (servername.com:(none)): username
331 Password required for username
Password:
230 User username logged in.
ftp>

Any ideas?



get-help get-content -online

$
0
0

Using PS 3 I'm not able to get to the online version of some of the cmdlets.  For example:

C:> get-help get-content -online
get-help : The online version of this Help topic cannot be displayed because
the Internet address (URI) of the Help topic is not specified in the command
code or in the help file for the command.

Is this a flaw in the current content of the help file update for get-content?

Other cmdlets allow access to the online help.

Sort Uptime Script just to bring back servers up more than 100 days

$
0
0

Hi guys,

I am just starting at powershell scripting and I am stuck with trying to bring back servers that have been up for more than 100 days. I am using the following script block,  Any help on this would be great, as it has been driving me nuts.

ForEach ($Server in $Servers) { Write-Host "Testing $Server..." If (Test-Connection $Server -Quiet) { #Get uptime information $WMI = Get-WmiObject Win32_OperatingSystem -ComputerName $Server If ($WMI) { $Uptime = New-TimeSpan -Start $($WMI.ConvertToDateTime($WMI.LastBootUpTime)) -End (Get-Date) $UpText = "$($Uptime.Days)d, $($Uptime.Hours)h, $($Uptime.Minutes)m" }

Thanks Guys

Format CreationTime from Get-Item

$
0
0

I need to format the CreationTime from Get-Item as "yyyymmdd hh:mm:ss."

I can find tons of examples for Get-Date (i.e., -Format u) that I could substring(0,18), but nothing for the value returned from Get-Item.

How can I format a [datetime]$Variable to the string I need to output to file?

Copy or move files from one folder to another

$
0
0

Hi

I have a list of files in following form

move;file1.txt

move;file2.txt

copy;file3.txt

etc.

as a list.txt file.

I need to copy or move files from one folder to another. I wrote the following test script:

$folder1 = 'C:\fld1\'
$folder2 = 'C:\fld2\'
$content = Get-Content C:\tmp\list.txt 
foreach($f in $content)
{
    $f = [regex]::split($f,'\t|;')
    if($f[0] -eq 'move'){Move-Item $folder1$f[1] $folder2$f[1]}
    else{Copy-Item $folder1$f[1] $folder2$f[1]}
    Write-Host $folder1$f[1] $folder2$f[1]
    Write-Host $folder1 $f[1] $folder2 $f[1]
}

But it is not working, the output of write host are like that:

C:\fld1\move pl1.txt[1] C:\fld2\move pl1.txt[1]
C:\fld1\ pl1.txt C:\fld2\ pl1.txt
C:\fld1\move pl2.txt[1] C:\fld2\move pl2.txt[1]
C:\fld1\ pl2.txt C:\fld2\ pl2.txt
C:\fld1\copy pl3.txt[1] C:\fld2\copy pl3.txt[1]
C:\fld1\ pl3.txt C:\fld2\ pl3.txt
C:\fld1\move pl4.txt[1] C:\fld2\move pl4.txt[1]
C:\fld1\ pl4.txt C:\fld2\ pl4.txt

What i need change to receive the appropriate path?

HELP reading InFo from .Mdb database

$
0
0

Morning i am a newbie to powershell and need some assistance

PROBLEM: i have a  mdb database (access). i a table name logActivity with a a column name logtext  stores information which i need to recieve using powershell. the columnlogtext stores string information.

 i want to search that column for all instance where there is the keyword is "error" and copy the output to a text file. 

 i hope i explain this properly and your help will be greatly appreciated

All the way from Jamaica "One Love" 



Use Command Prompt & Power Shell

$
0
0

How can we use Command Prompt and Power Shell to do that?

- Open several webpages and close all of them.

- how can we use TAB to jump to the fixed button to press it?

- press a button every 20 min (repeat).

- fill the "sign up form" in the fixed page.

-  .....

1 ,2,3,4, 5, 6, 7, 8, 9, 10, 11, 12, 13

Administering User Library

$
0
0
Hi, I need to write a script that allows me to change each user's default library folder in Windows 7, but I can't find a command that allows me to do this. Can anyone help?

Essentially I need to write the command so that when users sign in they can be assigned a default library folder such as D:\Data\%username% Documents or \\Server\Department\%username%

Changing the font color in richtexbox

$
0
0

Hi,

I am trying to create a tool for display comp info, disk info, service status...
Everything is working fine.

I have a question,  i want to dispaly the stopped serivce in red or disk usage if below 10% should be displayed in red.

for example...disk info.

The tool uses primal forms.

$richTextBox1.Text is for instering servername
$richTextBox2.Text for dispalying the result
Buttons to execute the functions.

Function disk {
   $richTextBox2.Text = $richTextBox2.Text.Clear
   $s=$richTextBox1.Text.split("`n")
  
       $info=Get-WmiObject win32_logicaldisk -computername $s -filter "drivetype=3"|
        Format-Table @{Name="Server Name";Expression={"{0:N1}" -f($_.systemname)}},deviceid,volumename,@{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="FreeSpace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}},@{Name="Freepercent%";Expression={"{0:N1}" -f([Math]::Round(($_.freespace / $_.size) * 100, 2))}}  -autosize | out-string
  
   
    $richtextbox2.Appendtext($info)
}

===

Displays the disk info of a computer. But displays in black font . I want it to display in red font if the freepercent is below 10%.
Please assist.

Thanks
Azam


Select-String in PS v2 - how to prevent expansion of tabs in output

$
0
0

I am using SELECT-STRING to filter a large tab-delimited text file so I can work with the file in subsets.   However, I find that the resulting output file has had all of the tabs expanded to spaces.  I have been able to reproduce the issue on two different systems running PowerShell v2 under both Windows 7 and Windows 8.  I would like to change this behavior to NOT expand the tabs.  I need to maintain the tab-delimited format because one field in each row can contain a large block of arbitrary text, and 'tab' is one of a very few characters (if not the only) that cannot appear in that field.

How can I prevent tab expansion in SELECT STRING?

Steps to reproduce the issue:

Here is a very simple test case.  Save the following text in a file called test_data.txt:

ID	NAME	STATE
001	Joe	Arizona
002	Bill	Florida
003	Jenny	Colorado
005	Anna	Arizona

Use the following command line to extract a couple of lines:

Select-String -Pattern "Arizona" -Path .\test_data.txt -SimpleMatch | Out-File -FilePath .\test_output.txt 

Open test_output.txt in notepad (or another text editor):

test_data.txt:1:001    Joe    Arizona
test_data.txt:4:005    Anna    Arizona

Note that the tabs have been expanded into spaces.

Note also that the following command line returns no results:

Select-String -Pattern "Arizona" -Path .\test_data.txt -SimpleMatch | Select-String -Pattern "`t" -SimpleMatch

This ensures that the behavior is coming from Select-String, not from Out-File.

I have also tested the following command line:

Get-Content .\test_data.txt | ? { $_ -like "*Arizona*" } | Out-File .\test_out.txt
This does not exhibit the same issue, but it appears to run more slowly than using Select-String. 

Thanks in advance for any and all assistance!

Jamie

HELP! PS script fails on remote call

$
0
0

I have three servers that I am activating a simple console app on

The call is:

([WMICLASS]"\\MyServer\ROOT\CIMV2:win32_process").Create("c:\myconsoleapp.exe") 

It runs fine on the first server (WinServ 2003) but not on the other two (WinServ 2008) 

Cannot convert value \\$servername\ROOT\CIMV2:win32_process to type "System.Management.ManagementClass". Error: "The RPC server is unavailable."

I am an admin on all three boxes. Any help is appreciated, I cannot figure this one out.

Delete all values inside registery key

$
0
0

HI,

I need to delete all the values inside a HKCU registery key for each use. SO i thought writting a login script that can perform such operation.

read MS KB which suggest to use Remove-Item -Path hkcu:\software\Reg\* but that didnt work.

any suggestions?

thanks!

How Do I Edit Webpage on a Website That Requires Authentication?

$
0
0

Hello,

I need to edit a webpage on a website that requires me to authenticate on it order to be able to access this web page.

What would you recommend me to implement this simple task:

1. [optional] Fetch data from an URL

2. Post data to the web page by adding text to the end of the form on that web page.

3. Post data to the web page by removing text at the end of the form on that web page.

Say, I want to post a line at the end of the text in web form on a regular basis, and then I want to get this line removed from there.

Would you recommend using Invoke-WebRequest?

Would somebody please assist here?

Thank you in advance.


Well this is the world we live in And these are the hands we're given...


Viewing all 2562 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>