Sick Gaming
How to Use Local / Remote Ollama with PowerShell 7 on Windows - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Computers (https://www.sickgaming.net/forum-86.html)
+--- Forum: Windows (https://www.sickgaming.net/forum-89.html)
+--- Thread: How to Use Local / Remote Ollama with PowerShell 7 on Windows (/thread-103533.html)



How to Use Local / Remote Ollama with PowerShell 7 on Windows - SickProdigy - 11-21-2025

How to Use Local / Remote Ollama with PowerShell 7 on Windows

This guide shows you how to set up a custom PowerShell command to interact with your local/remote Ollama server from the Windows console.


Step 1: Install PowerShell 7
  • Go to PowerShell GitHub Releases.
  • Download the latest MSI installer for Windows (e.g., PowerShell-7.x.x-win-x64.msi).
  • Run the installer and follow the prompts.
  • Start PowerShell 7 by typing pwsh in your Start menu or terminal.

Step 2: Set Up Your PowerShell Profile
  • Open PowerShell 7 (pwsh).
  • Type:
    Code:
    notepad $PROFILE
  • If prompted, create the file.
  • Paste the following function into the file: (replace model and uri with custom parameters)
    Code:
    function ollama {
        param(
            [Parameter(ValueFromRemainingArguments=$true)]
            $PromptArgs
        )
        $prompt = $PromptArgs -join " "
        $body = @{ model = "llama3.2"; prompt = $prompt } | ConvertTo-Json
        $response = Invoke-RestMethod -Uri "http://192.168.1.69:7869/api/generate" -Method POST -Body $body -ContentType "application/json"
        $lines = $response -split "`n"
        $answer = ($lines | ForEach-Object {
            try { ($_.Trim() | ConvertFrom-Json).response } catch {}
        }) -join ""
        Write-Host $answer
    }
  • Save and close Notepad.
  • Reload your profile by typing:
    Code:
    . $PROFILE

Note*
When you define a function (like ollama) in your profile, you can call it by typing its name in the console—this is known as a function-based command in PowerShell.

Step 3: Use Your Custom Command (Or alias)
  • In PowerShell 7, type:
    Code:
    ollama Your prompt here
  • Example:
    Code:
    ollama What is the capital of France?
  • You’ll see the combined response from your Ollama server.

Notes:
  • Make sure your Ollama server is running and accessible at the IP and port you specified.
  • You can change the model name or server address in the function as needed.
  • This command only sends text prompts and returns text responses.