Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

how do I code a clipboard viewer using PowerShell ?

$
0
0

How do I code a clipboard viewer using PowerShell ?

In other words, I'd like a window open that always shows the text content of the clipboard, and ideally also lets me search within it for specific text.

If the content of the clipboard changes Ideally the text within the window changes soon afterwards.


where is --% syntax documented ?

$
0
0

At some point the --% syntax was introduced (see example below) for turning off PowerShell interpretation in a command.
Where is the documentation for that syntax?   Is it possible to use --% as a search term in a search engine like Google?

<#c:#> cmd /c attrib --% Larry's_file.txt
A       I    C:\Users\Larry\Documents\WindowsPowerShell\Larry's_file.txt

Internet Explorer COM Automation Not Working

$
0
0

I've been searching for a solution to this for a while and I'm stunned and embarrassed I haven't found more helpful pages with information how to solve this problem for myself.

I have a few different scripts that spawn an instance of IE, navigate to the page, then update and click elements.  They work fine with IE 8, but nothing newer.  

$ie = New-Object -comobject InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate($URL)


This works fine.  I can type $ie.document | gm at the console and see getElementById, getElementsByClassName, etc in the list of methods and properties, but if I try to access them I get an error:

Cannot find an overload for "getElementsByClassName" and the argument count: "1".
At line:1 char:36
+ $ie.document.getElementsByClassName <<<< ("input")
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

I found this link:

http://stackoverflow.com/questions/17924770/how-can-i-translate-or-run-a-vbscript-function-inside-a-ps1-file

That gets me a little bit further:

$EmailField = [System.__ComObject].InvokeMember("getElementsByClassName",[System.Reflection.BindingFlags]::InvokeMethod, $null, $ie.document,"email")


If I output $EmailField I get a long list of properties that includes:

type                         : email
value                        :
name                         : email

But when I try to edit $EmailField, I get another error:

PS C:\Users\user> $EmailField.value
PS C:\Users\user> $EmailField.type
PS C:\Users\user> $EmailField.name
PS C:\Users\user> $EmailField.value = "email@email.com"
Property 'value' cannot be found on this object; make sure it exists and is settable.
At line:1 char:13
+ $EmailField. <<<< value = "email@email.com"
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Also from the previous site I tried using the similar method as above:

[System.__ComObject].InvokeMember("value",[System.Reflection.BindingFlags]::SetProperty,$null,$EmailField,"email@email.com")


But that caused another error:

Exception calling "InvokeMember" with "5" argument(s): "Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNO
WNNAME))"
At line:1 char:34
+ [System.__ComObject].InvokeMember <<<< ("value",[System.Reflection.BindingFlags]::SetProperty,$null,$EmailField,"emai
l@email.com")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I found another link that mentioned a missing microsoft.mshtml.dll and related it to this problem with IE without Office installed, which I can't find now, but copying that file and loading it didn't make any difference in the behavior.

I can't believe I'm the only one having this problem...anyone have an idea how I can access the IE Com object on newer versions? 


I hope this post has helped!

Get smtp server details

$
0
0

Hi All

Cant beleive I havent found this online allready

All I need to do is find the outgoing smtp server but cant see this in outlook 2013 Ive tried the account settings menus

Didnt get the correct answer from nslookup either!

I feel there shoud be a way to query this using powershell

Anybody know?

Thanks for reading


confuseis

disabling password complexity via powershell

$
0
0

hi friends

i spent lots of time searching entire internet to find a command or script (powershell, cmd, VB, registry...) to be able to disable password complexity. there are few solutions which none of them works.

i wonder how what a pity if we can't do such simple thing in Microsoft windows

i really need that because i have created a script which contains many lines which automates windows customization which i always need in my classrooms for testing & teaching purposes

thanks for any help

Reading log file and calculating time between

$
0
0

If someone could help me with this one, I would be very grateful.

I have a log file and I need to search a string that contains a start time and end time (eg. <time="11:10:58.000+000">). When I have these two values, I need to measure the time that has been elapsed between these two (from start to end).

SSH HostKey Fingerprint

$
0
0

Hi I am using the code below for SFTP upload to a SFTP server using WinSCP assembly. My code is running on Windows Server 2008 R2 Standard. This code has a line that asks a value for "SshHostKeyFingerprint". Now, I noticed when i connected SFTP server for the first time, a fingerprint showed up, and I had to accept as yes. I believe this fingerprint is stored somewhere in the server.
1. How to find this fingerprint from the system in the format for powershell?
2. Where this fingerprint is located in the server?


------------------
try
{
    # Load WinSCP .NET assembly
    [Reflection.Assembly]::LoadFrom("WinSCP.dll") | Out-Null
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "example.com"
    $sessionOptions.UserName = "user"
    $sessionOptions.Password = "mypassword"
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        # Upload files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
 
        $transferResult = $session.PutFiles("b:\toupload\*", "./", $FALSE, $transferOptions)
 
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}

------------------







get user detailes from Active directory windows 7/8

$
0
0

is there a way to get user that logged in, this email from the active directory

with out installing the "remote server administrative tools"?

i want to access some fields, when user logs in, to set logon script in the gpo, and do some things.


using "-whatif" parameter for a collection of commands

$
0
0

hi friends

imagine we write a PS script which contains multiple commands which will be executed one by one.

for example command1; command2; command3;......

how can we use whatif for the entire collection of commands? i don't want to write -whatif parameter for each one separately.

need a trick to write -whatif only one time, but it be applied to all commands in turn & shows the result of each command in turn.

thanks

assigning bulk license to Office 365 AD synced users

$
0
0

Hi,

We need to assign bulk office 365 license to more than 5K users. Users are already synched by Dirsync server and we only need to apply license. Our users use Exchange onprem and we need to exclude exchange online license from the E2 plan. So we want only, Lync ,Off web app and  share point. I have prepared the below script it doesn't make any changes even though it doesnt show any error. I appreciate your help 

  $Step1 = New-MsolLicenseOptions -AccountSkuId mycompany:STANDARDWOFFPACK_FACULTY -DisabledPlans EXCHANGE_S_STANDARD

Import-Csv .\UPN.CSV | foreach {set-MsolUser -UserPrincipalName $_.UPN -UsageLocation SA}

Import-Csv .\UPN.CSV | foreach {Set-MsolUserLicense -UserPrincipalName $_.UPN -AddLicenses mycompany:STANDARDWOFFPACK_FACULTY -verbose -LicenseOptions $Step1}

I followed the below link

http://community.office365.com/en-us/f/148/t/263052.aspx?ss=6818e221-4ad2-45e4-bf3e-ec8451732a99

get-winevent by IDs limited to 23 items

$
0
0

It seems the ID in filterhashtables for get-winevent is limited to max of 23 items in the array.

Please test this out to see

# there are 23 items in the list.  the last id is a real id that will return results so you can see.
# just hit ctrl-C to cancel since it could take a long time to list all those events
$IDs = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,4648
get-winevent -filterhashtable @{logname="security"; ID = $IDs}

# now add a 24th item to the list and run cmd again and notice you get no results
$IDs = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,4648,24
get-winevent -filterhashtable @{logname="security"; ID = $IDs}

WHY?  Seems to be a hardcoded limit that is undocumented?


How to retrieve Powershell Array Value

$
0
0

how to retrieve the value from array and pass it column by column...

below is the query:

$DbList=Invoke-Sqlcmd -Query "SELECT Name FROM sys.databases" -ServerInstance "QASER\RTYRE"
$DbList

--Output
Name
----------
DB1
DB2
DB3

$DbList[0]

--Output
Name
------
DB1

I want to just retrieve the "Value" not the "Value along with the column Name"

in other words, I want to see output as

"DB1" but not like

"Name

----------

DB1"



Hope it Helps!!


WindowsPowerShell has stopped working

$
0
0
I am using a new HP Envy laptop running windows 8.1 and am constantly receiving the message, "Windows PowerShell has stopped working". I continue to close it, but it reappears almost immediately. Any suggestions? Thank you!

Copy-Item to 'N' remote machines in parallel

$
0
0

Hi,

I want to copy a folder recursively from my local machine to 'n' remote machines parallely.

I tried the following:

$remoteMachines ='MachineA', 'MachineB', 'MachineC'Invoke-Command-ComputerName $remoteMachines -ScriptBlock{Copy-Item-Path"\\MachineZ\C$\Sample.txt"-Destination"\\$_\C$\" -Verbose
	}

MachineZ is the machine from which I'm running the above script.

And this one ended up with the following error message:

Access is denied
    + CategoryInfo          : PermissionDenied: (\\x.x.x.x\..Sample.txt:String) [Copy-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
    + PSComputerName        : MachineA
 
Cannot find path '\\192.168.172.219\Public\Aravind\invoke-parallel.txt' because it does not exist.
    + CategoryInfo          : ObjectNotFound: (\\x.x.x.x\...Sample.txt:String) [Copy-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
    + PSComputerName        : MachineA

(Same error message repeated for MachineB and C as well). The machines are in the same domain logged in with the same user account itself.

Am I doing it right ? This is after I tried Copy-Item with the Invoke-Parallel cmdlet. It works at times, but not reliable due to runspace issues and at times, some of the stuffs do not get copied, cannot rely on that.

Thanks in advance,

/Aravind

causing Read-Host to open a Graphical Box to enter something in it

$
0
0

hi friends

in PS 4.0 when we execute  $number=Read-Host "please enter a number"  ,  system asks to enter a number in powershell.

is it possible to do a task so that instead of asking for number in powershell console, a graphical box be appeared & the user type the number in it ?  ( something like the box which appears when we runGet-Credential)

thanks in advanced


using a variable in netsh command to set ip address on NIC

$
0
0

hi friends

i wrote an script which gets an input & use that variable to set ip address on NIC. but actually it doesn't set ip address. may you please help me.

my script contains:

$VMNumber=Read-Host "please enter your VM number (for example 2)"

Netsh interface ipv4 set address NIC static 192.168.1.$VMNumber

Install-WindowsFeature -name server-gui-mgmt-infra -source D:\sources\install.wim

$
0
0

I have a windows server 2012 r2 core installation (test machine), im trying to convert the server to full gui.

I tried issuing the command

Install-WindowsFeature -name server-gui-mgmt-infra -source "wim:\D:\sources\install.wim:4" or

Install-WindowsFeature -name server-gui-mgmt-infra -source "\D:\sources\install.wim"

where d: is the windows server 2012 r2 installer disk.

from powershell, however i'm getting an error message where the source parameter is incorrect, but the link 

http://technet.microsoft.com/en-us/library/jj205467.aspx

says i can point it to a wim file

any ideas?


For God, and Country.

Displaying Chinese in Powershell and Powershell ISE

$
0
0

I have a PS that retrieves file names and URLs from webpages, download files, display file names and download progress on screen and save files on disk.

file names are Chinese and were displayed correctly in Chinese both in Powershell console and in Powershell ISE before. But now they are displayed correctly only in Powershell ISE, not in Powershell console anymore. Any suggestion? thanks

 

Use powershell to read Environment tab checkbox from ADUC

$
0
0

Hello all,

In ADUC, when you pull up a user, you can see an "Environment" tab, which contains a checkbox for "Start the following program at logon:". Here's a picture:

What I would like to do is use PowerShell to see if this checkbox is checked for a user. In my Google searches however, I have found that this checkbox is contained in the infamous "UserParameters" attribute.

My question is, what is the best way to see if this checkbox is checked for a user using PowerShell? Is this checkbox contained in any other attribute that PowerShell can read, or will I need to parse the UserParameters attribute to see if it's checked?

Importing variables in Powershell

$
0
0

Hi,

Actually in vbscript:_include\Constants.lib

x= variable

Main.vbs

Function Include(scriptFilename)
 Dim fso, f
 err.Clear
 On Error Resume Next
 Set fso = CreateObject("Scripting.Filesystemobject")
 If fso.fileexists(scriptFilename) Then
  Set f = fso.OpenTextFile(scriptFilename)
  err.Clear
  ExecuteGlobal(f.ReadAll())
  f.Close
 Include = (Err.Number = 0) ' set return code as True or False

End Function  

Now I am trying to figure the samething in Powershell.

_include\Constants.lib

$Emplacementtrousse="c:\temp"

Main.PS1

??

What should I do to make all variables and function existing in constants.lib available in my main script? At the end of the main scripts all variables and functions must be release.

Thanks,

François

Viewing all 21975 articles
Browse latest View live


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