Jump to content

Powershell issues

Recommended Posts

So I am trying to create a powershell script that is doing a invoke-webrequest.  And every time I run it in development mode, I am getting the below results

 The term 'Invoke-WebRequest' is not recognized as the name of a cmdlet, functio
n, script file, or operable program. Check the spelling of the name, or if a pa
th was included, verify that the path is correct and try again.
At C:\Windows\system32\config\systemprofile\AppData\Local\2325971b95a34b5e8ba87
bb5bd09a470.ps1:1 char:18
+ Invoke-WebRequest <<<<  -Uri "https://remote.COMPANYNAME.com/Citrix/XenAp
p/" |Select-Object StatusCode
    + CategoryInfo          : ObjectNotFound: (Invoke-WebRequest:String) [], C 
    + FullyQualifiedErrorId : CommandNotFoundException
Why would this be?  I can run this all day via local powershell but when I try to run this same via the scripting, I have issues.  

Note I have tried using powershell as admin, powershell, and execute script.  They all have the same results.


Ideally I am trying to create a monitor but the monitors will not do what I am asking it to.  So instead I am going to run a script and see if that works in my favor.


Anyway, thanks for the help



Share this post

Link to post
Share on other sites

Invoke-WebRequest was introduced in Windows PowerShell 3.0, and is not on all computers...


Try this instead:

$SoftwarePath = "C:\Support\Automate"
$DownloadPath = "https://s3.amazonaws.com/assets-cp/assets/Agent_Uninstall.exe"
    $Filename = [System.IO.Path]::GetFileName($DownloadPath)
    $SoftwareFullPath = "$($SoftwarePath)\$Filename"
    $wc = New-Object System.Net.WebClient
    if (!(Test-Path $SoftwarePath)) {md $SoftwarePath}
    Set-Location $SoftwarePath
    if ((Test-Path $SoftwareFullPath)) {Remove-Item $SoftwareFullPath}
    $wc.DownloadFile($DownloadPath, $SoftwareFullPath)


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...