All Questions
Tagged with powershell-v3.0 function
16 questions
0
votes
2answers
91 views
Pass strings by reference in Powershell?
How can I pass strings by reference to the parent scope?
This doesn't work since strings are not acceptable "values".
function Submit([ref]$firstName){
$firstName.value = $txtFirstName.Text
...
0
votes
1answer
33 views
How to pass variables in functions back to main in Powershell?
I'm taking variable objects from a Windows Form and making them their own variables to be easier to work with.
$btnSubmit.Add_Click({ Submit })
function Submit(){
$FirstName = $txtFirstName....
2
votes
1answer
43 views
Powershell: Why doesn't this function work?
I am trying to make a script with neatly laid out functions that compare two folders items. The program:
Prompts the user for the file path
Check to see if the file names differ
Check to see if the ...
-1
votes
1answer
469 views
How to create a function in Powershell script?
How to write a function to avoid Repeated code for my powershell script, which basically display list of application installed on my machine from Add and Remove window present in control panel.
Below ...
0
votes
0answers
48 views
Function not Returning Data
I am using PowerShell to compare the file count and size (per file extension) in 2 separate directories.
$User = $env:username
$pwd = pwd
clear
write-host "`n"
write-host "`n"
write-host "`n"
write "...
2
votes
1answer
634 views
Functions in Powershell - can they be called within a string?
I'm loving how functions can vastly reduce the busywork within Powershell scripts, and they've saved me a ton of redundant coding. But I'm now having issues invoking a declared function within a ...
1
vote
4answers
6k views
How to pass arguments in Functions Powershell
i have below ps script
Function Publish
{
Param(
[parameter(Mandatory=$true)]
[String]
$RELEASEDIR,
[parameter(Mandatory=$true)]
[String]
$SERVICENAME,
[parameter(...
0
votes
1answer
283 views
Passing Excel type Variable into PowerShell Function
I'm basically trying to create a Power Shell function which takes in a variable set to an excel worksheet and returns the last used row and column.
I know the code works outside of a function. Here's ...
0
votes
1answer
928 views
Use Alias only for parameters in function
How can i use alias only when i call my cmdlet function ?
This is my code
Function Deploy-Citrix {
[cmdletBinding(SupportsShouldProcess=$True)]
Param(
[Parameter(Mandatory=$true)]
[Alias("...
0
votes
2answers
708 views
Wrap existing powershell script as function?
I have a script like this:
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
$Message
)
Write-Host "Hello, $Message!"
But I want to provide a method that allows users to dot source ...
0
votes
1answer
73 views
PowerShell | call a function when a variable's value changed
Not sure, how to accomplish this.
$a is a variable.
Tf() is a test function.
a gets values assigned in runtime within another function.
Whenever value of $a change, I want to call tf($a) where dollar-...
0
votes
0answers
77 views
powershell function treats nested object (each of them with one row) as one object
I have something like this now (Powershell v3):
Function (saved as file):
function global:Send-MailWithFormattedTables{
param(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true)] [...
2
votes
4answers
331 views
Get the last line of a specific function in a .ps1 file
I want to get the last line of a specific function in a .ps1 file. I already accomplished this with powershell v3 code:
function GetEndLineNumber($ParseFile, $functionName))
{
$AbstractSyntaxTree ...
16
votes
2answers
11k views
PowerShell changes return object's type
I am using PowerShell v3 and the Windows PowerShell ISE. I have the following function that works fine:
function Get-XmlNode([xml]$XmlDocument, [string]$NodePath, [string]$NamespaceURI = "", [string]...
1
vote
1answer
1k views
Can't add element in array with powershell function
I have a strange problem, i have a very simple function.
This is my powershell code
$exclude = @()
function GetOracleDb {
param([string]$servername)
$exclude += $servername
}
GetOracleDb "...
4
votes
1answer
12k views
Passing DateTime as a parameter
I've read widely that I can pass in an argument to my powershell script via:
param (
[Datetime]$argument
)
I've also read that I can define a default value:
param (
[Datetime]$argument = ...