Quantcast
Channel: PowerShell
Viewing all 15370 articles
Browse latest View live

Rsync bat to powershell

$
0
0

Hi,

I was wondering if someone could assist me on changing the one liner bat script to powershell, the issue is that every time i run the bat it requires elevated permissions. I was wondering maybe converting to powershell and forcing it to run without UAC?

Text
ShadowSpawn.exe "C:\Users\Windows10-PC\Documents\Archivos de Outlook" K: robocopy K:\ "\\192.168.3.253\shares\folders\backuppst" /mir /FFT /R:3 /Z /LOG:\\192.168.3.253\shares\folders\backuppst\robocopy.log

Thank you


Automated FTP (WinSCP) - Email Notifications

$
0
0

Hi All,

I've created a powershell script that leverages WinSCP for automated FTP uploads.
The output is saved as a .txt file and then attached to an email and also input into the email body.

The problem is with the text file that's input into the body of the email.
The text has all of it's formatting removed. This makes it very difficult to read but the attached .txt file's formatting remains intact.

Any ideas on how to preserve the formatting of the text file in the body of the email?

Text
# LOG FILE $LogDir = "c:\scripts\ftp\log\" $LogFile = "$LogDir\ftp.log" $ScriptFile = "C:\scripts\ftp\scp_script.txt" # SMTP SERVER $EmailFrom = "xxxxx" $EmailTo = "xxxxx" $EmailSubject = "FTP Transfer Summary" $SMTPServer = "xxxxx" # Execute WinSCP and call text document & "C:\Program Files (x86)\WinSCP\WinSCP.com" "/script:$ScriptFile" | out-file...

Parse text and export to csv file

$
0
0

I will try to show the sample file how it looks :

timestamp : 201812171505
streams : Total : 579 461 0 0 24 80 0 5 9
ABC : 630
A-1 : 98
B-2 : 87
C-3 : 0
D-4 : 0
E-5 : 238
timestamp : 201812171840

stream : Total : 476 372 0 0 20 74 0 10 0
ABC : 511
A-1 : 80
B-2 : 77
C-3 : 0
D-4 : 0
E-5 : 186

#The output I am looking for is somewhat like this

timestampABCA-1B-2C-3D-4E-5
201812171505630988700238
201812171505511807700186

I have tried couple of things , but it shows error everytime, not sure how to create the regex for this.

Tried using convertFrom-StringData, but no luck.


Powershell script to remotely query servers - Error

$
0
0
Spiceheads,
I am attempting to write a powershell script that I can run against remote machines that will show run the following commands against a list of servers:
Net view, net use, net session
I am attempting to establish a baseline of activity as to what and who our servers are connected too. However when I run the script I get an error about a parameter missing, but I don't believe it is?
The script I have come up with so far is:
Powershell
$Cred=Get-Credential$Servers=Get-Content-Path"C:\Scripts\Baseline_Activity\servers.txt"foreach($serverin$servers){Invoke-Command-ComputerNames$Servers-Credential$Cred-ScriptBlock{netview;netuse;netsession}|Out-File-FilePath$FilePath-NoClobber-Append
Here is the error:
Powershell
Invoke-Command:Aparametercannotbefoundthatmatchesparametername...

PSSession Not Working to Server

$
0
0

Came into the office this morning and had a few changes I didn't want to wait for our O365 Hybrid to sync with our on-prem. so I opened Powershell and typed the following:

PS C: New-PSSession - ComputerName Server01

Clicked "Enter" and nothing happened for about 10 minutes. I CTRL-C the command and attempted;

PS C: New-PSSession -ComputerName Server01 -Credential user@mydomain.com

Entered the credential info and same result.

I restarted my pc and tried again with the same result.

I then hoped on another server and started a new PSSession and it worked perfectly. So if server-to-server works but my machine cannot connect to either server then the issue is on my machine somewhere.

I have used Powershell PSSessions for over a year now and everything worked fine up until this morning when i came in.

No updates were installed and no big changes had...

Scripting Help!

$
0
0

Hi All,

I'm new to PowerShell and I'm trying to use a list provided by my company to input all the managers into AD using PowerShell. The list contains 1723 users DisplayNames and their managers (Two columns). I saved the list as a .csv file and ran this script to pull their SamAccountNames:

Powershell
Import-Moduleactivedirectory$displayname=@()$names=get-content"c:\user.txt"foreach($namein$names){$displaynamedetails=Get-ADUser-filter{DisplayName-eq$name}-server"Domain name "|Selectname,samAccountName$displayname+=$displaynamedetails}$displayname|Export-Csv"C:\Samaccountname.csv"

However, the output list only shows 1428 users. In AD it might show Alex but in the first list it shows Alexander. I'm assuming PowerShell doesnt see Alex as Alexander and skips in and doesn't put it in the output list. Is...

get-ciminstance on remote computers from CSV

$
0
0

Hey guys,

Ive been working on a little something to check if laptops are being charged at night using the get-cimInstance cmdlet to get the battery status whether it's discharging the battery or on AC power.

This is what I put together and in the curly brackets gets exactly what I need and writes it to the csv:

$computers = import-csv 'filepath'

foreach ($computername in $computers)

{get-ciminstance win32_battery -computername $computers -Property Description, BatteryStatus, SystemName |Select systemname, description, batterystatus | Export-CSV 'filepath'}

I'm still relatively new to Powershell and may be delving too deep too quick, still im curious. Now, i'm trying to import computer names from a CSV, and thats where I hit my roadblock. I'm not asking for someone to write this for me, but some ideas/info I can play with to get this to work....

UIAutomation.dll not found

$
0
0

Hi, 

I have a requirement for automating a window application which is running in another RDC machine, for that I am using powershell to automate. 

When I search google I found this solution using UIAutomation package we can automate that, but I am not finding the dll( UIAutomation.dll ) file in the package which I have downloaded from the below website:

https://archive.codeplex.com/?p=uiautomation

Could you help me on this?

Best Regards,

Shanmuka


Command to remove the last 3 pages of 3500 PDFs

$
0
0

Might not be possible but thought id check anyway. we have 3500 PDF's that are sent to a bank on these PDFs the last 3 pages are redundant. To save everyones time energy & paper i'm looking for a way to remove the last 3 pages from everyone of these documents. 

I was thinking maybe some sort of print command that would scan a folder and print every document in there? but i don't think that will work as some of the PDF's are 5 pages and some are 9 pages but its always the last 3 pages that aren't needed.

BGINFO to Text File or Alternative

$
0
0

Hello, 

We are currently using BGINFO to display the following information on the desktop:

Computer Name:
UserName:
TeamViewer ID: (Reg Key)
Model:
IP Address (This is populated using an VB Script)

However due to security changes we no longer want this information displayed on the desktop and our plan is to have this information in a TXT file on the Start Menu (This is the easy part)

However I am struggling to get this information to write to a txt file, does anyone know what is the best way to get the information above to a txt file so user can click on this and find there details.

Thanks

Dave

PSSession / Invoke-Command

$
0
0

I'm trying to learn how PSsessionsand invoke-command works. I've enabled psremotingon a PC, and have run the test cmdlet. Though, I seem to be running into some issues.

One of the things I'd like to be able to do is open an application on a PC. I've tried the following, as per a guide told me, but it seems to do nothing to the remote PC.

Powershell
invoke-command-computername$pc-ScriptBlock{Start-Processnotepad.exe}

If I start a new PSsession and just run the bit in brackets, it runs the command on my PC.

I looked into alternatives to what I'm trying to do (hide the contents of a remote kiosk screen and/or display a window/message covering a significant enough portion of the screen - long story)

Powershell
$shell=New-Object-ComObject"Shell.Application"$shell.minimizeall()

Again, this does absolutely nothing to the computer....

Powershell: Equivalent of Public Variables?

$
0
0

So I'm looking to basically have a little on/off boolean type variable in the script that will be default set to off however if some specific events in my script are hit, I will change the value say from 0 to 1. At the very end of the script, if it's set to 1 maybe I get have a warning message pop up or something. Here's an example that has nothing to do with my actual code:

Powershell
functiondoSomething($userInput){$retVal=$userInput+45if($retVal-lt45){$MyVal=1}return$retVal}functiondoSomethingElse($someValue){$arrSomething=Get-Printerif(!($arrSomething-like"*$someValue*")){$MyVal=1}}functionmain{$userInput=23$someValue=doSomething$userInputdoSomethingElse$someValueswitch($MyVar){'1'{Write-Output"Something went wrong"}'0'{Write-Output"No errors encountered"}}}main

So in this...

Script for transfering user profile folders to new computer

$
0
0

Hello everyone I have a script I am trying to run to back up folders from user profiles and migrate them onto a new machine. The back up process works and stores all the correct data. When it is writing it to the new computer however it either does not get properly placed or it gets renamed as a .old folder right away. Any help would be greatly appreciated.

Powershell
$destination="G:\Backup"$folder="Desktop","Downloads","Favorites","Documents","Music","Pictures","Videos","AppData\Local\Mozilla","AppData\Local\Google","AppData\Local\Microsoft\Outlook","AppData\Roaming\Mozilla","AppData\Roaming\Microsoft\Signatures","AppData\Roaming\Microsoft\Outlook"###############################################################################################################$username=gcenv:username$userprofile=gcenv:...

supress confirm in powershell

$
0
0

hello all I have powershell command to run in command prompt.

i have added -confirm switch as well but it prompts for confirmation

Any suggestions


Quick test for "any" null variable...?

$
0
0

So I have a series of inputs that are captured in Variables. Let's say $Var1 through $Var9

What I need is to have all variables with "something" in them. These are strings.

I can test each $Var and see if it has something in it, but I'm trying to see is any of them is empty. I would prefer not to do about 10 if statements, but I can't think of another way.

For example, I can do:

Powershell
If($Var1-like$Null){Write-Output"Error no data"}

Or

Powershell
If($var2.length-gt0){Write-Output"There's something here..."}

But I would rather not make 10 test conditions. Is there an "If any of these is empty" test? Or do I need to test each variable in a separate test condition?

(I know I can do it where an IF statement has multiple conditions, but... I'd prefer one test for all variables rather than 9 tests whether they are in 9 IF...


Monitor for Process and Display a Warning

$
0
0

I have a powershell script that I have written that will monitor for a process and if the process is detected it displays a dialog box with a warning. If the user accepts the warning (Yes) the dialog closes and sleeps for 4 hours, if the user declines the warning (No) the dialog box closes then closes process in question and returns to monitoring for that process to be launched again.

It is monitoring for the update checker used by a 3rd party vendor. The warning is a reminder to whomever starts the update checker that they should not be running service packs without first following another internally defined process relating to the SQL database or bad things will happen.

The script works just fine if I run it manually, but I am having trouble finding a reliable way to run it automatically.

I have tried applying it as a logon script VIA...

Bitlocker backing up key to AD

$
0
0

Am in the middle of designing a script to enable Bitlocker among all our staff and backup the recovery key to AD.

Here's the basic snippet (there are safety measures to prevent encryption if hardware does not meet specifications that have been omitted for simplicity):

Powershell
#Enabling EncryptionEnable-Bitlocker-MountPoint$env:SystemDrive-UsedSpaceOnly-RecoveryPasswordProtector#Getting Recovery Key GUID$RecoveryKeyGUID=(Get-BitLockerVolume-MountPoint$env:SystemDrive).keyprotector|where{$_.Keyprotectortype-eq'RecoveryPassword'}|Select-Object-ExpandPropertyKeyProtectorID
Powershell
#Backing up the Recovery to AD.manage-bde.exe-protectors$env:SystemDrive-adbackup-id$RecoveryKeyGUID

I have been able to get encryption to work. However I cannot backup the key to AD. By the looks of it, $RecoveryKeyGUID...

How-To using PowerShell Workflow

$
0
0

I'm new to WorkFlow.

What I trying to accomplish is:

1. Fill the $UserList variable with all AD Users that are enabled

2. Use a workflow to fill an array with some attributes from all users with the word "complete" in the OtherPager attribute.

Here is the code I am using:

cls
"Date and time is: $((Get-Date).ToString())"
workflow Get-users {
$UserArray = @()
$UserList = Get-ADUser -Filter {Enabled -eq $True} -Properties * -Server domainC1.contoso.com -searchbase "OU=Outside, OU=Clients, DC=contoso, DC=Com" -SearchScope Subtree

ForEach -parallel -throttleLimit 50 ($User in $UserList) {
if ($_.OtherPager -NotLike "*complete*") {
$workflow:UserArray += $_.name, $_.DisplayName, $_.Manager, $_.Created, $_.LastLogonDate, $_.PasswordLastSet
} #end if
} #end for each
$UserArray
} #end workflow

get-users | format-table
"Date and time...

Is it possible to run a complex script against a mounted image?

$
0
0

I've been using Disassembler's script to clean up windows 10. It works great when running it on a windows machine. However, I am trying to create a golden image that's already cleaned up, so nothing has to be done after installation. I used the DISM command in powershell to mount the image I'm crafting. Is it possible to somehow direct the Disassembler script to run against the mounted image?

Powershell script to gather AD Group membership and update a csv

$
0
0

I am working on a project where I need to know if an employee is a member of a particular group.

I get a csvfile from HR with First,Last,JobTitle,Username

The username in the file DOES match ad usernames so that is a plus. I need to loop through that csv and check to see if that user is a member of a particular group. If I could write that result back the same csvfile that would be awesome.

I have been working with this script

Powershell
$imported=Import-CsvE:\bin\Active020119.csv$Output=foreach($iin$imported){{(Get-ADUser$importedPropertiesMemberOf|Select-ObjectMemberOf).MemberOf}$i}$Output

But it is only looping through the csvand not checking groupmembership. Has anyone accomplished something similar?

Viewing all 15370 articles
Browse latest View live


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