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

Set focus on Desktop

$
0
0

I can set focus on a open window by using bellow. Is there a way to set focus on desktop?  I do not want to minimize all windows. In stead, just like if I click on desktop, all open windows will lost focus. Thanks

$a = Get-Process iexplore | ? {$_.MainWindowTitle -eq 'Webpage name - Windows Internet Explorer'}

[Microsoft.VisualBasic.Interaction]::AppActivate($a.ID)


Combining selection criteria problem

$
0
0

I am trying to get just the filename which is the title of the song in a m3u playlist file. I have a working command that gives me just the filename but it includes the extension. I would like to have it return just the filename without extension. my command for going through the playlist .m3u file is as follows

    Get-Content 'C:\Users\Trent\Music\Playlists\3LW.m3u' |  ? { $_ -and (Test-Path $_) }

I have seen the Basename method talked about but I am not sure how to add it to my command so it works. I tried

    Get-Content 'C:\Users\Trent\Music\Playlists\3LW.m3u' |  ? { $_ -and (Test-Path $_) } | {$_BaseName} but that either gave me error messages or nothing at all. I am satill trying to learn the syntax in powershell so don't be too hard on me please.

Get-mailbox all users except those in csv list

$
0
0

Hello, please someone help.

I have a LIST.CSV of users want exclude.

_________________________________

;SimpleDisplayName;
;user1;
;user2;
;user3;

_________________________________

Need something like:

$exclude = get-content LIST.CSV

$users = Get-mailbox -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (SimpleDisplayName -notlike '$exclude')}

Thanks in advance

GPO report

$
0
0

Hello all

I am trying get a GPO report of the Security Filtering of the GPOs in the domain

This line

    $SecurityFilter = ((Get-GPPermissions -Name $GPOItem -All | ?{$_.Permission -eq "GpoApply"}).Trustee | ?{$_.SidType -ne "Unknown"}).name -Join ','

Return the group but only if there is one group, if the GPO has more that one filtering return nothing...

Somebody can help me?

Thanks

Compare 2 CSVs and Export Merged Results

$
0
0

Hi All

I am trying to move a large group of FTP User Accounts to new Sub OUs based on the names of the objects. for example anything named CIS_<name> will be moved from GENERAL OU to GENERAL OU > CIS. However I have 2 CSV files which I need to merge together and then export to a csv and then I can run the powershell command. I have made a start but I am stuck. Here are the 2 CSV's

CSV 1 contains SamAccountName, Description and NewPath (NewPath is the new OU Location)

CSV 2 contains SamAccountName and DistinguishedName

Merge 2 CSVs together matching the SamAccountName and then add the rest of the data to the correct rows.

Desire Result CSV =  SamAccountName, DistinguishedName, Description, NewPath

What I have so far (it is not complete yet)

$ftpuserscsv = import-csv C:\ps\import\ftpusers.csv
$ftpdncsv = import-csv C:\ps\import\ftpdn.csv
Compare-Object $ftpuserscsv $ftpdncsv -property samaccountname -IncludeEqual | select * | Export-csv C:\ps\exports\ftp_complete.csv –NoTypeInformation
$csv = import-csv C:\ps\exports\ftp_complete.csv
foreach ($row in $csv){
Move-ADObject $row.distinguishedName -TargetPath $row.NewPath
Please Help!




Strange behaviour of Powershell on one DC

$
0
0

Dear all,

Recently I've add new DC to infrastructure (in the same way like other DC's). Cause it is the closest DC for me very often I am using it to for Powershell with ADModule jobs to do.

What is strange: (Tested on Powershell with AD module run normally and as an administrator) I am logged to this particular DC which have problem.

Get-ADUser -Filter * -Properties gidNumber, uidNumber -SearchBase "Path" | ft gidNumber, uidNumber

I've got as result no value for these parameters. So I decrease scope of filter to only one user

Get-ADUser -Filter 'samAccountName -eq "username"' -Properties gidNumber, uidNumber -SearchBase "Path" | ft gidNumber, uidNumber

Still no result

Doing the same commands but with switch -server

Get-ADUser -Filter 'samAccountName -eq "username"' -server otherdc.domain.com -Properties gidNumber, uidNumber -SearchBase "Path" | ft gidNumber, uidNumber

I am getting results as I expect.

When I am login to other DC and do the first two commands I've got result as I expect.

Funny is that if I am going to this problematic DC and looking for this info via console Active Directory Users and Computer (connected do problematic dc) -> user -> attributeEditor I can see values which I am looking for :)

Other strange thing is that if I am connecting from other server with Powershell with AD Module and doing the command like before with switch to problematic server I got proper values.

I think it may be related somehow with UAC but it should not appear when I start PS as Admin.

Second strange thing on this DC is that sometime when I trying to do some Set-commands as return I got info about insufficient rights to perform this operation (I mean when I am doing it directly from machine) but If I will use switch -server otherdc.domain.com everything works :):)

ExecutivePolicy is set to Unrestricted.  Account which I am using is a domain Admin,

Do you have any idea of strange behaviour of Powershell on this DC? Maybe I forgot about something?

Thank you in advance,

BR,

Sebastian,

SQL Agent job step fails after upgrading to Powershell 5

$
0
0

I have a brand new HP DL380 running SQL Server 2008R2 standard. It's not yet in production, and I'm testing SQL Agent jobs. The server is running Windows Server 2012R2 Standard, and came with Powershell 4 installed.

I upgraded to Windows Management Framework 5 (Powershell 5), ran the first script through Powershell ISE and everything was ok. Then I executed the same script from SQL Agent and it failed with: "The term 'New-Object' is not recognized as the name of a cmdlet, function, script file, or operable program."

The job step is a CmdExec type, uses a proxy account, and calls powershell.exe to execute the script. If I make the proxy account a member of the local administrators group it works. If I roll back to Powershell 4 it works (no other changes than uninstalling WMF 5). But if I again upgrade to Powershell 5, the job step fails.

It's obviously some type of permissions issue, but there is no clue as to what part of the security universe to investigate.

Jobstep command:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "D:\dbsoftware\Insert-Records.ps1 -InsertType LogCopyOnly" 

Thanks in advance for any suggestions.

Need help with script to list all users in domain with access to drives

$
0
0

Hi all,

is there any PS v2.0 script to list all users in the domain who has access to each of the network shared drive?

thank you in advance all

c0nst4




convert tiff to pdf

$
0
0

Hi I need some help to finish one script...

this script use the tiff2pdf.exe

we have to use it like it :

tiff2pdf source -o dest.pdf

My script is ok, but I need to rename correctly the outpout file.

$a=Get-ChildItem C:\source -Recurse -Include *.tiff
foreach($b in $a) {
    c:\test\tiff2pdf.exe $b -o $b.pdf
}

This is not ok...

Don't create anything

$a=Get-ChildItem C:\source -Recurse -Include *.tiff
foreach($b in $a) {
    $new = $b.BaseName
    c:\test\tiff2pdf.exe $b -o "$new.pdf"
}


PS2Exe not working for Script calling another script

$
0
0

I am trying to create a tool for our internal team using Powershell.I have different individual scripts which should be called from the main script.I would like to convert the complete scripts to exe using Ps2Exe ,so that no one else can alter the contents.Please find below what I have done using Ps2Exe converter.

1)I put the content of Scr1.ps1 as below

Ping Microsoft.com >>d:\out.txt

2)Converted Scr1.ps1 to Scr1.exe using Ps2exe
3)Created another PowerShell file ,Scr2.ps1 with the below content 

 & "D:\Scr1.exe"

4)Convert Scr2.Ps1 to Scr2.exe
5)Tried to run Scr2.exe and  it didn’t work
6).I tried to Run Scr2.ps1 and it worked, It also called Scr1.exe and generated the output to D:\Out.txt

Can someone please tell me whether I need to do anything else to call another exe during Ps2Exe conversion?

 

Powershell - Export permissions for folder and share?

$
0
0

I need to export all the share and folder level permission on one of my windows 2008 file servers. I have tried the command below and it give me all the folder and file level permissions.

Get-ChildItem "X:\Share" -recurse | Get-Acl | export-csv c:\djk\share_folder_permission.csv

I dont want file level permissions, only share and folder level.  Can you help?

 

 

Default Property Name of Any CmdLet

$
0
0

Hi,

Is there a way to get default Property name of any cmdLet.

I am Creating a ExportTo-Excel Function.

So I need the name of the Property which is displayed by default of any cmdlet.

I tried Get-Member but didn't find anything.

Ex- 

Get-Process - Handles , NPM(K) ,PM(K), WS(K), VM(M),CPU(s),Id,SI,ProcessName

Get-Service - Status, Name ,Displayname

These are the properties name i need.

Thanks

Wndows Task Scheduler Not Executing PS Script

$
0
0

Hi I have a script which reads files from a network path and uploads to sharepoint library and then moves to another archive folder.

It works fine if I run it manually

When I schedule it, in the task scheduler it says running and then after sometime ready state with (0x1) as code

When I schedule from task scheduler, I have a service account with admin privileges over the network path.

I have given these paramters

Start Program : Powershell

Add arguments : -executionpolicy bypass -Command & {"\\server1\data02\spscandocs\spupload.ps1"}

Start in : \\server1\data02\spscandocs

Any idea what I m doing wrong here

S



reboot machine if uptime is more than for x days

$
0
0

Hi , how to reboot multiple machines if uptime on those systems is more than Xdays? I am looking for a script using powershell(not VB).

Thanks in advance.

Get-DistributionGroupMember Recursive Functionality.

$
0
0

I’m looking to create a script that can use a list of groups to go through and get me the members of each group.

Example

$group = Get-DistributionGroupMember –identity “Group Name” | Select DisplayName

Now the content of $group will be a list of Distribution Groups, I need to use this as the input to create a CSV file of all the members of each of the groups in $group.

Can someone help me with this?

Ideally if Get-DistributionGroupMember had a recursive function I wouldn’t need to figure out a way to do this. I have seen a couple enumeration scripts around, but I’m not getting exactly the results I need. Any help would be appreciated.

 


Paul Arbogast

How to use Regular Expression to find SSN and then replace

$
0
0

I found a regular expression in a pattern I think I need for Social Security Number.

(?!000)(?!666)^([0-8]\d{2})(\d{2})(\d{4})$

My files do not have spaces within the numbers or hyphens.

I want to find all SSN in all. txt document in a specific folder and then replace them with X except for the last 4 digits on right.  It would be nice to tell the user how many were found and replaced.  (That might be a bit much to ask I know.)

My folder path is here \\shared\e_drive\Process\Scrub.

Can someone point me in the right direction 1)Excecute this expression and find social sec numbers 2)Replace those matches with all XXXX except last 4 numbers. 3) Message of completion.   Thanks for any help.

I found a couple similar examples via google but not really the same.



Create a Java Script to RUN on a Remote Computer.

$
0
0
I want to create a script which I will use to Run from Powershell on network PCs. It must point to a ComputerName and also the path were JAVA application is stored which can be a server path. If possible it must allow me to Run the script in bulk (meaning running it to more than 2 PCS simultaneously) on networked PCs.
I have tried this but its not working. The script must run silently without users on the network to see and I want it NOT to ask for ADMIN Credentials as it runs. I just don't know how to put addmin on the script all at once so from users PC it does not prompt it.

#Variables


$computername

=Get-ContentC:\PSdeploy\list.txt


$sourcefile

="\\Server\folder\list\Java\jre-8u91-windows-i586.exe"


#This section will install the software


foreach

($computerin$computername)

{


$destinationFolder

="\\$computer\C:\Program Files (x86)"


#This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.


if

(!(Test-Path-path$destinationFolder))

{


New-Item

$destinationFolder-TypeDirectory


}


Copy-Item

-Path$sourcefile-Destination$destinationFolder


Invoke-Command

-ComputerName$computer-ScriptBlock{Start-Process'c:\temp\jre-7u25-windows-x64.exe'}

Use DNS Cmdlets on Windows Server 2008 R2

$
0
0

I want to use the DNS Cmdlets (http://technet.microsoft.com/en-us/library/jj649850.aspx) on a Windows Server 2008 R2
I learned that they are shipped with PS v3. So I installed all prerequisites and finally PS v3.

Despite I'm not able to use those Cmdlets. What else I've to do?

Thanks

Get-Content from variable and use for each

$
0
0

Hello,

Actually what i would like to do is :

Get all list of computers from security group and store that list in variable, after that use for each.

Is it possible to get content from variable and use for each on it ?

$SCCM=Get-ADGroupMember-identity"gPEUT-SCCM2012R2Servers"-Recursive|selectname

$SCCMServers=Get-Content$SCCM

foreach ($DPin$SCCMServers)

Or for each command just can read TEXT array?


Split String to Array

$
0
0

Hi,


I extract line from a ROBOCOPY .log

"
               Total     Copié    IgnoréDiscordance     ÉCHEC    Extras
     Rép :         2         0         0         0         0         3
Fichiers :        16         2        14         0         0         2                                     ($ligne2)
  Octets :    22.3 k     2.7 k    19.6 k         0         0     2.9 k

"

$LigneFichiers=($ligne2.Substring(12))

$LigneFichier   16         2        14         0         0         2

I want to split in 5 group ($a, $b, $c, $d, $e)

I use $LigneFichier for main string to split

I've tried :

$test=$LigneFichiers.split(' ')

$test1=$LigneFichiers.split([char]0x0020)

$test2=$LigneFichiers.split('U+0009')

For $test and $test1 result here

For $test2 result :

.COUNT on $test, $test1 and $test2

-------

$test2[0]

   16         2        14

$test2[2]

    2

Somebody have a solution ?

Kind regards,

Viewing all 21975 articles
Browse latest View live


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