Hi,
Iam trying to copy a file from one server to other server. Both the servers having public IP's.
I tried using the below code.
Find the below image for more error description.
Regards.,
Srinivas.
SRINIVAS
Hi,
Iam trying to copy a file from one server to other server. Both the servers having public IP's.
I tried using the below code.
Find the below image for more error description.
Regards.,
Srinivas.
SRINIVAS
What am I doing wrong??
function New-SchedTask { $TaskName = Read-Host 'What would you like to name this job? Seperate words in name with an underscore ( _ ), be concise.' mkdir C:\Jobs\$TaskName | out-null $Freq = "None" While ( $Freq -eq "None" ) { $RequestedFreq = Read-Host "What frequency would you like this task to run? (Daily, Weekly, Monthly)" Switch ( $RequestedFreq.ToUpper() ) {"Daily" { "You picked Daily" ; $Freq = "-Daily" }"Weekly" { "You picked Weekly" ; $Freq = "-Weekly" }"Monthly" { "You picked Monthly" ; $Freq = "-Weekly -WeeksInterval 4" } default { "Default is Daily" ; $Freq = "-Daily"} } } $Day = Read-Host 'Which day of the week would you like this task to run on? (i.e. Monday or Monday,Tuesday,Wednesday. Note the lack of spaces after the comma when using multiple days)' $Time = Read-Host 'What time of day would you like this job to run? Please use 12 hour time with am or pm (i.e. 6am or 2pm).' $TaskTrigger = New-ScheduledTaskTrigger $Freq -At $Time -DaysOfWeek $Day $TaskAction = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "C:\Jobs\$TaskName\$TaskName.script.ps1" Register-ScheduledTask -Action $TaskAction -Trigger $Tasktrigger -TaskName "$TaskName" -User "Administrator" -RunLevel Highest Write-Host "File transfer task, $TaskName, created and scheduled for $Day at $Time" } New-SchedTask
Running that in the ISE generates the following error:
(Just from running the $Freq section) What frequency would you like this task to run? (Daily, Weekly, Monthly): Daily You picked Daily -Daily Which day of the week would you like this task to run on? (i.e. Monday or Monday,Tuesday,Wednesday. Note the lack of spaces after the comma when using multiple days): Monday What time of day would you like this job to run? Please use 12 hour time with am or pm(i.e. 6am or 2pm).: 2pm 2pm -Daily Monday New-ScheduledTaskTrigger : Cannot process argument transformation on parameter 'Weekly'. Cannot convert value "System.String" to type "System.Management.Automation.SwitchParameter". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0. At line:17 char:42+ $TaskTrigger = New-ScheduledTaskTrigger $Freq -At $Time -DaysOfWeek $Day+ ~~~~~+ CategoryInfo : InvalidData: (:) [New-ScheduledTaskTrigger], ParameterBindingArgume ntTransformationException+ FullyQualifiedErrorId : ParameterArgumentTransformationError,New-ScheduledTaskTrigger
Echoing back each variable though, shows me all variables set properly. Am I missing something derpy?
Thanks,
Mike
Hello
How can I modify this script to target all Users OU in one domain to move all disabled accounts from each Users OU to move to the Disabled Users OU?
Search-ADAccount –AccountDisabled –UsersOnly –SearchBase “OU=Users,OU=test,OU=domain,DC=domain,DC=com” | Move-ADObject –TargetPath “OU=Disabled Users,DC=domain,DC=com”
The above script will work for but only for one OU, I need it to target all OU=Users OU.
Thanks
I have this section in a script that restores a single database to a Dev server. Data is rarely added so I want to limit the growth size to that it does not take over the disk. However, the value is not being set. What is wrong with it?
$server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") "(local)"
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
$SMOserver = $Server
$databases = $SMOserver.Databases;
foreach ($DB in $databases ) {
#Set Log File growth
foreach ($DBLF in $DB.logfiles) {
$DBLF.set_GrowthType("KB");
$DBLF.set_Growth("51200"); #50mb
$DBLF.Alter();
}
#set File Growth
$DBFG = $DB.FileGroups;
foreach ($DBF in $DBFG.Files) {
$DBF.set_GrowthType("KB");
$DBF.set_Growth("102400"); #100mb
$DBF.Alter();
}
}
yaro
I've got a function which outputs a data table result and would like to be able to make it useable in a pipeline result. I can read into the table to return just the mpname but it I would like to know if its possible to have both options? So for example if the command is run separately it outputs the data table but if run in a pipeline is outputs just the string?
Any advice or suggestions greatly appreciated :)! Been scratching my head on this for a while...
function Get-MPPropertiesTest { [CmdletBinding(DefaultParameterSetName="None")] param ( [Parameter(Position=0,Mandatory=$false, HelpMessage='Select Management Pack', ParameterSetName="Two" )] [String]$ManagementPack ) begin { switch ($psCmdlet.ParameterSetName) { "None" {$ManagementPack = 'Microsoft.Unix.Library' $SqlQuery = "Select MPName, MPFriendlyName, MPVersion, MPXML FROM [dbo].[ManagementPack] Where MPName = '$ManagementPack'" }"Two" {$SqlQuery = "Select MPName, MPFriendlyName, MPVersion, MPXML FROM [dbo].[ManagementPack] Where MPName = '$ManagementPack'" } } } process{ write-verbose "Beginning process" Write-Verbose "Processing $ManagementPack" $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server = $SCOMSQLServer; Database = $SCOMDBName; Integrated Security = True" $SqlConnection.Open() $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $sqlcmd.CommandTimeout = 600000 $SqlCmd.Connection = $SqlConnection $SqlCmd.CommandText = $SqlQuery $result = $sqlcmd.ExecuteReader() $resulttable = new-object “System.Data.DataTable” $resulttable.Load($result) $SqlConnection.Close() } End{ return $resulttable } }
Raf Delgado
Hello:
With diskPart you can disable shadow copy of any disk, for example:
diskpart att vol clear shadowcopy
So I need disable shadow copy over Disk 1 on a server windows 2012. The server have 2 disk:
Number Friendly Name OperationalStatus
------ ------------- -----------------
1 VMware Virtual disk SCSI Disk Device Online
0 VMware Virtual disk SCSI Disk Device Online
But I need shadow copy on Disk 0, then only need disabled shadow copy on Disk 1.
Any way to do this with powershell and without Diskpart??. Thanks and sorry for my bad english.
Hi All,
Reposting this from the Exchange Forums based upon feedback...
We have some AD groups that I can successfully pull into a recipient filter if I use the "-eq" operator. Thing is, there are now more groups and it seems like there is a limit to how many groups you can add.
So, I thought a wildcard would make it cleaner and negate the size limitation, whatever that may be. Thing is, I cannot get it to work when just testing.
This works:
get-recipient -RecipientPreviewFilter {(memberofgroup -eq 'CN=MyADGroupInMN,OU=Groups,OU=MN,OU=SomeCompany,DC=PartyTown,DC=org')}
This does not:
get-recipient -RecipientPreviewFilter {(memberofgroup -like 'CN=MyADGroupIn*')}
I've tried about every variation of the above. According to this article you should be able to use the 'like' operator, but I'll be damned if I can find an example using 'memberofgroup.'
http://technet.microsoft.com/en-us/library/bb124268(v=exchg.150).aspx#OPATH
Hello,
I've got 1 logfile (authentification on a CAS) to parse with a list of IP. The goal is to have a list of user on some devices (this devices having MAC reservation in the DHCP and so, always the same IP).
I am stucked at the end of the script to export the table created (studentID, deviceID) in a text file.
For now, I have that :
numero_etudiant : kerherve1 ipad-tes 00:00:24 numero_etudiant : e21402325 ipad-fin 00:00:25
And I need that :
kerherve1 ipad-tes 00:00:24 e21402325 ipad-fin 00:00:25
Here's the script :
$deviceID = @() $file = Get-Content liste.txt foreach ($ligne in $file){ $lignetrait = $ligne -split(" ") $obj = New-Object psobject $obj | Add-Member -Name "deviceID" -Membertype NoteProperty -Value $lignetrait[0] $obj | Add-Member -Name "IPaddress" -MemberType NoteProperty -Value $lignetrait[1] #ajout de l'objet dans le tableau tabIp $deviceID += $obj } $studentID = @() $file = Get-Content log.txt #clean log file $file = $file -replace("\]' from '"," ") $file = $file -replace("'","") foreach ($ligne in $file){ $lignetrait = $ligne -split(" ") $obj = New-Object psobject $obj | Add-Member -Name "connection_time" -MemberType NoteProperty -Value $lignetrait[3] $obj | Add-Member -Name "studentID" -Membertype NoteProperty -Value $lignetrait[10] $obj | Add-Member -Name "IPaddress" -MemberType NoteProperty -Value $lignetrait[11] $studentID += $obj } $tabConnexion = @() $i = 0 foreach ($ip1 in $deviceID.IPaddress){ $j=0 foreach ($ip2 in $studentID.IPaddress) { if ($ip1 -eq $ip2){ $obj = New-Object psobject $obj | Add-Member -Name deviceID -MemberType NoteProperty -Value $deviceID.deviceID[$i] $obj | Add-Member -Name studentID -MemberType NoteProperty -Value $studentID.studentID[$j] $obj | Add-Member -Name connection_time -MemberType NoteProperty -Value $studentID.connection_time[$j] $tabConnexion += $obj } $j +=1 } $i +=1 } $tabConnexion = $tabConnexion | Format-Table -AutoSize -GroupBy studentID -HideTableHeaders -Property deviceID, connection_time | Get-Unique $tabConnexion
Here's some extracts from logs :
liste.txt and log.txt
iPad-247 172.18.210.66 iPad-248 172.18.210.67 ipad-tes 192.168.12.81 ipad-fin 46.193.0.46
Thu Jan 08 00:00:23 CET 2015 - AUTHENTICATION_SUCCESS for '[username: e21303362]' from '92.139.97.131' Thu Jan 08 00:00:24 CET 2015 - AUTHENTICATION_SUCCESS for '[username: kerherve1]' from '192.168.12.81' Thu Jan 08 00:00:25 CET 2015 - AUTHENTICATION_SUCCESS for '[username: e21402325]' from '46.193.0.46' Thu Jan 08 00:00:27 CET 2015 - AUTHENTICATION_SUCCESS for '[username: demopers]' from '195.83.247.111' Thu Jan 08 00:00:27 CET 2015 - AUTHENTICATION_SUCCESS for '[username: kerherve1]' from '192.168.12.81' Thu Jan 08 00:00:29 CET 2015 - AUTHENTICATION_SUCCESS for '[username: kerherve1]' from '192.168.12.81'
I've tried many things but I don't manage to have what I need.
If anyone could help me, I thank you.
I'm trying to run this command on my mgmt. server to see all the monitors in a particular Mgmt Pack:
get-monitor -managementPack System.Health.Library.mp | export-csv "C:\monitors.csv"
I'm getting this error:
The term 'get-monitor' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:12
I know it has to be something simple, what am I missing here?
Thank you.
Is it possible using powershell to get a list of users who’s description field (for instance) have changed in the last 24 hours? It seems when I use the “whenchanged”, anything could trigger it like a change in there address etc…. I am looking for when a single attribute change and not anything.
Thoughts and thanks in advance.
I need to know all the monitors and rules in a mgmt pack, but without using Powershell.
For some reason I cannot run the "get-monitor" or "get-SCOMMonitor" cmdlets and I need a workaround.
I keep getting this error: The term 'get-monitor' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
Is there another way to list all the rules/monitors in a Mgmt pack?
thank you.
Hello All,
Our management have decided to enable the powershell scripting on all WIndows 7 machines. We would like to implement it with "ALL SIGNED" part.
I would like to understand, the security challenges and also about "ALL SIGNED" part.
Thanks
Thanks HA
I would to check file in folder and send name file to my email. How to use power-shell script
we have files in folder but this file change name everyday. i need to check file and sent to my email every day
Please advise and idea .
I have played with Date math based on what I have found for documentation, and adding an arbitrary number of days is pretty easy. But what about adding an arbitrary number of business days? I found a web site that talks about "Next business day", which could be adapted I am sure, but it only accounts for weekends. I want to calculate the date an arbitrary number of business days from a provided date. So, +3 business days calculated from a Monday should produce the date of the following Thursday, and calculated from a Friday should produce the date of the next Wednesday. And calculated from Friday Sept 4, 2015 (Friday before Labor Day) should produce Thursday Sept 10, 2015.
Given that Windows is very business focused, I wonder if there is some nice hidden .NET functionality to calculate business days based on holidays as well? I know, some offices might give extra days off, four day weekends, etc. But those would be edge case enough to be safely ignorable for my purposes. Indeed, even holidays could probably be ignored, but if there is a quick approach I would rather use it. If I would need to code some sort of Exchange calendar scraper or some such, I'll live with just accounting for weekends. ;)
I'm a beginer to PowerShell, so sorry if the question is dumb.
I have a concole utility (JAVA utility). And a .bat file that starts it. This utility is used for tasks like mange server application including upload data. Such task is time consumming. I need to make a large number of such actions and I want to automate this process.
Basicly I want PowerShell to open this utility and pass some commands, wait utill process is completed, pass another command and so on.
I'm looking for answers:
- Is it possible(I'm pretty sure it is).
- How to pass commands to utility when it is already running.
- Do I need to rewrite .bat to PS script or I can use something like "cmd /c my.bat"
Thank you for your answers in advance - I really stuck with this issue.
if that does matter this is the content of that .bat file.
@echo off
rem Set the lib dir relative to the batch file's directory
set LIB_DIR=%~dp0\..\lib
rem echo LIB_DIR = %LIB_DIR%
rem Slurp the command line arguments. This loop allows for an unlimited number
rem of arguments (up to the command line limit, anyway).
set CMD_LINE_ARGS=%1
if ""%1""=="""" goto setupArgsEnd
shift
:setupArgs
if ""%1""=="""" goto setupArgsEnd
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setupArgs
:setupArgsEnd
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
goto javaHome
:noJavaHome
set JAVA=java
goto javaHomeEnd
:javaHome
set JAVA=%JAVA_HOME%\bin\java
:javaHomeEnd
:checkJdk14
"%JAVA%" -version 2>&1 | findstr "1.4" >NUL
IF ERRORLEVEL 1 goto checkJdk15
echo Java 5 or newer required to run the console
goto end
:checkJdk15
"%JAVA%" -version 2>&1 | findstr "1.5" >NUL
IF ERRORLEVEL 1 goto java6
rem use java.ext.dirs hack
rem echo Using java.ext.dirs to set classpath
"%JAVA%" -Djava.ext.dirs="%LIB_DIR%" org.openrdf.console.Console %CMD_LINE_ARGS%
goto end
:java6
rem use java 6 wildcard feature
rem echo Using wildcard to set classpath
"%JAVA%" -cp "%LIB_DIR%\*" org.openrdf.console.Console %CMD_LINE_ARGS%
goto end
:end
So, I have a script that does a write-host to the console (see script below). I've tried everything to get this thing to write to file....
I've tried just calling the script and passing the to the out-file parameter like this:
C:\> .myscript.ps1 | out-file results.txt
I've tried:
C:\> .myscript.ps1 > results.txt
I've tried re-writing the script to use write-output instead of write-host and it works for the first two write-host statements (hostname and template) but not the 'device name' statement which is in the for loop.
Hoping someone can help me get this info into a file. It needs to be something that is nor version specific as we're stuck using a very old version of powershell.
Sorry, it's not my language of expertise so the code below might look a bit shabby,,,,It works though, but only to the console.
#Conecting and gathering information $objDomain = new-object system.directoryServices.directoryEntry $strTopDomain = $objDomain.distinguishedName $strTopLDAP = "LDAP://OU=Topology,OU=APC,OU=Applications,$strTopDomain" $objTopOU = new-object system.directoryServices.directoryEntry("$strTopLDAP") $strTopOU = $objTopOU.distinguishedName $topFilter = "(&(sita-Vps-computerLink=*)(sita-Vps-iwsTemplateLink=*))" $topObjSearcher = New-Object System.DirectoryServices.DirectorySearcher($topFilter) $topObjSearcher.searchRoot = $objTopOU $topObjSearcher.searchScope = "subtree" $topObjSearcher.sizelimit = 1000 $properties=@('name','sita-Vps-iwsTemplateLink') $topObjSearcher.PropertiesToLoad.AddRange($properties) $hash = @{} $objTopList = $topObjSearcher.findAll() | foreach-object{ $hash.Add($_.Properties.Item("name")[0], $_.Properties.Item("sita-Vps-iwsTemplateLink")[0].toString().split(',=')[1])} $objIwsDomain = new-object system.directoryServices.directoryEntry $strIwsDomain = $objIwsDomain.distinguishedName $iwsFilter = "(sita-Vps-deviceTemplate=*)" $strIwsLDAP = "LDAP://OU=IwsTemplates,OU=APC,OU=Applications,$strIwsDomain" $objIwsOU = new-object system.directoryServices.directoryEntry("$strIwsLDAP") $strIwsOU = $objIwsOU.distinguishedName $iwsObjSearcher = New-Object System.DirectoryServices.DirectorySearcher($iwsFilter) $iwsObjSearcher.searchRoot = $objIwsOU $iwsObjSearcher.searchScope = "subtree" $iwsObjSearcher.sizelimit = 1000 $iwsProperties=@('distinguishedName','sita-vps-deviceTemplate') $iwsObjSearcher.PropertiesToLoad.AddRange($iwsProperties) #Looping through gathered information and displaying foreach($i in $hash.keys){ write-host "Hostname: $i" | Out-File -filepath "c:\" -append -encoding utf8; Write-host "Template:" "$($hash.$i)" | Out-File -filepath "c:\" -append -encoding utf8; $objIwsList = $iwsObjSearcher.findAll() | foreach-object{ $tmp_name = ($_.Properties.Item("distinguishedName")[0].split(',=')[3]); $tmp_device = ($_.Properties.Item("sita-Vps-deviceTemplate")[0].toString().split(',=')[1])| where-object{$tmp_name -eq $hash.$i if($tmp_device -ne $null){write-host "Device:" $tmp_device | Out-File -filepath "c:\" -append -encoding utf8} } } }
Using the script below I can test for admin rights in Windows 7 with no problems. Windows 8 is causing some issues however. I launch the script with a shortcut, and if I just double click the link as I would in Windows 7 it comes back that I don't have sufficient rights. But if I Run as Administrator the script fails claiming the script referenced in the -file argument doesn't exist.
I have enabled the local admin user, so I am wondering, what else do I need to do to get admin rights? My real script runs this same test, because it also does things like install software and manipulate Program Files, so it has to be run with elevated privileges.
Also, given the difference in PS between Windows 7 and Windows 8, is there some kind of reference to all the differences between versions? I have about 10,000 lines of code I need to make work in 8+ soon (well, probably just 10 actually, as I am not seeing anyone in my industry moving to 8.X.)
Clear-Host
$Logfile = "C:\himanshu\Logs\$(gc env:computername).log"
$exePath="C:\Windows\System32\notepad.exe"
$isRunning = (get-wmiobject win32_process | ?{ $_.Path -eq $exePath} | measure-object | % { $_.Count }) -gt 0
$timespan=0
if(!(Test-Path -Path $Logfile)){
new-item -Path $Logfile –itemtype file
}
do{
$timespan++
if($isRunning -and ($time -gt 0))
{
$isRunning
$b="YES"
LogWrite $b
}
else
{
$isRunning
"opening notepad"
#Start-Process -FilePath java.exe -ArgumentList -jar,C:\HP\AHCMail\AHC-2.9\AHCheck.jar,-classpath,$Env:CLASSPATH -NoNewWindow
$Start = ([wmiclass]"win32_process").Create($exePath)
$b="NO"
LogWrite $b
}
}
while($timespan -lt 0)
Function LogWrite
{
Param ([string]$logstring,[string]$a)
$a=Get-Date
Add-content $Logfile -value ($a + "############" + $logstring)
}
I need to extract server backup policy information from a text file.
The file has over fifty server policies listed and I need to run an update schedule report and export the info to a csv file.
For each backup client server I need the following information:
Client Name HW OS Include
Schedule Type
WinServer01 PC Windows2008 All_local_Drives Full Full Backup
WinServer11 PC Windows2008 All_local_Drives Full Full Backup
UnixServer12 Unix Solaris / Full Full Backup
So, how do I extract the fields and format them as follows for each policy formatted as below:
-----------------------------------------------------------------------------
Policy Name: Windows_Server_1
Policy Type: MS-Windows-NT
Active: no
Effective Date: 06/24/2014 01:00:00
Backup network drives: no
Collect TIR info: no
Mult. Data Streams: no
Client Enctypt: no
Checkpoint: no
Policy Priority: 0
Max Jobs/Policy: Unlimited
Disastery Recovery: 0
Collect BMR info: no
Residence: BackupSrv01-hcart2
Volume Pool: NetBackup
Server group: *Any*
Keyword: (none specified)
Residence is Lifecycle Policy: no
Granular Restore Info: no
HW/OS/Client: PC Windows2008 WinServer01
Include: All_Local_Drives
Schedule: Full
Type: Full Backup
Frequency: every 7 days
Maximum MPX: 1
Synthetic: 0
PFI Recovery: 0
Retention Level: 8
Number Copies: 0
Fail on error: 0
Residence: (specific storage unit not required)
Volume Pool: (same as policy volume pool)
Server Group: (Same as specified for policy)
Residence is Storage Lifecycle Policy: 0
Daily Windows: