Quantcast
Channel: Windows PowerShell Forum
Viewing all 2562 articles
Browse latest View live

Use Powershell or vbscript to help update my Sophos clients

$
0
0

Hello all,

We hade issues with some of are servers with Sophos installed I now have to perform the actions below on a hundred servers. Has anybody be able to do something similar in PowerShell?

  • Delete agen-xuv.ide from C:\Program Files\Sophos\Sophos Anti-Virus\  [C:\Program Files (x86)\Sophos\Sophos Anti-Virus\]
  • Restart the 'Sophos Anti-Virus Service'
  • Perform a update from the client side. (right click on the Sophos Icon and select update now.)

Thanks,


Getting a complete list of long UNC paths

$
0
0

Hello,

Been looking left and right for an easy to way to do this but I've come up empty handed.

I have about 4TB of data on a file server and I need to have a complete list of all UNC paths that are >255 characters.

I had a simple batch file (dir /s /b "W:\" 1>nul 2>C:\Error-W.txt)that seemed to work but it's definitely not picking up all the paths. Any idea how to do this in Powershell ? I'm thinkin just browsing through the files and folder structure and logging every "path not found" error, but this kind of error handling is beyond my current knowledge. Besides, there might be a better and easy way.

upgrading PowerShell V2 to PowerShell V3 on Windows 7 64-bit

$
0
0

Where on the web are the instructions for downloading and installing PowerShell V3 on Windows 7 64-bit ?

System.Console doesn't work in remote session

$
0
0

In a local console:
[System.Console]::WriteLine("mytext")
...outputs the text.

In a remote console:
Invoke-Command -cn myserver { [System.Console]::WriteLine("mytext") }
...doesn't output the text.

How can I get the System.Console working in remote sessions?

Set a variable as DistinguishedName? (powershell)

$
0
0

I'm fairly new to powershell scripting, and to scripting in general, so this is probably a very easy question. Sorry if there's an answered question out there like this already.

My goal is to create a script that prompts you to enter an existing Active Directory username, and then reports back which users have "Send-As" rights from that Exchange mailbox.

(this part I need help with)
The first part of the script collects the DistinguishedName of the mailbox in question and sets it as variable $dn

$un = read-host "Enter Username"
$dn = $un????????????

(this part I already have figured out)

The second part uses the Get-ADPermission command to report back which users have "send-as" rights. The problem is, due to my organization's active directory structure, I have to use the DistinguishedName of an object for it to work, otherwise the command errors.

Get-ADPermission -Identity $dn | ? {($_.ExtendedRights -like "*send-as*") -and -not ($_.User -like "*exchange*") | ft user,extendedrights

Any help would be appreciated! Thank you!

 - Dan


REG UNLOAD Access Denied in CMD

$
0
0

Greetings,

I'm trying to write a simple batch file to load a hive from another hard drive, create a key, create a subkey, and then unload the hive. It all works well until I try to unload the hive. It says access denied. Here is what I have

REG LOAD HKLM\MINWIN E:\Windows\System32\config\system
REG ADD HKLM\MINWIN\xxxxxxxx\xxxxxxx\xxxxxx /f
REG ADD HKLM\MINWIN\xxxxxxxx\xxxxxxx\xxxxxx /f /v xxxxxxxxxxxxxxxx /t REG_DWORD /d 0
REG UNLOAD HKLM\MINWIN

Also, I am running these commands in cmd (ran as administrator) using windows 7.

Drive freespace percentage

$
0
0

So I'm trying to get freespace percentage output and can't figure out why I'm getting two percentages when I should only be getting one.

This is my input:

$drives = get-wmiobject win32_volume | where-object {$_.drivetype -eq 3 -or $_.drivetype -eq 4}
foreach ($drive in $drives)
{
    $freespace = $drive.freespace/1gb
    $freespace = "{0:P2}" -f $freespace
    write-host $freespace
}   

and the output comes to

25.46 %
11,432.85 %


I don't see where the second percent comes from, I know that I have about 25% left, so this is right but how do I get rid of the second part?

Thanks in advance.

The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration on server xxx

$
0
0

 set-WebConfigurationProperty -filter /system.WebServer/security/authentication/digestAuthentication -location $sitedir -PSPath "IIS:\" -name enabled -value false -ErrorVariable err -ErrorAction SilentlyContinue

when I run above command, got the error:

Filename: \\?\E:\wwwroot\farmTen1.xxx\web.config Line number: 1034 Error: The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration on server xxx

anybody can help me? thanks in advance.



Awen


help needed with environmental variables needing a restart of powershell

$
0
0

hi I am having a bit of a headache over Environmental Variables and would really like some guidance.

I have a script that sets a couple of environmental variables and does a few other things before launching an exe that calls for these environmental variables and installs an application. as it stands it does not work because unless powershell is restarted the variables dont appear to the powershell session (or prehapes the exe).

if i seperate the environmental variables and the calling of the exe in two scripts and run them independently it works.

if i try a launcher the second script for the first script, even in a different window it does not work. I guess the session is maintain between the two windows?

my question is - is there some way round this? Can i set an environmental variable and use it without a ps restart? 

thanks 

james


Problem with External Commands in Powershell

$
0
0

HI together...

I have a script for configuring some Settings on Windows Server 2008 R2...

Everything is working fine but....

I have Problem that when i start PowerShell script (via batch File) for first time after Server new Installation that externel DOS commands (gpupdate,shutdown....) are not working.

But when i start same Script second time everything is working fine....

I Start Script with following Lines in BAtch File:

powershell.exe Set-ExecutionPolicy RemoteSigned
powershell.exe -noexit -command "C:\MYScript.ps1"

When I start Script from Powershell directly and set first execution policy than everythin is workin fine.

Could someone help....help....

How to display boolean $True in output

$
0
0

Hello,

For documentation purposes, I would like to display in my output the value of PasswordNeverExpires, namely $True.  However, when I run the following, nothing displays.  How can I get the value of $True to display?

Get-Aduser -Filter 'PasswordNeverExpires -eq $True' -searchbase "ou=users,ou=External Users and Groups,dc=acme,dc=net" | Sort Surname | Select Surname, Givenname, SamaccountName, PasswordNeverExpires | out-file ExternalUsersPassNeverExpires11_2.txt


Thanks for your help! SdeDot

How to export -Share Ntfs and other AD atrribues for Share permission

$
0
0

I am Trying to pull data in below format from PowerShell , can someone help me with a script :

Sr.   No.

Server   Name

Shared   Folder Name

Folder Current size

Sharing   Rights

Security   Rights

Department

No.   of Users

Division

 Server Name| Shared Folder Name |Folder Current size |Sharing Rights| Security Rights |Department| No. of Users |Division

Anand Shankar


Can I Filter on two attributes with Get-Aduser?

$
0
0

Hello,

I get a parse error on the following.  Can I filter on two attributes or need I say Get-Aduser -Filter * and pipe to a Where clause?

Get-Aduser -Filter {('PasswordNotRequired -eq $True') -and ('PasswordNeverExpires -eq $True')} -searchbase "ou=users,ou=External Users and Groups,dc=acme,dc=net" 


Thanks for your help! SdeDot

Combine Get-ADComputer, Get-ADuser .. and optimalize the script

$
0
0

Hello,
I need to optimize my script

It should select all computer from AD, select attribute ManagedBy and for each user in managedby  it should search for mail,telephonenumber...  

It is working, but i got errors when ManagedBy attribute is empty - because Get-ADUser requires its identity..

Output should looks like:

Name          ManagedBy   TelephoneNumber
P011W7       user1          +420 123 456 789
P012XP                                                   <=  (computer account is with empty managedby attribute.. )
P013XP        user2          +420 558 555 555

Also, i dont know if quering multiple times cmdlet get-aduser is efficient.   If i run this script for 4000 computer accounts, for each account quering 3+  get-aduser ... it would be slow. Any ideas how to optimize that? 

Thanks

$ComputerList = get-adcomputer -filter {(Name -like "P*") -or (Name -like "n*")} -properties * | ?{$_.OperatingSystem -notlike "*server*"} | select Name,@{n="Managedby";e={($_.Managedby -split ",*..=")[1]}}
$Output = @()
foreach ($PC in $ComputerList) {
$MyObject = New-Object PSObject -Property @{
PcName = $PC.Name
ManagedBy = $PC.Managedby
UserEnabled = (get-aduser -identity $PC.ManagedBy).Enabled
PrimarySMTP = (get-aduser -identity  $PC.Managedby -properties *).Mail
Phone = (get-aduser -identity  $PC.Managedby -properties * ).telephoneNumber
}
$Output += $MyObject
}
$Output

How to pipe a file name into attribute

$
0
0

Hi,
I have a script that sends an email with attachments. The script takes as its input an attribute that contains the file path of the file. Works great for me normally.
The issue I have now is that the file I want to use this for will be a .HTM file without a specific file name (it uses the date and time as the filename). The mail commands for powershell do not allow me to use wildcards in the path so I have been trying to pipe the filename of the only htm file in the directory into an attribute.

I can get the file name using:
get-childitem "c:\ReportData" | where-object {$_.Name -like "*.htm"} | select-object Name

This shows the name, but if i use the attribute in the file path it contains the additional formatting, so i tried this:

get-childitem "c:\ReportData" | where-object {$_.Name -like "*.htm"} | select-object Name | format-wide

This displays the filename on its own with no extra text

but if i try to put this into the attribute using:

$filename = get-childitem "c:\ReportData" | where-object {$_.Name -like "*.htm"} | select-object Name | format-wide

 the attribute takes on the value:

Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartDa
ta Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndD
ata Microsoft.PowerShell.Commands.Internal.Format.FormatEndData

Any idea how I can just get the filename of the single .htm file into the attribute? I am a beginner with powershell! But I am enjoying it.



Start-service, set-service

$
0
0

Hi,

I need to start a service and set the startup type to automatic on a large number of PC's.  I can do this for a single PC with :

Set-Service -StartupType Automatic -InputObject $(Get-Service -Computer PC01 -Name dot3svc)
Start-Service -InputObject $(Get-Service -Computer PC01 -Name dot3svc)

How can I do this for say 20 PC's listed in a .txt file ?

Thanks

Bill

Add Carriage return problem

$
0
0

I'm having a problem adding a Carriage return to the following. I'm not sure where to put the `n or if there is another method. When the output is recieved in Outlook, it is in one string.

$body = get-content "d:\Sharepoint backups\spbrtoc.xml" | where-object { $_ -match "Count" -or $_ -match "Time"}

Thank you,

Dave

Powershell Compare Files Script Help

$
0
0

I am having a problem with a powershell script I am trying to write. I want to compare multiple .txt files to a master .txt file. If the user are in the master .txt file remove it from the .txt file. Then I want it to copy the new txt file with removed users to .\output\orginalname.txt. For example:

serv1_Users.txt -  james mike

serv2_Users.txt -  james mike admin bob

Serv3_Users.txt - james bob marry admin

User_Ignore.txt  - admin marry bob

Compare (User_Ignore file and remove admin marry bob from the Serv1 Serv2 Serv3 files and output them to:

.\output\serv1_Users.txt

.\output\serv2_Users.txt

.\output\serv3_Users.txt

I have tried many ways to do this but it doesn't work.

unset "hidden" attribute

$
0
0
In Powershell, it is theoretically possible to set a file's "hidden" attribute to False.

Catch 22: POWERSHELL CAN'T FIND HIDDEN FILES! So please, how can I do this? Syntax and an example would be very helpful and much appreciated.

O/S: Win 7 Ultimate

Powershell XML update

$
0
0

Hi, i need to edit a XML file with userdata that i get from a query ans is stores in  a $variable

I can update most of the fields but there is a field that i can't get to work due to the XML file structure.

This is the XML base type:

<?xml version="1.0" encoding="UTF-8"?>
<agentList>
  <newAgent>
    <firstName></firstName>
    <lastName></lastName>
    <startid></startid>
    <emailList><email number=1></email></emailList>

  </newAgent>
</agentList>

The powershell code  goes:

[xml]$source = @"
<?xml version="1.0" encoding="UTF-8"?>
<agentList>
  <newAgent>
    <firstName></firstName>
    <lastName></lastName>
    <startid></startid>


<emailList><email number=1></email></emailList>

 </newAgent>
</agentList>
"@
 $result | % {
	$newagent = $agentnode.Clone()

	$newagent.firstName= $_.FirstName
	$newagent.lastName= $_.lastname
	$newagent.startid= $_.id.ToString()
        

$source.agentList.AppendChild($newagent)
}

$source.agentList.RemoveChild($source.agentList.newAgent[0])


$source.Save("c:\temp.xml")

This updates correctly the name, lastname and id fields, but i am not sure how to update the email address field to end like this:

<emailList><email number=1></email>$_.email</emailList>

Any ideas?

Thanks


Viewing all 2562 articles
Browse latest View live